[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::seal

Title:SEAL
Moderator:GALVIA::SMITH
Created:Mon Mar 21 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1989
Total number of notes:8209

1717.0. "How to do backups?" by SNOFS1::snod17dgp9.gen.sno.dec.com::snofs1.sno.dec.com::stylianoua () Thu Jan 16 1997 07:45

T.RTitleUserPersonal
Name
DateLines
1717.1QUICHE::PITTAlph a ha is better than no VAX!Thu Jan 16 1997 13:1311
1717.2BIGUN::nessus.cao.dec.com::MayneWake up, time to dieMon Jan 20 1997 18:1616
1717.3EEMELI::EINAMOTue Jan 21 1997 01:2810
1717.4BIGUN::nessus.cao.dec.com::MayneWake up, time to dieTue Jan 21 1997 16:0711
1717.5NQOS01::16.81.112.24::KyleHow secure is it?Thu Jan 23 1997 19:5637
1717.6QUICHE::PITTAlph a ha is better than no VAX!Fri Jan 24 1997 06:514
Can anyone who knows UNIX (?) improve on .5 so that there's some error handling,
or is this a silly question?

T
1717.7BIGUN::nessus.cao.dec.com::MayneWake up, time to dieFri Jan 31 1997 01:03129
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