]>
Dogcows Code - chaz/tar/blob - scripts/level-1
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 # Useful for backup-specs, in case things have to be done slightly
12 # differently for different dump levels.
15 # Insure `mail' is in PATH.
16 PATH
="/usr/ucb:${PATH}"
19 # This is not the most reliable test in the world. The following might be
23 # euid="`sed -ne '/^'\"${whoami}\"':/{s/^[^:]*:[^:]*://;s/:.*//p;q;}' /etc/passwd`"
24 # if [ "${euid}" != 0 ]; then ...
27 echo "The backup must be run as root or else some files will fail to be dumped."
31 # Get the values of BACKUP_DIRS, BACKUP_FILES, and other variables.
34 # Maybe sleep until around specified or default hour.
35 if [ "z${1}" != "znow" ]; then
36 if [ "${1}x" != "x" ]; then
42 pausetime
="`date | awk '
44 hr = substr($4, 1, 2);
45 mn = substr($4, 4, 2);
46 if((hr + 0) < (spec + 0))
47 print 3600 * (spec - hr) - 60 * mn;
49 print 3600 * (spec + (24 - hr)) - 60 * mn;
53 echo "${SLEEP_MESSAGE}"
59 # Put startdate in the subject line of mailed report, since if it happens
60 # to run longer than 24 hours (as may be the case if someone forgets to put
61 # in the next volume of the tape in adequate time), the backup date won't
62 # appear too misleading.
67 # Logfile name should be in the form ``log-1993-03-18-level-1''
68 # i.e. year-month-date. This format is useful for sorting by name, since
69 # logfiles are intentionally kept online for future reference.
70 LOGFILE
=log
-`date | awk '
72 d["Jan"] = "01"; d["Feb"] = "02"; d["Mar"] = "03";
73 d["Apr"] = "04"; d["May"] = "05"; d["Jun"] = "06";
74 d["Jul"] = "07"; d["Aug"] = "08"; d["Sep"] = "09";
75 d["Oct"] = "10"; d["Nov"] = "11"; d["Dec"] = "12";
78 if ($3 < 10) $3 = "0" $3;
79 print $6 "-" d[$2] "-" $3;
80 }'`-level-${DUMP_LEVEL}
82 localhost
="`hostname | sed -e 's/\..*//'`"
84 TAR_PART1
="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
86 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
87 if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
88 TAR_PART1
="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
91 # Make sure the log file did not already exist. Create it.
93 if [ -f "${LOGFILE}" ] ; then
94 echo "Log file ${LOGFILE} already exists." 1>&2
100 # Most everything below here is run in a subshell for which all output is
101 # piped through `tee' to the logfile. Doing this, instead of having
102 # multiple pipelines all over the place, is cleaner and allows access to
103 # the exit value from various commands more easily.
105 # Caveat: Some version of `mt' require `-t', not `-f'.
106 mt
-f "${TAPE_FILE}" rewind
107 rm -f "${VOLNO_FILE}"
110 while [ $# -ne 0 ] ; do
112 remotehost
="`echo \"${1}\" | sed -e 's/:.*$//'`"
113 fs
="`echo \"${1}\" | sed -e 's/^.*://'`"
114 fsname
="`echo \"${1}\" | sed -e 's/\//:/g'`"
116 # This filename must be absolute; it is opened on the machine that runs tar.
117 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
118 TAR_PART3
="--label='level 1 backup of ${fs} on ${remotehost} at ${date}' -C ${fs} ."
120 echo "Backing up ${1} at ${date}"
121 echo "Last full dump on this filesystem:"
123 if [ "z${remotehost}" != "z${localhost}" ] ; then
124 rsh "${remotehost}" "ls -l /etc/tar-backup/${fsname}.level-0; \
125 cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1"
127 ls -l "/etc/tar-backup/${fsname}.level-0"
128 cp "/etc/tar-backup/${fsname}.level-0" /etc
/tar-backup/temp.level
-1
131 # Actually back things up.
133 if [ "z${remotehost}" != "z${localhost}" ] ; then
134 rsh "${remotehost}" ${TAR_PART1} -f "${localhost}:${TAPE_FILE}" ${TAR_PART2} ${TAR_PART3}
136 # Using `sh -c exec' causes nested quoting and shell substitution
137 # to be handled here in the same way rsh handles it.
138 sh
-c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3}"
141 # `rsh' doesn't exit with the exit status of the remote command. What
142 # stupid lossage. TODO: think of a reliable workaround.
143 if [ $?
-ne 0 ] ; then
144 echo "Backup of ${1} failed."
145 # I'm assuming that the tar will have written an empty
146 # file to the tape, otherwise I should do a cat here.
148 if [ "z${localhost}" != "z${remotehost}" ] ; then
149 rsh "${remotehost}" mv -f /etc
/tar-backup/temp.level
-1 "/etc/tar-backup/${fsname}.level-1"
151 mv -f /etc
/tar-backup/temp.level
-1 "/etc/tar-backup/${fsname}.level-1"
159 # Dump any individual files requested.
161 if [ "x${BACKUP_FILES}" != "x" ] ; then
163 TAR_PART2
="--listed=/etc/tar-backup/temp.level-1"
164 TAR_PART3
="--label='Incremental backup of miscellaneous files at ${date}'"
166 echo "Backing up miscellaneous files at ${date}"
167 echo "Last full dump of these files:"
168 ls -l /etc
/tar-backup/misc.level
-0
170 rm -f /etc
/tar-backup/temp.level
-1
171 cp /etc
/tar-backup/misc.level
-0 /etc
/tar-backup/temp.level
-1
173 # Using `sh -c exec' causes nested quoting and shell substitution
174 # to be handled here in the same way rsh handles it.
175 sh
-c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3} ${BACKUP_FILES}"
177 if [ $?
-ne 0 ] ; then
178 echo "Backup of miscellaneous files failed." 1>&2
179 # I'm assuming that the tar will have written an empty
180 # file to the tape, otherwise I should do a cat here.
182 mv -f /etc
/tar-backup/temp.level
-1 /etc
/tar-backup/misc.level
-1
186 echo "No miscellaneous files specified"
189 # Caveat: some versions of `mt' use `-t' instead of `-f'.
190 mt
-f "${TAPE_FILE}" rewind
191 mt
-f "${TAPE_FILE}" offl
193 ) 2>&1 | tee -a "${LOGFILE}"
195 echo "Sending the dump log to ${ADMINISTRATOR}"
196 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
This page took 0.044155 seconds and 4 git commands to generate.