brf@ho2cad.UUCP (Bruce Fowler) (05/19/86)
=================================================================
Here for your amusement and edification is a shell script
I put together that makes me sleep much better after powering down
the UNIX PC. It may have application on 3B2s or other machines
that have big hard disks and small floppies. There are a lot of
lines, but it should be easy to follow. I would be happy to
answer any questions and/or incorporate your suggestions.
Bruce Fowler
{ihnp4}!ho2cad!brf
AT&T-Bell Labs
Holmdel, N. J.
____ ==> [ unzip here ]
|____)-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-
# This script handles all the chores associated with selective
# backups of PC7300 files to floppy disk. The selection is based
# on subtree of the directory structure, and file size. Maximum
# size files can be specified on a directory subtree basis. By
# eliminating executables and such, useful backups will often fit on
# one disk. Several floppies or sets of floppies are assumed to be
# used in rotation, so that the oldest set is rewritten with the new
# backup. About 600 blocks of data will fit on one floppy.
# Optional command line args are explained below. The usual
# is no args, which just does the backup.
#
# set pager to specified or system available one
if test "X$PAGER" = "X"
then
PAGER=more
fi
# error check number of args
ARG1=$1
if test $# -gt 1
then
ARG1=TOMANY # force "usage" message
fi
# analyze arg, if any
OPT=BACKUP
if test $# -ge 1
then
case $ARG1 in
-e) # edit values in ./.bkuprc file
OPT=EDIT
;;
-l) # list files that will be backed up
OPT=LIST
;;
-x) # list files excluded from back up
OPT=EXCLUDE
;;
-r) # restore data from the backup set. (it may be
# put into a different directory than it came from)
OPT=RESTORE
;;
*)
echo "usage: backup (no args - backs up current directory)"
echo " -or: backup -e (Edit values in ./.bkuprc file)"
echo " -or: backup -l (List files that will be backed up)"
echo " -or: backup -x (list files eXcluded from back up)"
echo " -or: backup -r (Restore files to current directory)"
echo
exit 0
;;
esac
fi
# for restore, we can skip all the .bkuprc stuff
if test "$OPT" = "RESTORE"
then
echo "Data will be restored to the current directory, which is"
pwd
echo "Please insert the first floppy of the backup set from which"
echo "the data is to be restored."
echo "Hit <return> when ready, or <q><return> to abort: \c"
read RPLY
if test "X$RPLY" = "X"
then
cpio -idB </dev/rfp021
dismount -f
sleep 5
echo "O.K. - The restore is done."
exit 0
fi
fi
# see if ./.bkuprc file exists: if not, create one
NEWRC=NO
if test ! -f ./.bkuprc
then
echo "This is the first backup from this directory level."
NEWRC=YES
echo "File to control selective backups." >./.bkuprc
echo "BKBLK=40" >>./.bkuprc
echo "FLOPS=3" >>./.bkuprc
echo "NXDSK=1" >>./.bkuprc
echo "Date of last backup - NONE" >>./.bkuprc
else
tail -1 ./.bkuprc
fi
# suck the parameter values out of the file
BKBLK=`sed -n "/^BKBLK=/s///p" ./.bkuprc`
FLOPS=`sed -n "/^FLOPS=/s///p" ./.bkuprc`
NXDSK=`sed -n "/^NXDSK=/s///p" ./.bkuprc`
# edit the values in the ./.bkuprc file
if test "$OPT" = "EDIT" -o "$NEWRC" = "YES"
then
echo "What is the largest file (in blocks) that you want backed up? \c"
echo "[$BKBLK]: \c"
read RPLY
if test "X$RPLY" != "X"
then
BKBLK=$RPLY
fi
echo "How many sets of floppies will you use in rotation? \c"
echo "[$FLOPS]: \c"
read RPLY
if test "X$RPLY" != "X"
then
FLOPS=$RPLY
fi
echo "Which of the sets of floppies will you start with? \c"
echo "[$NXDSK]: \c"
read RPLY
if test "X$RPLY" != "X"
then
NXDSK=$RPLY
fi
# fit the data back out onto the ./.bkuprc file
ed - ./.bkuprc <<-!EDFILE
/^BKBLK=.*\$/s//BKBLK=$BKBLK/
/^FLOPS=.*\$/s//FLOPS=$FLOPS/
/^NXDSK=.*\$/s//NXDSK=$NXDSK/
w
q
!EDFILE
fi
# list the files that qualify for backup
if test "$OPT" = "LIST"
then
XBKUP=`expr $BKBLK + 1`
find . -type f -size -$XBKUP -exec ls -sd {} \; | awk '
BEGIN { bktot = 0; nfil = 0 }
/ *[0-9]+/ { bktot += $1 ; nfil++ }
{ print }
END { print "There are a total of " nfil " files"
print "not larger than " maxblk " blocks."
print "These files total to " bktot " blocks." }' \
maxblk=$BKBLK - | $PAGER
fi
# list the files that will be excluded from backup
if test "$OPT" = "EXCLUDE"
then
find . -type f -size +$BKBLK -exec ls -sd {} \; | awk '
BEGIN { bktot = 0; nfil = 0 }
/ *[0-9]+/ { bktot += $1 ; nfil++ }
{ print }
END { print "There are a total of " nfil " files"
print "larger than " maxblk " blocks."
print "These files total to " bktot " blocks." }' \
maxblk=$BKBLK - | $PAGER
fi
# finally, if all else fails, DO THE BACKUP !!!
if test "$OPT" = "BACKUP"
then
echo "Please put a floppy to be written in the disk drive."
echo "You should use the first floppy in set number $NXDSK"
echo "of the $FLOPS sets being used to backup directory"
pwd
echo "Hit <return> when ready, or <q><return> to abort: \c"
read RPLY
if test "X$RPLY" = "X"
then
echo "\n\n >>> BACKUP IN PROGRESS <<<\n\n"
XBKUP=`expr $BKBLK + 1`
find . -type f -size -$XBKUP -print |
cpio -oB >/dev/rfp021
dismount -f
# cycle the number of the floppy set for the next rotation
if test $NXDSK -lt $FLOPS
then
NXDSK=`expr $NXDSK + 1`
else
NXDSK=1
fi
# update the .bkuprc file
ed - ./.bkuprc <<-!EDFILE
/^NXDSK=.*\$/s//NXDSK=$NXDSK/
/^Date.*\$/s//Date of last backup - `date`/
w
q
!EDFILE
sleep 5
echo "O.K. - Haul out the floppy, we're done!"
else
echo "Backup request not performed"
fi
fi