| I suppose answering .5 implies that I know UNIX, which may not be something I
want to admit, but nevertheless...
(Unfortunately, NetNotes wraps some lines. Look at it as an opportunity to earn
consulting revenue from your customer. 8-)
PJDM
#!/bin/sh
#+
# Use vdump to backup the system, and verify the last file backed up
# to give some assurance that the backup worked.
#
# PJDM, Digital Equipment Corporation, 10-Oct-1995
#-
PATH=/sbin:/usr/sbin:/usr/bin
export PATH
Failure()
{
echo Backup verify failed: $1. > /dev/console
echo Failed backup of $fs at $now finished at `date +%d-%b-%Y-%H:%M` >
$tmpdir/$$
echo >> $tmpdir/$$
echo File $2 incorrect. >> $tmpdir/$$
echo >> $tmpdir/$$
grep -v '^b' $log >> $tmpdir/$$
mailx -s 'Failed backup' root < $tmpdir/$$
echo "Backup verify unsuccessfully completed at `date`." > /dev/console
exit
}
#+
# Put the list of filesystems to be backed up here.
#-
fs='/ /usr /var'
#+
# Is this a callback?
#-
if [ "$1" = "-" ]; then
mt rewind
for i in $fs; do
echo "Backup: vdumping $i at `date`..." > /dev/console
vdump -0vf /dev/nrmt0h $i 2>&1
done
echo "Backup completed at `date`." > /dev/console
exit
fi
now=`date +%d-%b-%Y-%H:%M`
log_base="backup-$now"
log=/var/local/$log_base
#echo Backups to $log
last_fs=`echo $fs|awk '{print $NF}'`
#echo Last filesystem is $last_fs
#+
# Use a callback to send stdout + stderr to the log file.
#-
$0 - > $log
#+
# Rewind the tape...
#-
mt rewind
#+
# ...and skip vdumps to the last one.
#-
n=`echo $fs|wc -w`
n=`expr $n - 1`
mt fsf $n
#+
# We want the last non-zero length file that was backed up, so we can
# restore it and compare it with the original file to verify that the backup
# worked.
#
# The vdump output looks like
# bf filename, size
#
# so:
# grep '^bf' finds the files
# awk '$3 != 0' finds the non-zero length files
# grep -v $log_base removes the log file we're using
# tail -1 gets the last file
# awk '{print $2}' returns the filename
# rev|cut -c2-|rev removes the trailing ","
last_file=`grep '^bf' $log|awk '$3 != 0'|grep -v $log_base|tail -1|awk '{print
$2}'|rev|cut -c2-|rev`
#echo Last file backed up was $last_fs/$last_file
tmpdir=/var/tmp/backup.$now
rm -rf $tmpdir
mkdir $tmpdir
vrestore -x -D $tmpdir $last_file 2>&1 > /dev/null
#+
# We've finished with the tape, so eject it.
#-
mt rewoffl
#+
# Now verify the restored file.
#-
if [ ! -f $tmpdir/$last_file ]; then
Failure 'file recover failed'
fi
file_len=`wc -c<$last_fs/$last_file`
last_file_len=`wc -c<$tmpdir/$last_file`
if [ $last_file_len -ne $file_len ]; then
Failure 'different lengths'
fi
cmp -s $last_fs/$last_file $tmpdir/$last_file || Failure 'files compare
differently'
echo "Backup verify successfully completed at `date`." > /dev/console
echo Successful backup of $fs at $now finished at `date +%d-%b-%Y-%H:%M` >
$tmpdir/$$
echo >> $tmpdir/$$
echo "File $last_fs/$last_file compared successfully." >> $tmpdir/$last_file
echo >> $tmpdir/$$
grep -v '^b' $log >> $tmpdir/$$
mailx -s 'Successful backup' root < $tmpdir/$$
rm -rf $tmpdir
|