]>
Dogcows Code - chaz/tar/blob - scripts/backup.sh.in
2 # This program is part of GNU tar
3 # Copyright 2004, 2005, 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., 51 Franklin Street, Fifth Floor, Boston, MA
20 PROGNAME
=`basename $0`
21 CONFIGPATH
="$SYSCONFDIR/backup"
22 REMOTEBACKUPDIR
="$SYSCONFDIR/tar-backup"
23 CONFIGFILE
=${CONFIGPATH}/backup
-specs
24 DIRLIST
=${CONFIGPATH}/dirs
25 FILELIST
=${CONFIGPATH}/files
26 LOGPATH
=${CONFIGPATH}/log
28 # Default functions for running various magnetic tape commands
45 # The main configuration file may override any of these variables
51 # Insure `mail' is in PATH.
52 PATH
="/usr/ucb:${PATH}"
54 # Put startdate in the subject line of mailed report, since if it happens
55 # to run longer than 24 hours (as may be the case if someone forgets to put
56 # in the next volume of the tape in adequate time), the backup date won't
57 # appear too misleading.
61 localhost
="`hostname | sed -e 's/\..*//' | tr A-Z a-z`"
63 # Produce a diagnostic output
65 if [ "$VERBOSE" != "" ]; then
66 if [ $VERBOSE -ge $1 ]; then
75 echo "$PROGNAME: $*" >&2
85 sed 's/[^ ]* *\([^ ]*\) *\([^ ]*\).* \([^ ]*\)$/\3-\1-\2/
86 /-[0-9]$/s/\([0-9]\)$/0\1/
102 # Bail out if we don't have root privileges.
104 if [ ! -w ${ROOT_FS-/} ]; then
105 bailout
"The backup must be run as root or else some files will fail to be dumped."
110 echo "${ROOT_FS}$1" | tr -s /
114 echo "Directory $1 is not found." >&2
116 The following directories and files are needed for the backup to function:
118 1. Directory with configuration files and file lists:
120 2. Directory for backup log files
122 3. Main configuration file
125 Please, create these and invoke the script again.
130 # Check if the necessary directories exist
131 if [ ! -d $CONFIGPATH ]; then
135 if [ ! -d $LOGPATH ]; then
136 if mkdir $LOGPATH; then
143 # Get the values of BACKUP_DIRS, BACKUP_FILES, and other variables.
144 if [ ! -r $CONFIGFILE ]; then
145 echo "$PROGNAME: cannot read $CONFIGFILE. Stop." >&2
150 # Environment sanity check
154 if [ x
"${ADMINISTRATOR}" = x
]; then
155 bailout
"ADMINISTRATOR not defined"
158 [ x
"$TAR" = x
] && TAR
=tar
159 [ x
"$SLEEP_TIME" = x
] && SLEEP_TIME
=60
161 if [ x
$VOLNO_FILE = x
]; then
162 bailout
"VOLNO_FILE not specified"
165 if [ -r $DIRLIST ]; then
166 BACKUP_DIRS
="$BACKUP_DIRS `cat $DIRLIST`"
168 if [ -r $FILELIST ]; then
169 BACKUP_FILES
="$BACKUP_FILES `cat $FILELIST`"
172 if [ \
( x
"$BACKUP_DIRS" = x \
) -a \
( x
"$BACKUP_FILES" = x \
) ]; then
173 bailout
"Neither BACKUP_DIRS nor BACKUP_FILES specified"
175 if [ -z "$RSH" ]; then
179 MT_RSH_OPTION
="--rsh-command=$RSH"
181 if [ -z "$TAPE_FILE" ]; then
185 # If TAPE_FILE is a remote device, update mt invocation accordingly
188 *:*) MT
="$MT $MT_RSH_OPTION";;
193 export POSIXLY_CORRECT
198 TAR_PART1
="${TAR} -c --format=gnu --multi-volume --one-file-system --sparse --volno-file=${VOLNO_FILE}"
199 if [ "x$XLIST" != x
]; then
200 TAR_PART1
="${TAR_PART1} \`test -r $REMOTEBACKUPDIR/$XLIST && echo \"--exclude-from $REMOTEBACKUPDIR/$XLIST\"\`"
202 if [ "$RSH_COMMAND" != "" ]; then
203 TAR_PART1
="${TAR_PART1} --rsh-command=$RSH_COMMAND"
205 if [ x
$BLOCKING != x
]; then
206 TAR_PART1
="${TAR_PART1} --blocking=${BLOCKING}"
209 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
210 if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
211 TAR_PART1
="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
214 # Logfile name should be in the form ``log-1993-03-18-level-0''
215 # They go in the directory `@sysconfdir@/log'.
216 # i.e. year-month-date. This format is useful for sorting by name, since
217 # logfiles are intentionally kept online for future reference.
218 LOGFILE
="${LOGPATH}/log-`now`-level-${DUMP_LEVEL}"
223 # FIXME: Replace --list with --extract
224 TAR_PART1
="${TAR} --extract --multi-volume"
225 if [ "$RSH_COMMAND" != "" ]; then
226 TAR_PART1
="${TAR_PART1} --rsh-command=$RSH_COMMAND"
228 if [ x
$BLOCKING != x
]; then
229 TAR_PART1
="${TAR_PART1} --blocking=${BLOCKING}"
232 # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
233 if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
234 TAR_PART1
="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
236 LOGFILE
="${LOGPATH}/restore-`now`"
240 if [ "${1}" != "now" ]; then
241 if [ "${1}x" != "x" ]; then
244 spec
="${BACKUP_HOUR}"
247 pausetime
="`date | awk -v spec=\"${spec}\" '
249 split(spec, time, ":")
253 diff = 3600 * (time[1] - now[1]) + 60 * (time[2] - now[2]);
259 echo "${SLEEP_MESSAGE}"
265 echo "$REMOTEBACKUPDIR/${1}.level-${2-$DUMP_LEVEL}"
268 # Prepare a temporary level logfile
269 # usage: make_level_log HOSTNAME
271 if [ "z${localhost}" != "z$1" ] ; then
272 $RSH "$1" mkdir $REMOTEBACKUPDIR > /dev
/null
2>&1
273 $RSH "$1" rm -f `level_log_name temp`
275 mkdir $REMOTEBACKUPDIR > /dev
/null
2>&1
276 rm -f `level_log_name temp`
280 # Rename temporary log
281 # usage: flush_level_log HOSTNAME FSNAME
283 message
10 "RENAME: `level_log_name temp` --> `level_log_name $2`"
284 if [ "z${localhost}" != "z$1" ] ; then
285 $RSH "$1" mv -f `level_log_name temp` "`level_log_name $2`"
287 mv -f `level_log_name temp` "`level_log_name $2`"
291 # Return the timestamp of the last backup.
292 # usage: get_dump_time LEVEL
294 ls -r ${LOGPATH}/log
-*-level-$1 \
296 | sed "s,.*log-\(.*\)-level-$1,\1,"
299 # Do actual backup on a host
300 # usage: backup_host HOSTNAME [TAR_ARGUMENTS]
302 message
10 "ARGS: $@"
305 if [ "z${localhost}" != "z$rhost" ] ; then
306 $RSH "$rhost" ${TAR_PART1} -f "${localhost}:${TAPE_FILE}" $@
308 # Using `sh -c exec' causes nested quoting and shell substitution
309 # to be handled here in the same way rsh handles it.
310 CMD
="exec ${TAR_PART1} -f \"${TAPE_FILE}\" $@"
311 message
10 "CMD: $CMD"
318 if [ ${1-$DUMP_LEVEL} -eq 0 ]; then
321 echo "Level ${1-$DUMP_LEVEL}"
326 print_level
`expr $DUMP_LEVEL - 1` | tr A
-Z a
-z
332 message
10 "REMOTE $rhost: $@"
333 if [ "x$rhost" != "x${localhost}" ] ; then
342 This program is part of GNU tar
343 Copyright 2004, Free Software Foundation
345 This program is free software; you can redistribute it and/or modify
346 it under the terms of the GNU General Public License as published by
347 the Free Software Foundation; either version 1, or (at your option)
350 This program is distributed in the hope that it will be useful,
351 but WITHOUT ANY WARRANTY; without even the implied warranty of
352 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
353 GNU General Public License for more details.
355 You should have received a copy of the GNU General Public License
356 along with this program; if not, write to the Free Software
357 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
This page took 0.050687 seconds and 4 git commands to generate.