Script for mounting SMB share volumes on demand
-------------------------------------------------------------------------------
#!/bin/sh

## /usr/bin/samba_back.sh
##
## This script will read a list of systems from the command line and
## mount them using smbmount one at a time.
##
## This allows us to perform a backup of each system as a separate backup
## set on a single 12GB DDS3 4MM DAT tape.
##
## While I use BRU 2000 for our operations, you could run a similar
## operation with tar, cpio and other shell-based tools.
##


SYSTEMS='kingtut/labc sparc1/tjones' # add all machines to backup here
MOUNTHOME=/desktops # this is the top level mount point
SYSCOUNT=0          # keep track of how many systems we include
NTAPE=/dev/nst0     # the non-rewinding tape drive
TAPE=/dev/st0       # the rewinding tape drive
USER=backup         # the name of the user with access to the shares
PASSWD=secret       # the user's password - sorry, no way around plain text
                    #  for this example.

# This script is for a Linux server, so make sure smbfs is loaded
# if it wasn't compiled into the kernel.
if lsmod | grep smbfs >/dev/null 2>&1
then
	echo "SMB Filesystem is loaded"
else
	modprobe smbfs
fi

# Loop through each element of the $SYSTEM variable above
for x in `cat $SYSTEMS`
do
    if [ -e $MOUNTHOME/$x != 0 ]
    then
        mkdir -p $MOUNTHOME/$x
    fi
    smbmount //$x $MOUNTHOME/$x -U $BACKUP -P $PASSWD
    SMBERR=$?
    if [ ${SMBERR} -ne 0 ]
    then
        # Notice that we don't increment SYSCOUNT if we can't mount the share.
        echo "Unable to mount $x on $MOUNTHOME/$x
	echo "  $x not included in this backup"
    else
        SYSCOUNT=`expr $SYSCOUNT + 1`
        bru -cvvf $NTAPE $MOUNTHOME/$x
        BRUERR=$?
        if [ ${BRUERR} -gt 1 ]
        then
            echo "Errors occurred during the backup of $x."
            echo "  Refer to the BRUEXECLOG for details."
        fi
        # Free up the mount from the currently finished system
        smbumount $MOUNTHOME/$x
        echo "Backup of $x completed as backup set $SYSCOUNT on this tape."
    fi
done

mt -f $TAPE rewind
for x in [1-$SYSCOUNT]
do
    bru -if $NTAPE
    $BRUERR=$?
    if [ ${BRUERR} -gt 1 ]
    then
        echo "Errors occurred during the verification of backup #$x"
	echo "  Refer to the BRUEXECLOG for details"
    fi
done

echo "Backup and verification of $SYSTEMS is complete."
