]>
Dogcows Code - chaz/tar/blob - scripts/level-1
447dbd220f3eedba0dc4d078b33c19ea6935566a
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.
11 # Insure `mail' is in PATH.
12 PATH
="/usr/ucb:${PATH}"
16 echo "The backup must be run as root or else some files will fail to be dumped."
20 # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
23 # Maybe sleep until around specified or default hour.
25 if [ "${1}" != "now" ]; then
26 if [ "${1}x" != "x" ]; then
32 pausetime
="`date | awk '
34 hr = substr($4, 1, 2);
35 mn = substr($4, 4, 2);
36 if((hr + 0) < (spec + 0))
37 print 3600 * (spec - hr) - 60 * mn;
39 print 3600 * (spec + (24 - hr)) - 60 * mn;
44 # Put your favorite message here. We just want a screenful of obnoxious
45 # caps warning people from messing with the dedicated terminal.
47 for (i = 0; i < 30; i++)
48 print " D O N O T T O U C H T H I S T E R M I N A L !!!!!"
56 # Put startdate in the subject line of mailed report, since if it happens
57 # to run longer than 24 hours (as may be the case if someone forgets to put
58 # in the next volume of the tape in adequate time), the backup date won't
59 # appear too misleading.
64 # Logfile name should be in the form ``log-1993-03-18-full''
65 # i.e. year-month-date. This format is useful for sorting by name.
66 LOGFILE
=log
-`date | awk '
68 d["Jan"] = "01"; d["Feb"] = "02"; d["Mar"] = "03";
69 d["Apr"] = "04"; d["May"] = "05"; d["Jun"] = "06";
70 d["Jul"] = "07"; d["Aug"] = "08"; d["Sep"] = "09";
71 d["Oct"] = "10"; d["Nov"] = "11"; d["Dec"] = "12";
76 print $6 "-" d[$2] "-" $3;
79 HOST
="`hostname | sed -e 's/\..*//'`"
81 TAR_PART1
="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
83 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
84 if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
85 TAR_PART1
="${TAR_PART1} --info-script=${DUMP_REMIND_SCRIPT}"
88 # Make sure the log file did not already exist. Create it.
90 if [ -f "${LOGFILE}" ] ; then
91 echo "Log file ${LOGFILE} already exists."
97 # Caveat: Some version of `mt' require `-t', not `-f'.
98 mt
-f "${TAPE_FILE}" rewind
101 set - "${BACKUP_DIRS}"
102 while [ $# -ne 0 ] ; do
103 host="`echo \"${1}\" | sed -e 's/:.*$//'`"
104 fs
="`echo \"${1}\" | sed -e 's/^.*://'`"
106 fsname
="`echo \"${1}\" | sed -e 's/\//:/g'`"
108 # This filename must be absolute; it is opened on the machine that runs tar.
109 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
110 TAR_PART3
="--label='level 1 backup of ${fs} on ${host} at ${date}' -C ${fs} ."
112 echo "Backing up ${1} at ${date}" | tee -a "${LOGFILE}"
113 echo "Last full dump on this filesystem:" | "tee -a ${LOGFILE}"
115 if [ "z${host}" != "z${HOST}" ] ; then
116 rsh "${host}" "ls -l /etc/tar-backup/${fsname}.level-0; \
117 cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1" 2>&1 \
118 | tee -a "${LOGFILE}"
120 ls -l /etc
/tar-backup/${fsname}.level
-0 2>&1 | tee -a ${LOGFILE}
121 cp /etc
/tar-backup/${fsname}.level
-0 /etc
/tar-backup/temp.level
-1 2>&1 | tee -a ${LOGFILE}
124 # Actually back things up.
126 if [ "z${host}" != "z${HOST}" ] ; then
127 rsh "${host}" ${TAR_PART1} -f ${HOST}:${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} 2>&1 \
128 | tee -a "${LOGFILE}"
130 # Using `sh -c exec' causes nested quoting and shell substitution
131 # to be handled here in the same way rsh handles it.
132 sh
-c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3}" 2>&1 | tee -a "${LOGFILE}"
135 # This doesn't presently work, of course, because $? is set to the exit
136 # status of the last thing in the pipeline of the previous command,
137 # namely `tee'. We really want the exit status of the sh command
138 # running tar, but getting this seems to be nontrivial. --friedman
139 if [ $?
-ne 0 ] ; then
140 echo "Backup of ${1} failed." | tee -a "${LOGFILE}"
141 # I'm assuming that the tar will have written an empty
142 # file to the tape, otherwise I should do a cat here.
144 if [ ${HOST} != ${host} ] ; then
145 rsh ${host} mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/${fsname}.level
-1 2>&1 \
148 mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/${fsname}.level
-1 2>&1 \
152 ${TAPE_STATUS} | tee -a "${LOGFILE}"
157 # Dump any individual files requested.
159 if [ "x${BACKUP_FILES}" != "x" ] ; then
161 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
162 TAR_PART3
="--label='Incremental backup of miscellaneous files at ${date}'"
164 echo "Backing up miscellaneous files at ${date}" | tee -a "${LOGFILE}"
165 echo "Last full dump of these files:" | tee -a "${LOGFILE}"
166 ls -l /etc
/tar-backup/misc.level
-0 2>&1 | tee -a "${LOGFILE}"
168 rm -f /etc
/tar-backup/temp.level
-1 2>&1 | tee -a "${LOGFILE}"
169 cp /etc
/tar-backup/misc.level
-0 /etc
/tar-backup/temp.level
-1 2>&1 | tee -a "${LOGFILE}"
171 # Using `sh -c exec' causes nested quoting and shell substitution
172 # to be handled here in the same way rsh handles it.
173 sh
-c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} ${BACKUP_FILES}" 2>&1 \
174 | tee -a "${LOGFILE}"
176 # This doesn't presently work, of course, because $? is set to the exit
177 # status of the last thing in the pipeline of the previous command,
178 # namely `tee'. We really want the exit status of the sh command
179 # running tar, but getting this seems to be nontrivial. --friedman
180 if [ $?
-ne 0 ] ; then
181 echo "Backup of miscellaneous files failed." | tee -a "${LOGFILE}"
182 # I'm assuming that the tar will have written an empty
183 # file to the tape, otherwise I should do a cat here.
185 mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/misc.level
-1 2>&1 | tee -a "${LOGFILE}"
187 ${TAPE_STATUS} | tee -a "${LOGFILE}"
189 echo "No miscellaneous files specified" | tee -a "${LOGFILE}"
192 # Caveat: some versions of `mt' use `-t' instead of `-f'.
193 mt
-f "${TAPE_FILE}" rewind
194 mt
-f "${TAPE_FILE}" offl
196 echo "Sending the dump log to ${ADMINISTRATOR}"
197 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
This page took 0.044436 seconds and 4 git commands to generate.