]> Dogcows Code - chaz/tar/blob - scripts/level-1
447dbd220f3eedba0dc4d078b33c19ea6935566a
[chaz/tar] / scripts / level-1
1 #!/bin/sh
2 #
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.
5 #
6 # If you give `now' as an argument, the dump is done immediately.
7 # Otherwise, it waits until 1am.
8 #
9 # You must edit the file `backup-specs' to set the parameters for your site.
10
11 # Insure `mail' is in PATH.
12 PATH="/usr/ucb:${PATH}"
13 export PATH
14
15 if [ ! -w / ]; then
16 echo "The backup must be run as root or else some files will fail to be dumped."
17 exit 1
18 fi
19
20 # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
21 . ./backup-specs
22
23 # Maybe sleep until around specified or default hour.
24 #
25 if [ "${1}" != "now" ]; then
26 if [ "${1}x" != "x" ]; then
27 spec="${1}"
28 else
29 spec="${BACKUP_HOUR}"
30 fi
31
32 pausetime="`date | awk '
33 {
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;
38 else
39 print 3600 * (spec + (24 - hr)) - 60 * mn;
40 }' spec=\"${spec}\"`"
41
42 clear
43
44 # Put your favorite message here. We just want a screenful of obnoxious
45 # caps warning people from messing with the dedicated terminal.
46 awk 'BEGIN {
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 !!!!!"
49 }' /dev/null
50
51 sleep "${pausetime}"
52 fi
53
54 # start doing things
55
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.
60 startdate="`date`"
61
62 here="`pwd`"
63
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 '
67 BEGIN {
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";
72 }
73 {
74 if ($3 < 10)
75 $3 = "0" $3;
76 print $6 "-" d[$2] "-" $3;
77 }'`-level-1
78
79 HOST="`hostname | sed -e 's/\..*//'`"
80
81 TAR_PART1="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
82
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}"
86 fi
87
88 # Make sure the log file did not already exist. Create it.
89
90 if [ -f "${LOGFILE}" ] ; then
91 echo "Log file ${LOGFILE} already exists."
92 exit 1
93 else
94 touch "${LOGFILE}"
95 fi
96
97 # Caveat: Some version of `mt' require `-t', not `-f'.
98 mt -f "${TAPE_FILE}" rewind
99 rm -f "${VOLNO_FILE}"
100
101 set - "${BACKUP_DIRS}"
102 while [ $# -ne 0 ] ; do
103 host="`echo \"${1}\" | sed -e 's/:.*$//'`"
104 fs="`echo \"${1}\" | sed -e 's/^.*://'`"
105 date="`date`"
106 fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
107
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} ."
111
112 echo "Backing up ${1} at ${date}" | tee -a "${LOGFILE}"
113 echo "Last full dump on this filesystem:" | "tee -a ${LOGFILE}"
114
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}"
119 else
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}
122 fi
123
124 # Actually back things up.
125
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}"
129 else
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}"
133 fi
134
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.
143 else
144 if [ ${HOST} != ${host} ] ; then
145 rsh ${host} mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/${fsname}.level-1 2>&1 \
146 | tee -a ${LOGFILE}
147 else
148 mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/${fsname}.level-1 2>&1 \
149 | tee -a ${LOGFILE}
150 fi
151 fi
152 ${TAPE_STATUS} | tee -a "${LOGFILE}"
153 sleep 60
154 shift
155 done
156
157 # Dump any individual files requested.
158
159 if [ "x${BACKUP_FILES}" != "x" ] ; then
160 date="`date`"
161 TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
162 TAR_PART3="--label='Incremental backup of miscellaneous files at ${date}'"
163
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}"
167
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}"
170
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}"
175
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.
184 else
185 mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/misc.level-1 2>&1 | tee -a "${LOGFILE}"
186 fi
187 ${TAPE_STATUS} | tee -a "${LOGFILE}"
188 else
189 echo "No miscellaneous files specified" | tee -a "${LOGFILE}"
190 fi
191
192 # Caveat: some versions of `mt' use `-t' instead of `-f'.
193 mt -f "${TAPE_FILE}" rewind
194 mt -f "${TAPE_FILE}" offl
195
196 echo "Sending the dump log to ${ADMINISTRATOR}"
197 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
198
199 # eof
This page took 0.046258 seconds and 3 git commands to generate.