]> Dogcows Code - chaz/tar/blob - scripts/level-0
*** empty log message ***
[chaz/tar] / scripts / level-0
1 #!/bin/sh
2 #
3 # Run this script as root on the machine that has the tape drive, to make a
4 # full (level-0) dump.
5 #
6 # If you give `now' as an argument, the dump is done immediately.
7 # Otherwise, it waits until 1am, or until the hour given as argument.
8 # Specify the hour as a number from 0 to 23.
9 #
10 # You must edit the file `backup-specs' to set the parameters for your site.
11
12 # Useful for backup-specs, in case things have to be done slightly
13 # differently for different dump levels.
14 DUMP_LEVEL=0
15
16 # Insure `mail' is in PATH.
17 PATH="/usr/ucb:${PATH}"
18 export PATH
19
20 # This is not the most reliable test in the world. The following might be
21 # more predictable:
22 #
23 # whoami="`whoami`"
24 # euid="`sed -ne '/^'\"${whoami}\"':/{s/^[^:]*:[^:]*://;s/:.*//p;q;}' /etc/passwd`"
25 # if [ "${euid}" != 0 ]; then ...
26 #
27 if [ ! -w / ]; then
28 echo "The backup must be run as root or else some files will fail to be dumped."
29 exit 1
30 fi
31
32 # Get the values of BACKUP_DIRS, BACKUP_FILES, and other variables.
33 . ./backup-specs
34
35 # Maybe sleep until around specified or default hour.
36 if [ "${1}" != "now" ]; then
37 if [ "${1}x" != "x" ]; then
38 spec="${1}"
39 else
40 spec="${BACKUP_HOUR}"
41 fi
42
43 pausetime="`date | awk '
44 {
45 hr = substr($4, 1, 2);
46 mn = substr($4, 4, 2);
47 if((hr + 0) < (spec + 0))
48 print 3600 * (spec - hr) - 60 * mn;
49 else
50 print 3600 * (spec + (24 - hr)) - 60 * mn;
51 }' spec=\"${spec}\"`"
52
53 clear
54 echo "${SLEEP_MESSAGE}"
55 sleep "${pausetime}"
56 fi
57
58 # start doing things
59
60 # Put startdate in the subject line of mailed report, since if it happens
61 # to run longer than 24 hours (as may be the case if someone forgets to put
62 # in the next volume of the tape in adequate time), the backup date won't
63 # appear too misleading.
64 startdate="`date`"
65
66 here="`pwd`"
67
68 # Logfile name should be in the form ``log-1993-03-18-level-0''
69 # i.e. year-month-date. This format is useful for sorting by name, since
70 # logfiles are intentionally kept online for future reference.
71 LOGFILE=log-`date | awk '
72 BEGIN {
73 d["Jan"] = "01"; d["Feb"] = "02"; d["Mar"] = "03";
74 d["Apr"] = "04"; d["May"] = "05"; d["Jun"] = "06";
75 d["Jul"] = "07"; d["Aug"] = "08"; d["Sep"] = "09";
76 d["Oct"] = "10"; d["Nov"] = "11"; d["Dec"] = "12";
77 }
78 {
79 if ($3 < 10)
80 $3 = "0" $3;
81 print $6 "-" d[$2] "-" $3;
82 }'`-level-${DUMP_LEVEL}
83
84 localhost="`hostname | sed -e 's/\..*//'`"
85
86 TAR_PART1="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
87
88 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
89 if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
90 TAR_PART1="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
91 fi
92
93 # Make sure the log file did not already exist. Create it.
94
95 if [ -f "${LOGFILE}" ] ; then
96 echo "Log file ${LOGFILE} already exists." 1>&2
97 exit 1
98 else
99 touch "${LOGFILE}"
100 fi
101
102 # Most everything below here is run in a subshell for which all output is
103 # piped through `tee' to the logfile. Doing this, instead of having
104 # multiple pipelines all over the place, is cleaner and allows access to
105 # the exit value from various commands more easily.
106 (
107 # Caveat: Some version of `mt' require `-t', not `-f'.
108 mt -f "${TAPE_FILE}" rewind
109 rm -f "${VOLNO_FILE}"
110
111 set - ${BACKUP_DIRS}
112 while [ $# -ne 0 ] ; do
113 date="`date`"
114 remotehost="`echo \"${1}\" | sed -e 's/:.*$//'`"
115 fs="`echo \"${1}\" | sed -e 's/^.*://'`"
116 fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
117
118 # This filename must be absolute; it is opened on the machine that runs tar.
119 TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
120 TAR_PART3="--label='Full backup of ${fs} on ${remotehost} at ${date}' -C ${fs} ."
121
122 echo "Backing up ${1} at ${date}"
123
124 # Actually back things up.
125
126 if [ "z${localhost}" != "z${remotehost}" ] ; then
127 rsh "${remotehost}" mkdir /etc/tar-backup > /dev/null 2>&1
128 rsh "${remotehost}" rm -f /etc/tar-backup/temp.level-0
129 rsh "${remotehost}" ${TAR_PART1} -f "${localhost}:${TAPE_FILE}" ${TAR_PART2} ${TAR_PART3}
130 else
131 mkdir /etc/tar-backup > /dev/null 2>&1
132 rm -f /etc/tar-backup/temp.level-0
133 # Using `sh -c exec' causes nested quoting and shell substitution
134 # to be handled here in the same way rsh handles it.
135 sh -c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3}"
136 fi
137
138 # `rsh' doesn't exit with the exit status of the remote command. What
139 # stupid lossage. TODO: think of a reliable workaround.
140 if [ $? -ne 0 ] ; then
141 echo "Backup of ${1} failed." 1>&2
142 # I'm assuming that the tar will have written an empty
143 # file to the tape, otherwise I should do a cat here.
144 else
145 if [ "z${localhost}" != "z${remotehost}" ] ; then
146 rsh "${remotehost}" mv -f /etc/tar-backup/temp.level-0 "/etc/tar-backup/${fsname}.level-0"
147 else
148 mv -f /etc/tar-backup/temp.level-0 "/etc/tar-backup/${fsname}.level-0"
149 fi
150 fi
151 ${TAPE_STATUS}
152 sleep 60
153 shift
154 done
155
156 # Dump any individual files requested.
157
158 if [ "x${BACKUP_FILES}" != "x" ] ; then
159 date="`date`"
160
161 TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
162 TAR_PART3="--label='Full backup of miscellaneous files at ${date}'"
163
164 mkdir /etc/tar-backup > /dev/null 2>&1
165 rm -f /etc/tar-backup/temp.level-0
166
167 echo "Backing up miscellaneous files at ${date}"
168
169 # Using `sh -c exec' causes nested quoting and shell substitution
170 # to be handled here in the same way rsh handles it.
171 sh -c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3} ${BACKUP_FILES}"
172
173 # `rsh' doesn't exit with the exit status of the remote command. What
174 # lossage. TODO: think of a reliable workaround.
175 if [ $? -ne 0 ] ; then
176 echo "Backup of miscellaneous files failed."
177 # I'm assuming that the tar will have written an empty
178 # file to the tape, otherwise I should do a cat here.
179 else
180 mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0
181 fi
182 ${TAPE_STATUS}
183 else
184 echo "No miscellaneous files specified"
185 fi
186
187 # Caveat: some versions of `mt' use `-t' instead of `-f'.
188 mt -f "${TAPE_FILE}" rewind
189 mt -f "${TAPE_FILE}" offl
190
191 ) 2>&1 | tee -a "${LOGFILE}"
192
193 echo "Sending the dump log to ${ADMINISTRATOR}"
194 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
195
196 # eof
This page took 0.04239 seconds and 4 git commands to generate.