4 # Copyright 2004-2006, 2013 Free Software Foundation
6 # This file is part of GNU tar.
8 # GNU tar is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU tar is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Load library routines
22 SYSCONFDIR
=${SYSCONFDIR-@sysconfdir@}
23 .
${LIBDIR-@libexecdir@}/backup.sh
31 usage: $PROGNAME [OPTIONS] [WHEN]
34 -l, --level=LEVEL Do backup level LEVEL (default $DUMP_LEVEL).
35 -f, --force Force backup even if today's log file already
37 -v, --verbose[=LEVEL] Set verbosity level. Default 100.
38 -t, --time=TIME Wait till TIME, then do backup.
40 Informational options:
41 -h, --help Display this help message.
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?
*) DUMP_LEVEL
=`expr $option : '-l\(.*\)'`;;
77 -l|
--l|
--le|
--lev|
--leve|
--level)
80 --verb=*|
--verbo=*|
--verbos=*|
--verbose=*)
83 -v|
--verb|
--verbo|
--verbos|
--verbose)
86 -v*) VERBOSE
=`expr $option : '-v\(.*\)'`;;
87 --t=*|
--ti=*|
--tim=*|
--time=*)
90 -t?
*) TIME
=`expr $option : '-t\(.*\)'`;;
91 -t|
--t|
--ti|
--tim|
--time)
94 -V|
--v|
--ve|
--ver|
--vers|
--versi|
--versio|
--version)
95 echo "backup (@PACKAGE_NAME@) @VERSION@"
98 -h|
--h|
--he|
--hel|
--help)
101 -f|
--f|
--fo|
--for|
--forc|
--force)
104 *) if [ "x$TIME" != "x" ]; then
105 bailout
"Extra argument. Try $PROGNAME --help for more info."
112 if [ "x$TIME" = x
]; then
113 bailout
"No backup time specified. Try $PROGNAME --help for more info."
119 # Maybe sleep until around specified or default hour.
122 if [ $DUMP_LEVEL -ne 0 ]; then
123 PREV_LEVEL
=`expr $DUMP_LEVEL - 1`
124 PREV_DATE
=`ls -t ${LOGPATH}/log-*-level-$PREV_LEVEL|
126 sed "s,${LOGPATH}/log-\(.*\)-level.*,\1,"`
127 if [ "x$PREV_DATE" = x
]; then
128 bailout
"Can't determine date of the previous backup"
130 message
0 "Backup from $PREV_DATE to $NOW"
135 # Make sure the log file did not already exist. Create it.
137 if [ "x$FORCE" = "xyes" ]; then
141 if [ -f "${LOGFILE}" ] ; then
142 bailout
"Log file ${LOGFILE} already exists."
146 message
1 "Ready for backup."
147 message
10 "TAR invocation: $TAR_PART1"
148 message
20 "Variables:"
149 message
20 "BACKUP_DIRS=$BACKUP_DIRS"
150 message
20 "BACKUP_FILES=$BACKUP_FILES"
152 # The buch of commands below is run in a subshell for which all output is
153 # piped through 'tee' to the logfile. Doing this, instead of having
154 # multiple pipelines all over the place, is cleaner and allows access to
155 # the exit value from various commands more easily.
157 message
1 "preparing tapes"
158 if ! $MT_BEGIN "${TAPE_FILE}"; then
159 echo >&2 "$0: tape initialization failed"
162 rm -f "${VOLNO_FILE}"
164 message
1 "processing backup directories"
167 while [ $# -ne 0 ] ; do
169 fs
="`echo \"${1}\" | sed -e 's/^.*://'`"
171 fsname
="`echo \"${1}\" | sed -e 's/\//:/g'`"
172 remotehost
="`expr \"${1}\" : '\([^/][^/]*\):.*'`"
173 if [ -z "$remotehost" ]; then
174 remotehost
=$localhost
177 echo "Backing up ${1} at ${date}"
179 message
10 "fsname=$fsname"
180 message
10 "remotehost=$remotehost"
181 if [ $DUMP_LEVEL -eq 0 ]; then
182 make_level_log
${remotehost}
184 echo "Last `prev_level` dump on this filesystem was on $PREV_DATE"
185 remote_run
"${remotehost}" cp "`level_log_name ${fsname} $PREV_LEVEL`" "`level_log_name temp`"
188 ${DUMP_BEGIN-:} $DUMP_LEVEL $remotehost $fs $fsname
189 backup_host
${remotehost} \
190 "--listed=`level_log_name temp`" \
191 "--label='`print_level` backup of ${fs} on ${remotehost} at ${NOW}'" \
194 # 'rsh' doesn't exit with the exit status of the remote command. What
195 # stupid lossage. TODO: think of a reliable workaround.
196 if [ $?
-ne 0 ] ; then
197 echo "$0: backup of ${1} failed." 1>&2
198 # I'm assuming that the tar will have written an empty
199 # file to the tape, otherwise I should do a cat here.
201 flush_level_log
${remotehost} ${fsname}
203 ${MT_STATUS} "$TAPE_FILE"
204 ${DUMP_END-:} $DUMP_LEVEL $remotehost $fs $fsname
205 echo "sleeping ${SLEEP_TIME} seconds"
210 # Dump any individual files requested.
212 if [ "x${BACKUP_FILES}" != "x" ] ; then
213 message
1 "processing individual files"
217 if [ $DUMP_LEVEL -eq 0 ]; then
218 make_level_log
$localhost
220 echo "Last `prev_level` dump on this filesystem was on $PREV_DATE"
221 remote_run
"${localhost}" cp "`level_log_name MISC $PREV_LEVEL`" "`level_log_name temp`"
224 echo "Backing up miscellaneous files at ${date}"
226 ${DUMP_BEGIN-:} $DUMP_LEVEL $localhost MISC MISC
227 backup_host
$localhost \
228 "--listed=`level_log_name temp`"\
229 "--label='`print_level` backup of miscellaneous files at ${NOW}'" \
232 if [ $?
-ne 0 ] ; then
233 echo "Backup of miscellaneous files failed."
234 # I'm assuming that the tar will have written an empty
235 # file to the tape, otherwise I should do a cat here.
237 flush_level_log
$localhost MISC
239 ${MT_STATUS} "$TAPE_FILE"
240 ${DUMP_END-:} $DUMP_LEVEL $localhost MISC MISC
242 echo "No miscellaneous files specified"
244 message
1 "final cleanup"
246 $MT_REWIND "${TAPE_FILE}"
247 $MT_OFFLINE "${TAPE_FILE}"
249 ) 2>&1 |
tee -a "${LOGFILE}"
252 if test "${ADMINISTRATOR}" != NONE
; then
253 echo "Sending the dump log to ${ADMINISTRATOR}"
254 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"