]> Dogcows Code - chaz/tar/blob - scripts/level-1
*** empty log message ***
[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 if [ ! -w / ]; then
12 echo The backup must be run as root,
13 echo 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}'`-level-1
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 #TAR_PART1="/usr/local/bin/tar -c --multi-volume --one-file-system --block=$BLOCKING "
48
49 # Make sure the log file did not already exist. Create it.
50
51 if [ -f $LOGFILE ] ; then
52 echo Log file $LOGFILE already exists.
53 exit 1
54 else
55 touch $LOGFILE
56 fi
57
58 mt -f $TAPE_FILE rewind
59 rm $VOLNO_FILE
60
61 set $BACKUP_DIRS
62 while [ $# -ne 0 ] ; do
63 host=`echo $1 | sed 's/:.*$//'`
64 fs=`echo $1 | sed 's/^.*://'`
65 date=`date`
66 fsname=`echo $1 | sed 's/\//:/g'`
67
68 # This filename must be absolute; it is opened on the machine that runs tar.
69 TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
70 TAR_PART3="--label='level 1 backup of $fs on $host at $date' -C $fs ."
71
72 echo Backing up $1 at $date | tee -a $LOGFILE
73 echo Last full dump on this filesystem: | tee -a $LOGFILE
74
75 if [ $HOST != $host ] ; then
76 rsh $host "ls -l /etc/tar-backup/$fsname.level-0; \
77 cp /etc/tar-backup/$fsname.level-0 /etc/tar-backup/temp.level-1" \
78 2>&1 | tee -a $LOGFILE
79 else
80 ls -l /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
81 cp /etc/tar-backup/$fsname.level-0 /etc/tar-backup/temp.level-1 2>&1 | tee -a $LOGFILE
82 fi
83
84 # Actually back things up.
85
86 if [ $HOST != $host ] ; then
87 rsh $host $TAR_PART1 -f $HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3 2>&1 | tee -a $LOGFILE
88 else
89 # Using `sh -c exec' causes nested quoting and shell substitution
90 # to be handled here in the same way rsh handles it.
91 sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3" 2>&1 | tee -a $LOGFILE
92 fi
93 if [ $? -ne 0 ] ; then
94 echo Backup of $1 failed. | tee -a $LOGFILE
95 # I'm assuming that the tar will have written an empty
96 # file to the tape, otherwise I should do a cat here.
97 else
98 if [ $HOST != $host ] ; then
99 rsh $host mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/$fsname.level-1 2>&1 | tee -a $LOGFILE
100 else
101 mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/$fsname.level-1 2>&1 | tee -a $LOGFILE
102 fi
103 fi
104 $TAPE_STATUS | tee -a $LOGFILE
105 sleep 60
106 shift
107 done
108
109 # Dump any individual files requested.
110
111 if [ x != "x$BACKUP_FILES" ] ; then
112 date=`date`
113 TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
114 TAR_PART3="--label='Incremental backup of miscellaneous files at $date'"
115
116 echo Backing up miscellaneous files at $date | tee -a $LOGFILE
117 echo Last full dump of these files: | tee -a $LOGFILE
118 ls -l /etc/tar-backup/misc.level-0 2>&1 | tee -a $LOGFILE
119
120 rm -f /etc/tar-backup/temp.level-1 2>&1 | tee -a $LOGFILE
121 cp /etc/tar-backup/misc.level-0 /etc/tar-backup/temp.level-1 2>&1 | tee -a $LOGFILE
122
123 echo Backing up miscellaneous files at $date | tee -a $LOGFILE
124 # Using `sh -c exec' causes nested quoting and shell substitution
125 # to be handled here in the same way rsh handles it.
126 sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3 \
127 $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
128 if [ $? -ne 0 ] ; then
129 echo Backup of miscellaneous files failed. | tee -a $LOGFILE
130 # I'm assuming that the tar will have written an empty
131 # file to the tape, otherwise I should do a cat here.
132 else
133 mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/misc.level-1 2>&1 | tee -a $LOGFILE
134 fi
135 $TAPE_STATUS | tee -a $LOGFILE
136 else
137 echo No miscellaneous files specified | tee -a $LOGFILE
138 false
139 fi
140
141 mt -f $TAPE_FILE rewind
142 mt -f $TAPE_FILE offl
143
144 echo Sending the dump log to $ADMINISTRATOR
145 cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
146 /usr/ucb/mail -s "Results of backup on `date`" $ADMINISTRATOR < $LOGFILE.tmp
This page took 0.04318 seconds and 4 git commands to generate.