3 # Run this script as root on the machine that has the tape drive, to make a
4 # level-1 dump containing all files changed since the last full dump.
6 # If you give `now' as an argument, the dump is done immediately.
7 # Otherwise, it waits until 1am.
9 # You must edit the file `backup-specs' to set the parameters for your site.
12 echo The backup must be run as root
,
13 echo or
else some files will fail to be dumped.
19 # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
22 # Maybe sleep until around specified or default hour.
24 if [ "${1}" != "now" ]; then
25 if [ "${1}"x
!= x
]; then
30 pausetime
=`date | awk '{hr=substr($4,1,2);\\
33 print 3600*(spec-hr)-60*mn;\\
35 print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
44 LOGFILE
=log
-`date | awk '{print $2 "-" $3 "-" $6}'`-level-1
45 HOST
=`hostname | sed 's/\..*//'`
46 TAR_PART1
="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
48 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
49 if [ x
!= "x${DUMP_REMIND_SCRIPT}" ]; then
50 TAR_PART1
="${TAR_PART1} --info-script=${DUMP_REMIND_SCRIPT}"
53 # Make sure the log file did not already exist. Create it.
55 if [ -f ${LOGFILE} ] ; then
56 echo Log
file ${LOGFILE} already exists.
62 mt
-f ${TAPE_FILE} rewind
66 while [ $# -ne 0 ] ; do
67 host=`echo ${1} | sed 's/:.*$//'`
68 fs
=`echo ${1} | sed 's/^.*://'`
70 fsname
=`echo ${1} | sed 's/\//:/g'`
72 # This filename must be absolute; it is opened on the machine that runs tar.
73 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
74 TAR_PART3
="--label='level 1 backup of ${fs} on ${host} at ${date}' -C ${fs} ."
76 echo Backing up
${1} at ${date} | tee -a ${LOGFILE}
77 echo Last full dump on this filesystem
: | tee -a ${LOGFILE}
79 if [ ${HOST} != ${host} ] ; then
80 rsh ${host} "ls -l /etc/tar-backup/${fsname}.level-0; \
81 cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1" \
82 2>&1 | tee -a ${LOGFILE}
84 ls -l /etc
/tar-backup/${fsname}.level
-0 2>&1 | tee -a ${LOGFILE}
85 cp /etc
/tar-backup/${fsname}.level
-0 /etc
/tar-backup/temp.level
-1 2>&1 | tee -a ${LOGFILE}
88 # Actually back things up.
90 if [ ${HOST} != ${host} ] ; then
91 rsh ${host} ${TAR_PART1} -f ${HOST}:${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} 2>&1 | tee -a ${LOGFILE}
93 # Using `sh -c exec' causes nested quoting and shell substitution
94 # to be handled here in the same way rsh handles it.
95 sh
-c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3}" 2>&1 | tee -a ${LOGFILE}
97 # This doesn't presently work, of course, because $? is set to the exit
98 # status of the last thing in the pipeline of the previous command,
99 # namely `tee'. We really want the exit status of the sh command
100 # running tar, but getting this seems to be nontrivial. --friedman
101 if [ $?
-ne 0 ] ; then
102 echo Backup of
${1} failed.
| tee -a ${LOGFILE}
103 # I'm assuming that the tar will have written an empty
104 # file to the tape, otherwise I should do a cat here.
106 if [ ${HOST} != ${host} ] ; then
107 rsh ${host} mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/${fsname}.level
-1 2>&1 | tee -a ${LOGFILE}
109 mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/${fsname}.level
-1 2>&1 | tee -a ${LOGFILE}
112 ${TAPE_STATUS} | tee -a ${LOGFILE}
117 # Dump any individual files requested.
119 if [ x
!= "x${BACKUP_FILES}" ] ; then
121 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
122 TAR_PART3
="--label='Incremental backup of miscellaneous files at ${date}'"
124 echo Backing up miscellaneous files
at ${date} | tee -a ${LOGFILE}
125 echo Last full dump of these files
: | tee -a ${LOGFILE}
126 ls -l /etc
/tar-backup/misc.level
-0 2>&1 | tee -a ${LOGFILE}
128 rm -f /etc
/tar-backup/temp.level
-1 2>&1 | tee -a ${LOGFILE}
129 cp /etc
/tar-backup/misc.level
-0 /etc
/tar-backup/temp.level
-1 2>&1 | tee -a ${LOGFILE}
131 echo Backing up miscellaneous files
at ${date} | tee -a ${LOGFILE}
132 # Using `sh -c exec' causes nested quoting and shell substitution
133 # to be handled here in the same way rsh handles it.
134 sh
-c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} \
135 ${BACKUP_FILES}" 2>&1 | tee -a ${LOGFILE}
136 # This doesn't presently work, of course, because $? is set to the exit
137 # status of the last thing in the pipeline of the previous command,
138 # namely `tee'. We really want the exit status of the sh command
139 # running tar, but getting this seems to be nontrivial. --friedman
140 if [ $?
-ne 0 ] ; then
141 echo Backup of miscellaneous files failed.
| tee -a ${LOGFILE}
142 # I'm assuming that the tar will have written an empty
143 # file to the tape, otherwise I should do a cat here.
145 mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/misc.level
-1 2>&1 | tee -a ${LOGFILE}
147 ${TAPE_STATUS} | tee -a ${LOGFILE}
149 echo No miscellaneous files specified
| tee -a ${LOGFILE}
153 mt
-f ${TAPE_FILE} rewind
154 mt
-f ${TAPE_FILE} offl
156 echo Sending the dump log to
${ADMINISTRATOR}
157 cat ${LOGFILE} | sed -f logfile.
sed > ${LOGFILE}.tmp
158 /usr
/ucb
/mail -s "Results of backup on `date`" ${ADMINISTRATOR} < ${LOGFILE}.tmp