Autmatically backing up PCs with Amanda and Samba

Ernie Oporto ernie_oporto at MENTORG.COM
Thu Jan 15 19:56:40 GMT 1998


Here's how we now set up Amanda to backup PCs from Samba without
continually adding users to a disklist file.  Ask each person that
wants a backup done to share a certain folder that they are keeping
their files in.  A policy that the folder must be shared as "BACKUP"
or have the word "BACKUP" (as in MYBACKUP) somewhere in it is in
place here.  Also, all PCs are running WinPopUp to receive
notifications.  We then use these scripts to gather and handle the
proper info...


smbclientbrowse accesses a machine's domain list, assuming that the
authorized user for backups is "BACKUP"
(permissions just like /etc/amandapass! (600)):
--------------------------------------------------------------------



#!/usr/cygnus/bin/expect -f
spawn /usr/local/pkgs/samba/bin/smbclient -L $argv -U BACKUP
expect {Password:*} {send <<insert your passwd here>>\r ; interact}



--------------------------------------------------------------------
which is called by smbbackuplister for each machine the PDC knows of
and lists only the shares.
(OK, so I'm not too hot with the names):
--------------------------------------------------------------------


#!/usr/local/bin/perl
$FLAG=0;
$debug=0;
$|=1;

# Add parsing to support ability to check all domains or particular domains

# Find out what is in the Warren domain
open(FILEH,"/fx/amanda/etc/smbclientbrowse NOT|") || die "couldn't read the
domain";
while (<FILEH>)
{
    $line=$_;
    $line =~ s/^M//g;
    chop($line);
    if (($line =~ "^This machine has a browse list:") && ($FLAG EQ 0))
    {
        $FLAG = 1;
        next;
    }
    $FLAG = 2 if ($line =~ "^This machine has a workgroup list:");
    next if (($FLAG EQ 0)||($FLAG EQ 2));
    next if ($line EQ "");
    push(@array,$line);
}
close(FILEH);
foreach $line (@array)
{
    $line=(split(/[ ]+/,$line))[1];
    next if ($line EQ "Server");
    next if ($line EQ "---------");
    # don't check the server list...not yet anyway
    # their shares are added later
    next if ($line EQ "PDC");
    next if ($line EQ "BDC1");
    next if ($line EQ "BDC2");
    next if ($line EQ "SAMBA");
    print "$line\n" if $debug;
    push (@machinelist,$line);
}
foreach $machine (@machinelist)
{
    $FLAG=0;
    print "$machine\n" if ($debug);
    open(FILEH,"/fx/amanda/etc/smbclientbrowse $machine|");
    while (<FILEH>)
    {
        $line=$_;
        $line =~ s/^M//g;
        chop($line);
        if (($line =~ "^        ---------") && ($FLAG EQ 0))
        {
            $FLAG = 1;
            next;
        }
        # change the regexp in this next link to match your backup policy.
        next unless ($line =~ /BACKUP/i);
        $FLAG = 2 if ($line =~ "^NOTE: There were share names longer than 8
chars.");
        next if (($FLAG EQ 0)||($FLAG EQ 2));
        next if ($line EQ "");
        next if ($line EQ " ");
        $line=(split(/[ ]+/,$line))[1];
        $UNC = "\\"."\\".$machine."\\".$line;
        $UNC =~ s/^M/\n/g;
        print $UNC;
        print "\r\n";
    }
    close(FILEH);
}
#print any other special cases to be backed up here


---------------------------------------------------------------------
which is in turn called by full-dumper.pcs-day.A, the wrapper for this whole
fiesta.  Note that the name of the script dictates what conf directory it is
looking for.  Doing this, I can just copy the script to another name to have
it work a different area that might back things up under a different
criteria.
The script massages the list of shares and machines into the proper formats
for
the files Amanda needs, and then runs the Amanda stuff.  It also handles
letting end users know when the backup has started and ended.  The only flaw
in
that is that everyone is notified at once, rather than when their backup is
actually taking place.  A little hacking of Amanda's calls to smbclient
might
fix that.
(permissions just like /etc/amandapass! (600)):
---------------------------------------------------------------------


#!/bin/sh
amandahome="/fx/amanda"
sambahome="/usr/local/samba"
confdir=`basename $0 | awk -F. '{print $2"."$3 }'`
device=`grep tapedev $amandahome/etc/$confdir/amanda.conf | awk '{print $2}'
| awk -F\" '{print $2}'`
logdir=`grep logfile $amandahome/etc/$confdir/amanda.conf | egrep -v '(^#)'
| awk '{print $2}' | awk -F\" '{print $2}' | awk -F\/ '{print $4}'`

if [ -f $confdir/skip ]
then
  echo Skipping today
  rm $confdir/skip
  exit
fi

# PC specific disklist handling.  Replaced for UNIX backups.
$amandahome/etc/smbbackuplister | sed s/^M//g | sed s/\\\\/\\\//g | awk
'{print "salamanda "$1" comp-user-gnutar"}' | tee
$amandahome/etc/$confdir/disklist | awk '{print $2}' | awk '{print $1"
<<insert your passwd here>> WARREN"}' > /etc/amandapass

# PC specific block.  Removed for UNIX backups.
if [ ! -f $confdir/debug ]; then
for i in `cat $amandahome/etc/$confdir/disklist | awk -F/ '{print $3}' |
sort | uniq`; do
    (echo "Beginning backup of your machine. Do not reboot your machine
during this period.  This will ensure a complete backup of your folder.";
echo "If the folder being backed up is empty, you will see the backup for it
listed as a failure."; echo; echo; echo "To clear this message, simply hit
the trashcan button for the application.  Please do not exit WinPopup") |
$sambahome/bin/smbclient -M $i -U BACKUP
done
fi

# This is meant for holidays and days we forget to put the tape in.
mt -f $device stat || exit 0

# Label AMANDA tape, check the AMANDA tape, dump to the AMANDA tape and
eject
$amandahome/bin/amcheck $confdir
$amandahome/bin/amdump $confdir
mt -f $device offl || exit 1
sleep 10

# PC specific block.  Removed for UNIX backups.
if [ ! -f $confdir/debug ]; then
for i in `cat $amandahome/etc/$confdir/disklist | awk -F/ '{print $3}' |
sort | uniq`; do
    (echo "Backup cycle finished.  Thank you."; echo ; echo "To clear this
message, simply hit the trashcan button for the application.  Please do not
exit WinPopup.") | $sambahome/bin/smbclient -M $i -U BACKUP
done
fi


-Ernie






More information about the samba mailing list