]> Dogcows Code - chaz/tar/blob - scripts/level-0
25571d4b15bf9850ff3c5b1b6de8375735188b02
[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 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 if [ ! -w / ]; then
13 echo The backup must be run as root or else some files will fail to be dumped.
14 exit 1
15 else
16 false
17 fi
18
19 # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
20 . ./backup-specs
21
22 # Maybe sleep until around specified or default hour.
23 #
24 if [ "${1}" != "now" ]; then
25 if [ "${1}x" != "x" ]; then
26 spec="${1}"
27 else
28 spec="${BACKUP_HOUR}"
29 fi
30 pausetime=`date | awk '{hr=substr($4,1,2);\\
31 mn=substr($4,4,2);\\
32 if((hr+0)<(spec+0))\\
33 print 3600*(spec-hr)-60*mn;\\
34 else\\
35 print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
36 clear
37 cat ./dont_touch
38 sleep ${pausetime}
39 fi
40
41 # start doing things
42
43 here=`pwd`
44 LOGFILE=log-`date | awk '{print $2 "-" $3 "-" $6}'`-full
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}"
47
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}"
51 fi
52
53 # Make sure the log file did not already exist. Create it.
54
55 if [ -f ${LOGFILE} ] ; then
56 echo Log file ${LOGFILE} already exists.
57 exit 1
58 else
59 touch ${LOGFILE}
60 fi
61
62 mt -f ${TAPE_FILE} rewind
63 rm ${VOLNO_FILE}
64
65 set ${BACKUP_DIRS}
66 while [ $# -ne 0 ] ; do
67 host=`echo ${1} | sed 's/:.*$//'`
68 fs=`echo ${1} | sed 's/^.*://'`
69 date=`date`
70 fsname=`echo $1 | sed 's/\//:/g'`
71
72 TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
73 TAR_PART3="--label='Full backup of ${fs} on ${host} at ${date}' -C ${fs} ."
74
75 echo Backing up ${1} at ${date} | tee -a ${LOGFILE}
76
77 # Actually back things up.
78
79 if [ ${HOST} != ${host} ] ; then
80 # Removed 2>&1/dev/null cruft since that's incorrect sh syntax.
81 rsh ${host} mkdir /etc/tar-backup > /dev/null 2>&1
82 rsh ${host} rm -f /etc/tar-backup/temp.level-0
83 rsh ${host} ${TAR_PART1} -f ${HOST}:${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} 2>&1 | tee -a ${LOGFILE}
84 else
85 mkdir /etc/tar-backup > /dev/null 2>&1
86 rm -f /etc/tar-backup/temp.level-0
87 # Using `sh -c exec' causes nested quoting and shell substitution
88 # to be handled here in the same way rsh handles it.
89 sh -c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3}" 2>&1 | tee -a ${LOGFILE}
90 fi
91 # This doesn't presently work, of course, because $? is set to the exit
92 # status of the last thing in the pipeline of the previous command,
93 # namely `tee'. We really want the exit status of the sh command
94 # running tar, but getting this seems to be nontrivial. --friedman
95 if [ $? -ne 0 ] ; then
96 echo Backup of ${1} failed. | tee -a ${LOGFILE}
97 # I'm assuming that the tar will have written an empty
98 # file to the tape, otherwise I should do a cat here.
99 else
100 if [ ${HOST} != ${host} ] ; then
101 rsh ${host} "mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/${fsname}.level-0" 2>&1 | tee -a ${LOGFILE}
102 else
103 mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/${fsname}.level-0 2>&1 | tee -a ${LOGFILE}
104 fi
105 fi
106 ${TAPE_STATUS} | tee -a ${LOGFILE}
107 sleep 60
108 shift
109 done
110
111 # Dump any individual files requested.
112
113 if [ x != "x${BACKUP_FILES}" ] ; then
114 date=`date`
115
116 TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
117 TAR_PART3="--label='Full backup of miscellaneous files at ${date}'"
118
119 mkdir /etc/tar-backup > /dev/null 2>&1
120 rm -f /etc/tar-backup/temp.level-0
121
122 echo Backing up miscellaneous files at ${date} | tee -a ${LOGFILE}
123 # Using `sh -c exec' causes nested quoting and shell substitution
124 # to be handled here in the same way rsh handles it.
125 sh -c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} \
126 ${BACKUP_FILES}" 2>&1 | tee -a ${LOGFILE}
127 # This doesn't presently work, of course, because $? is set to the exit
128 # status of the last thing in the pipeline of the previous command,
129 # namely `tee'. We really want the exit status of the sh command
130 # running tar, but getting this seems to be nontrivial. --friedman
131 if [ $? -ne 0 ] ; then
132 echo Backup of miscellaneous files failed. | tee -a ${LOGFILE}
133 # I'm assuming that the tar will have written an empty
134 # file to the tape, otherwise I should do a cat here.
135 else
136 mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0 2>&1 | tee -a ${LOGFILE}
137 fi
138 ${TAPE_STATUS} | tee -a ${LOGFILE}
139 else
140 echo No miscellaneous files specified | tee -a ${LOGFILE}
141 false
142 fi
143
144 mt -f ${TAPE_FILE} rewind
145 mt -f ${TAPE_FILE} offl
146
147 echo Sending the dump log to ${ADMINISTRATOR}
148 cat ${LOGFILE} | sed -f logfile.sed > ${LOGFILE}.tmp
149 /usr/ucb/mail -s "Results of backup on `date`" ${ADMINISTRATOR} < ${LOGFILE}.tmp
150 rm -f ${LOGFILE}.tmp
151
This page took 0.050765 seconds and 3 git commands to generate.