Auto backup script
Elliot Dierksen
elliot at alfred.orl.fl.us
Fri Feb 2 16:05:19 AEST 1990
Well folks, here is a little script that you may find useful should you be
one of the lucky few who have a tape drive for your Unix-PC. This script
was modeled after Tbackup.sh except it doesn't do any prompting. It sends
mail about what happened and how much was backed up. It won't do a backup if
it requires more than one tape. I run this from my crontab every night and
it makes life much easier. It also saved my rear end when my HD croaked!!
Enjoy!!
EBD
--------snip-------snip--------snip----------snip----------snip------------
# autobackup
#
# Script adapted from AT&T's Tbackup.sh
#
# Elliot Dierksen 01/31/90
#
#----------------------------------------------------------------------
RET=
SHROOT=/usr/bin
TAPEDEVNAME=/dev/rft3
LOGFILE=/tmp/tape.log
MAILTO=root
## PROMPT TO INSERT TAPE. GET TAPE TYPE.
TTYPE="UNIX PC"
##
## GET BACKUP TYPE
##
#BTYPE="Complete Backup"
BTYPE="Partial Backup"
(
echo "Subject: Automatic Backup\n"
## Lock Tape, then read the VTOC
for ARG in +l -v
do
RET=`$SHROOT/Tgetname $ARG`
ERC=$?
if [ "$ERC" != "0" ]
then
echo "Error code $ERC during Tgetname $ARG"
exit 1
fi
done
OVWRIT="Yes"
TAPETYPE="UNIX PC"
fCONFM="No"
##
## GET BACKUP OPTIONS
##
VERIFY="Yes"
OWCONF="No"
OFFSET=0
DATAAT="Start of tape"
TPNAME="ctctape"
SSNAME="autoback"
SSCMNT="Automatic $BTYPE"
## LOCATE FILES FOR COMPLETE OR PARTIAL BACKUPS.
DATEFILE=/dev/null
eval set $BTYPE
if [ "$1" = "Complete" ]
then
find / -newer /etc/.installdate -print > $FORMROOT/BUfiles
DATEFILE=/etc/.lastbackup
elif [ "$1" = "Partial" ]
then
if [ ! -s /etc/.lastbackup ]
then
COMPFILE=/etc/.installdate
DATEFILE=/etc/.lastbackup
echo \
"No Complete Backup has been done, so this backup will be a Complete Backup."
BTYPE="Complete Backup"
else
COMPFILE=/etc/.lastbackup
DATEFILE=/etc/.lastpartial
fi
find / -newer $COMPFILE -print > $FORMROOT/BUfiles
fi
##
## CREATE SAVE-SET LIST
##
if [ ! -s $FORMROOT/BUfiles ]
then
clear
echo "There are no files to be backed up at this time."
exit
fi
## THE NUMBER OF TAPES IS RETURNED AS THE ERROR NUMBER
$SHROOT/TmakessList $OFFSET <$FORMROOT/BUfiles >ss.filelist
NTAPES=$?
## CONFRIM EXTRA TAPES
FMORE=`expr $NTAPES \> 1`
if [ $FMORE = 1 ]
then
echo "This Backup requires more than one tape, backup aborted!"
rm -f ss.filelist
exit
fi
echo "Backup in progress."
if [ "$TTYPE" = "UNIX PC" ]
then
echo "ss.filelist" > /tmp/BUlist$$
cat /tmp/BUlist$$ $FORMROOT/BUfiles | \
tapecpio -ocT124 2>/tmp/size$$ | \
dbuf -oT124O$OFFSET > $TAPEDEVNAME
ERC=$?
else
OFFSET=0
cat $FORMROOT/BUfiles | \
tapecpio -ocT124 2>/tmp/size$$ | \
dbuf -oT124O$OFFSET > $TAPEDEVNAME
ERC=$?
fi
if [ "$ERC" != "0" ]
then
echo "Error in backup during tapecpio:"
echo " ERC = $ERC, OFFSET = $OFFSET, TAPE = $TAPEDEVNAME"
$SHROOT/Tgetname -w "BAD BACKUP" "$TPNAME" "" "" \
$OFFSET 0 0
exit
fi
$SHROOT/Tgetname -t
eval set `grep "blocks" /tmp/size$$`
NBLOCKS=$1
##
## PERFORM VERIFY PASS.
##
if [ "$VERIFY" = "Yes" ]
then
echo "Performing verify pass."
dbuf -iT124O$OFFSET"S"$NBLOCKS $TAPEDEVNAME |
tapecpio -ictT124 > /dev/null 2>&1
ERC=$?
if [ "$ERC" != "0" ]
then
echo \
"An error has been discovered while trying to verify this backup."
echo "Error in verify during tapecpio:"
echo " ERC = $ERC, TAPE = $TAPEDEVNAME"
## PLACE BAD BACKUP INFO ON BOTH TAPES.
$SHROOT/Tgetname -w "BAD BACKUP" "$TPNAME" "" "" \
$OFFSET 0 0
exit
fi
echo "Verification complete."
fi
date > $DATEFILE
##
## CREATE SAVE-SET INFORMATION TO PUT ON TAPE.
##
$SHROOT/Tgetname -t
if [ "$TTYPE" = "UNIX PC" ]
then
eval set `wc -l ss.filelist`
NFILES=$1
$SHROOT/Tgetname -w "$BTYPE" "$TPNAME" "$SSNAME" "$SSCMNT" \
$OFFSET $NBLOCKS $NFILES
ERC=$?
if [ "$ERC" != "0" ]
then
echo "An error $ERC occurred while trying to write to the tape."
exit
else
echo "$NFILES file(s), $NBLOCKS block(s)."
fi
else
$SHROOT/Tgetname -3
fi
##
## REMOVE GARBAGE FILES
##
##
## SET UP Tbackup.menu AND Backup.menu WITH LAST BACKUP DATES
##
BDATE=`cat -s /etc/.lastbackup`
UDATE=`cat -s /etc/.lastpartial`
if [ -z "$BDATE" ]
then
COM="has not been done yet."
PAR="has not been done yet."
set `cat -s /etc/.installdate`
elif [ -z "$UDATE" ]
then
set $BDATE
COM="last done on $2 $3."
PAR="has not been done yet."
else
set $BDATE $UDATE
COM="last done on $2 $3."
PAR="last done on $8 $9."
fi
cat > $FORMROOT/Tbackup.menu << END
Menu = Partial Backup includes files changed since $2 $3
Label = Backup to Tape
Prompt =Complete Backup saves whole system, Partial Backup saves changed items.
## NOTE:
##
## It is important that each name be unique in the nineth
## (9th) character position. This insures that the data
## will be transfered onto the tape in the correct coded
## format. The current default for unrecognized backup
## types is BUPARTIAL.
## v
Name = Complete Backup - $COM
Name = Partial Backup - $PAR
Name = Backup User
Name = Backup Folders
Name = Backup Files
Name = Backup by Names
END
cat > $FORMROOT/Backup.menu << END
Menu = Partial Backup includes files changed since $2 $3
Label = Backup
Prompt =Complete Backup saves whole system, Partial Backup saves changed items.
Name = Complete Backup - $COM
Name = Partial Backup - $PAR
Name = Backup one user
END
## CONFIRM COMPLETE
eval set $BTYPE
if [ "$1" = "Partial" ]
then
echo "The partial backup is now finished."
else
echo "The backup is now complete."
fi
) 2>&1 | mail $MAILTO
$SHROOT/Tgetname -l
rm -f /tmp/BUlist?*
rm -f /tmp/size?*
rm -f /tmp/error?*
rm -f $FORMROOT/BUfiles
rm -f ss.filelist
rm -f /tmp/tape.vtoc
--
Elliot Dierksen "I don't care if my lettuce has DDT on it,
as long as it's crisp!!" -- Jorma Kaukonen
Work) {att,codas}!candi!fang!ebd (407) 660-3377
Home) {peora,uunet,ucf-cs}!tarpit!alfred!elliot (407) 290-9744
More information about the Unix-pc.sources
mailing list