#!/opt/bin/bash
# Written for Solaris. Should be simple to port to other systems. # Change the tape device, the remote program (rsh or ssh), and # choose your dump program. This script assumes you know what you're doing # with .rhosts, hosts.equiv and/or ssh keys so that you will not need to # input passwords to do this. This script is designed to run from cron, # but I see nothing wrong with running it manually. # # This script will by default append to existing information on a tape. # If you would like to nuke the tape, you can simply call this script with # the --scratch parameter. # # Note that this script makes *NO* provisions for restoring your data. # If your box dies, you'll need to attach a tape drive to your server's # SCSI chain and run a restore locally, after booting from a CD, floppy, # Jaz disk, or something else. Jaz drives make really cool emergency # startup systems for times like this. You can have the convenience of a # fully functioning system on a 3.5" disk. If you can boot the machine, # AND have network connectivity, you can restore over the network, using # a technique similar to this script.... # # Make sure the tape device you choose is a non-rewinding device!
tape=/dev/rmt/0cn remote=rsh dump=ufsdump
# dumpit remote filesystems and writes the output to a local tape dumpit() { host=$1 fsys=$2 fno=`expr $fno + 1` echo ====================================================================== echo File $fno on $tape echo Host: $host echo Filesystem: $fsys echo Started `date` echo "$remote -n $host \"cd $fsys && $dump 0f - .\" | dd of=$tape bs=256k" $remote -n $host "cd $fsys && $dump 0f - ." | dd of=$tape bs=256k if [ $? != 0 ]; then echo Error writing tape $tape echo No more backups for now exit 1 fi echo Finished `date` echo echo };
if [ "$1" = "--help" ]; then cat <<EOF;
Your only option is the --scratch parameter. If you use it, all data on your tape will be destroyed.
For options regarding what tape device to use, and so forth, set them at the top of the script. EOF exit 0 fi
if [ "$1" = "--scratch" ]; then echo Writing from the beginning of the tape $tape mt -f $tape rewind mt -f $tape eof else # does not overwrite whatever is written already mt -f $tape eom > /dev/null 2>&1 fi
# This works on Solaris. Other mt's may not behave the same way. YMMV. fno=`mt -f $tape stat | grep 'file no' | \ sed 's/.*file no= \([0-9][0-9]*\).*/\1/'`
if [ "$fno" = "" ]; then echo No tape in the device $tape echo Abort backup exit 1 fi
echo Starting backup at `date` echo Current position of $tape is $fno
# several filesystems on one box. dumpit box1 / dumpit box1 /usr dumpit box1 /var dumpit box1 /home
# several filesystems on many boxen. for host in box2 box3 box4; do dumpit $host / dumpit $host /var dumpit $host /home done
echo "" echo "All Backups complete!" mt -f $tape rewind
|