]>
Dogcows Code - chaz/tar/blob - scripts/backup.in
2 # This program is part of GNU tar
3 # Copyright 2004, Free Software Foundation
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 1, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # Load library routines
21 SYSCONFDIR
=${SYSCONFDIR-@sysconfdir@}
22 .
${LIBDIR-@libexecdir@}/backup.sh
30 usage: $PROGNAME [OPTIONS] [WHEN]
33 -l, --level=LEVEL Do backup level LEVEL (default $DUMP_LEVEL).
34 -f, --force Force backup even if today's log file already
36 -v, --verbose[=LEVEL] Set verbosity level. Default 100.
37 -t, --time=TIME Wait till TIME, then do backup.
39 Informational options:
40 -h, --help Display this help message.
41 -L, --license Display program license.
42 -V, --version Display program version.
44 Optional argument WHEN is for backward compatibility only. It has been
45 superseded by --time option.
46 TIME argument can be one of:
48 now -- do backup immediately.
49 HH -- do backup at HH hours.
50 HH:MM -- do backup at HH:MM.
52 Send bug reports to @PACKAGE_BUGREPORT@.
56 # For compatibility with previous versions, deduce the backup level
57 # from the command name
59 level
-[0-9]) DUMP_LEVEL
=`expr $PROGNAME : 'level-\([0-9][0-9]*\)'`;;
64 if [ -z "$prev" ]; then
66 optarg
=`expr "x$opt" : 'x[^=]*=\(.*\)'`
73 --l=*|--le=*|--lev=*|--leve=*|--level=*)
76 -l|--l|--le|--lev|--leve|--level)
79 --verb=*|--verbo=*|--verbos=*|--verbose=*)
82 -v|--verb|--verbo|--verbos|--verbose)
85 -v*) VERBOSE
=`expr $option : "-v\(.*\)"`;;
86 --t=*|--ti=*|--tim=*|--time=*)
90 -t*) TIME
=`expr $option : "-t\(.*\)"`;;
91 --t|--ti|--tim|--time)
94 -V|--v|--ve|--ver|--vers|--versi|--versio|--version)
95 echo "backup (@PACKAGE@ @VERSION@)"
97 -L|--li|--lic|--lice|--licen|--licens|--license)
100 -h|--h|--he|--hel|--help)
103 -f|--f|--fo|--for|--forc|--force)
106 *) if [ "x$TIME" != "x" ]; then
107 bailout
"Extra argument. Try $PROGNAME --help for more info."
114 if [ "x$TIME" = x
]; then
115 bailout
"No backup time specified. Try $PROGNAME --help for more info."
121 # Maybe sleep until around specified or default hour.
124 if [ $DUMP_LEVEL -ne 0 ]; then
125 PREV_LEVEL
=`expr $DUMP_LEVEL - 1`
126 PREV_DATE
=`ls -t ${LOGPATH}/log-*-level-$PREV_LEVEL|
128 sed "s,${LOGPATH}/log-\(.*\)-level.*,\1,"`
129 if [ "x$PREV_DATE" = x
]; then
130 bailout
"Can't determine date of the previous backup"
132 message
0 "Backup from $PREV_DATE to $NOW"
137 # Make sure the log file did not already exist. Create it.
139 if [ "x$FORCE" = "xyes" ]; then
143 if [ -f "${LOGFILE}" ] ; then
144 bailout
"Log file ${LOGFILE} already exists."
148 message
1 "Ready for backup."
149 message
10 "TAR invocation: $TAR_PART1"
150 message
20 "Variables:"
151 message
20 "BACKUP_DIRS=$BACKUP_DIRS"
152 message
20 "BACKUP_FILES=$BACKUP_FILES"
154 # The buch of commands below is run in a subshell for which all output is
155 # piped through `tee' to the logfile. Doing this, instead of having
156 # multiple pipelines all over the place, is cleaner and allows access to
157 # the exit value from various commands more easily.
159 message
1 "preparing tapes"
160 $MT_BEGIN "${TAPE_FILE}"
161 rm -f "${VOLNO_FILE}"
163 message
1 "processing backup directories"
166 while [ $# -ne 0 ] ; do
168 fs
="`echo \"${1}\" | sed -e 's/^.*://'`"
169 fsname
="`echo \"${1}\" | sed -e 's/\//:/g'`"
170 remotehost
="`expr \"${1}\" : '\([^/][^/]*\):.*'`"
171 if [ -z "$remotehost" ]; then
172 remotehost
=$localhost
175 echo "Backing up ${1} at ${date}"
177 message
10 "fsname=$fsname"
178 message
10 "remotehost=$remotehost"
179 if [ $DUMP_LEVEL -eq 0 ]; then
180 make_level_log
${remotehost}
182 echo "Last `prev_level` dump on this filesystem was on $PREV_DATE"
183 remote_run
"${remotehost}" cp "`level_log_name ${fsname} $PREV_LEVEL`" "`level_log_name temp`"
186 ${DUMP_BEGIN-:} $DUMP_LEVEL $remotehost $fs $fsname
187 backup_host
${remotehost} \
188 "--listed=`level_log_name temp`" \
189 "--label='`print_level` backup of ${fs} on ${remotehost} at ${NOW}'" \
192 # `rsh' doesn't exit with the exit status of the remote command. What
193 # stupid lossage. TODO: think of a reliable workaround.
194 if [ $?
-ne 0 ] ; then
195 echo "Backup of ${1} failed." 1>&2
196 # I'm assuming that the tar will have written an empty
197 # file to the tape, otherwise I should do a cat here.
199 flush_level_log
${remotehost} ${fsname}
202 ${DUMP_END-:} $DUMP_LEVEL $remotehost $fs $fsname
203 echo "sleeping ${SLEEP_TIME} seconds"
208 # Dump any individual files requested.
210 if [ "x${BACKUP_FILES}" != "x" ] ; then
211 message
1 "processing individual files"
215 if [ $DUMP_LEVEL -eq 0 ]; then
216 make_level_log
$localhost
218 echo "Last `prev_level` dump on this filesystem was on $PREV_DATE"
219 remote_run
"${localhost}" cp "`level_log_name MISC $PREV_LEVEL`" "`level_log_name temp`"
222 echo "Backing up miscellaneous files at ${date}"
224 ${DUMP_BEGIN-:} $DUMP_LEVEL $localhost MISC MISC
225 backup_host
$localhost \
226 "--listed=`level_log_name temp`"\
227 "--label='`print_level` backup of miscellaneous files at ${NOW}'" \
230 if [ $?
-ne 0 ] ; then
231 echo "Backup of miscellaneous files failed."
232 # I'm assuming that the tar will have written an empty
233 # file to the tape, otherwise I should do a cat here.
235 flush_level_log
$localhost MISC
238 ${DUMP_END-:} $DUMP_LEVEL $localhost MISC MISC
240 echo "No miscellaneous files specified"
243 message
1 "final cleanup"
245 $MT_REWIND "${TAPE_FILE}"
246 $MT_OFFLINE "${TAPE_FILE}"
248 ) 2>&1 | tee -a "${LOGFILE}"
250 if test "${ADMINISTRATOR}" != NONE
; then
251 echo "Sending the dump log to ${ADMINISTRATOR}"
252 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
This page took 0.045844 seconds and 4 git commands to generate.