]>
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 .
${LIBPATH-@libexecdir@}/backup.sh
29 sed 's/[^ ]* *\([^ ]*\) *\([^ ]*\).* \([^ ]*\)$/\3-\1-\2/
30 /-[0-9]$/s/\([0-9]\)$/0\1/
51 usage: $PROGNAME [OPTIONS] [WHEN]
54 -l, --level LEVEL Do backup level LEVEL (default $DUMP_LEVEL).
55 -f, --force Force backup even if today's log file already
57 -v, --verbose LEVEL Set verbosity level.
58 -t, --time TIME Wait till TIME, then do backup.
60 Informational options:
61 -h, --help Display this help message.
62 -l, --license Display program license.
63 -V, --version Display program version.
65 Optional argumen WHEN is for backward compatibility only. It has been
66 superseded by --time option.
67 TIME argument can be one of:
69 now -- do backup immediately.
70 HH -- do backup at HH hours.
71 HH:MM -- do backup at HH:MM.
74 Send bug reports to @PACKAGE_BUGREPORT@.
78 # For compatibility with previous versions, deduce the backup level
79 # from the command name
81 level
-[0-9]) DUMP_LEVEL
=`expr $PROGNAME : 'level-\([0-9][0-9]*\)'`;;
87 -l|--l|--le|--lev|--leve|--level)
91 -v|--verb|--verbo|--verbos|--verbose)
95 -V|--v|--ve|--ver|--vers|--versi|--versio|--version)
96 echo "backup; @PACKAGE@ (@VERSION@)"
98 -L|--li|--lic|--lice|--licen|--licens|--license)
101 -t|--ti|--tim|--time)
105 -f|--f|--fo|--for|--forc|--force)
108 -h|--h|--he|--hel|--help)
111 *) if [ "x$TIME" != "x" ]; then
112 bailout
"Extra argument. Try $PROGNAME --help for more info."
120 if [ "x$TIME" = x
]; then
121 bailout
"No backup time specified. Try $PROGNAME --help for more info."
127 # Maybe sleep until around specified or default hour.
130 if [ $DUMP_LEVEL -ne 0 ]; then
131 PREV_LEVEL
=`expr $DUMP_LEVEL - 1`
132 PREV_DATE
=`ls -t ${LOGPATH}/log-*-level-$PREV_LEVEL|
134 sed "s,${LOGPATH}/log-\(.*\)-level.*,\1,"`
135 if [ "x$PREV_DATE" = x
]; then
136 bailout
"Can't determine date of the previous backup"
138 message
0 "Backup from $PREV_DATE to $NOW"
143 # Make sure the log file did not already exist. Create it.
145 if [ "x$FORCE" = "xyes" ]; then
149 if [ -f "${LOGFILE}" ] ; then
150 bailout
"Log file ${LOGFILE} already exists."
154 message
1 "Ready for backup."
155 message
10 "TAR invocation: $TAR_PART1"
156 message
20 "Variables:"
157 message
20 "BACKUP_DIRS=$BACKUP_DIRS"
158 message
20 "BACKUP_FILES=$BACKUP_FILES"
160 # The buch of commands below is run in a subshell for which all output is
161 # piped through `tee' to the logfile. Doing this, instead of having
162 # multiple pipelines all over the place, is cleaner and allows access to
163 # the exit value from various commands more easily.
165 message
1 "preparing tapes"
166 $MT_BEGIN "${TAPE_FILE}"
167 rm -f "${VOLNO_FILE}"
169 message
1 "processing backup directories"
172 while [ $# -ne 0 ] ; do
174 fs
="`echo \"${1}\" | sed -e 's/^.*://'`"
175 fsname
="`echo \"${1}\" | sed -e 's/\//:/g'`"
176 remotehost
="`expr \"${1}\" : '\([^/][^/]*\):.*'`"
177 if [ -z "$remotehost" ]; then
178 remotehost
=$localhost
181 echo "Backing up ${1} at ${date}"
183 message
10 "fsname=$fsname"
184 message
10 "remotehost=$remotehost"
185 if [ $DUMP_LEVEL -eq 0 ]; then
186 make_level_log
${remotehost}
188 LF
=`level_log_name ${fsname} 0`
189 pdate
=`remote_run "${remotehost}" ls -l $LF | awk '{
194 echo "Last `prev_level` dump on this filesystem was on $pdate"
195 remote_run
"${remotehost}" cp $LF "`level_log_name temp`"
198 backup_host
${remotehost} \
199 "--listed=`level_log_name temp`" \
200 "--label='`print_level` backup of ${fs} on ${remotehost} at ${date}'" \
203 # `rsh' doesn't exit with the exit status of the remote command. What
204 # stupid lossage. TODO: think of a reliable workaround.
205 if [ $?
-ne 0 ] ; then
206 echo "Backup of ${1} failed." 1>&2
207 # I'm assuming that the tar will have written an empty
208 # file to the tape, otherwise I should do a cat here.
210 flush_level_log
${remotehost} ${fsname}
213 echo "sleeping ${SLEEP_TIME} seconds"
218 # Dump any individual files requested.
220 if [ "x${BACKUP_FILES}" != "x" ] ; then
221 message
1 "processing individual files"
225 make_level_log
$localhost
227 echo "Backing up miscellaneous files at ${date}"
229 backup_host
$localhost \
230 "--listed=`level_log_name temp`"\
231 "--label='`print_level` backup of miscellaneous files at ${date}'" \
234 if [ $?
-ne 0 ] ; then
235 echo "Backup of miscellaneous files failed."
236 # I'm assuming that the tar will have written an empty
237 # file to the tape, otherwise I should do a cat here.
239 flush_level_log
$localhost
243 echo "No miscellaneous files specified"
246 message
1 "final cleanup"
248 $MT_REWIND "${TAPE_FILE}"
249 $MT_OFFLINE "${TAPE_FILE}"
251 ) 2>&1 | tee -a "${LOGFILE}"
253 echo "Sending the dump log to ${ADMINISTRATOR}"
254 mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
This page took 0.047379 seconds and 4 git commands to generate.