#!/bin/sh
DUMP_LEVEL=1
PATH="/usr/ucb:${PATH}"
export PATH
if [ ! -w / ]; then
echo "The backup must be run as root or else some files will fail to be dumped."
exit 1
fi
. ./backup-specs
if [ "z${1}" != "znow" ]; then
if [ "${1}x" != "x" ]; then
spec="${1}"
else
spec="${BACKUP_HOUR}"
fi
pausetime="`date | awk '
{
hr = substr($4, 1, 2);
mn = substr($4, 4, 2);
if((hr + 0) < (spec + 0))
print 3600 * (spec - hr) - 60 * mn;
else
print 3600 * (spec + (24 - hr)) - 60 * mn;
}' spec=\"${spec}\"`"
clear
echo "${SLEEP_MESSAGE}"
sleep "${pausetime}"
fi
startdate="`date`"
here="`pwd`"
LOGFILE="log/log-`date | sed -ne '
s/[^ ]* *\([^ ]*\) *\([^ ]*\).* \([^ ]*\)$/\3-\1-\2/
/-[0-9]$/s/\([0-9]\)$/0\1/
/Jan/{s/Jan/01/p;q;}
/Feb/{s/Feb/02/p;q;}
/Mar/{s/Mar/03/p;q;}
/Apr/{s/Apr/04/p;q;}
/May/{s/May/05/p;q;}
/Jun/{s/Jun/06/p;q;}
/Jul/{s/Jul/07/p;q;}
/Aug/{s/Aug/08/p;q;}
/Sep/{s/Sep/09/p;q;}
/Oct/{s/Oct/10/p;q;}
/Nov/{s/Nov/11/p;q;}
/Dec/{s/Dec/12/p;q;}'`-level-${DUMP_LEVEL}"
localhost="`hostname | sed -e 's/\..*//'`"
TAR_PART1="${TAR} -c --multi-volume --one-file-system --blocking=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
TAR_PART1="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
fi
if [ -f "${LOGFILE}" ] ; then
echo "Log file ${LOGFILE} already exists." 1>&2
exit 1
else
touch "${LOGFILE}"
fi
(
mt -f "${TAPE_FILE}" rewind
rm -f "${VOLNO_FILE}"
set - ${BACKUP_DIRS}
while [ $ date="`date`"
remotehost="`echo \"${1}\" | sed -e 's/:.*$//'`"
fs="`echo \"${1}\" | sed -e 's/^.*://'`"
fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
TAR_PART3="--label='level 1 backup of ${fs} on ${remotehost} at ${date}' -C ${fs} ."
echo "Backing up ${1} at ${date}"
echo "Last full dump on this filesystem:"
if [ "z${remotehost}" != "z${localhost}" ] ; then
rsh "${remotehost}" "ls -l /etc/tar-backup/${fsname}.level-0; \
cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1"
else
ls -l "/etc/tar-backup/${fsname}.level-0"
cp "/etc/tar-backup/${fsname}.level-0" /etc/tar-backup/temp.level-1
fi
if [ "z${remotehost}" != "z${localhost}" ] ; then
rsh "${remotehost}" ${TAR_PART1} -f "${localhost}:${TAPE_FILE}" ${TAR_PART2} ${TAR_PART3}
else
sh -c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3}"
fi
if [ $? -ne 0 ] ; then
echo "Backup of ${1} failed."
else
if [ "z${localhost}" != "z${remotehost}" ] ; then
rsh "${remotehost}" mv -f /etc/tar-backup/temp.level-1 "/etc/tar-backup/${fsname}.level-1"
else
mv -f /etc/tar-backup/temp.level-1 "/etc/tar-backup/${fsname}.level-1"
fi
fi
${TAPE_STATUS}
sleep 60
shift
done
if [ "x${BACKUP_FILES}" != "x" ] ; then
date="`date`"
TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
TAR_PART3="--label='Incremental backup of miscellaneous files at ${date}'"
echo "Backing up miscellaneous files at ${date}"
echo "Last full dump of these files:"
ls -l /etc/tar-backup/misc.level-0
rm -f /etc/tar-backup/temp.level-1
cp /etc/tar-backup/misc.level-0 /etc/tar-backup/temp.level-1
sh -c "exec ${TAR_PART1} -f \"${TAPE_FILE}\" ${TAR_PART2} ${TAR_PART3} ${BACKUP_FILES}"
if [ $? -ne 0 ] ; then
echo "Backup of miscellaneous files failed." 1>&2
else
mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/misc.level-1
fi
${TAPE_STATUS}
else
echo "No miscellaneous files specified"
fi
mt -f "${TAPE_FILE}" rewind
mt -f "${TAPE_FILE}" offl
) 2>&1 | tee -a "${LOGFILE}"
echo "Sending the dump log to ${ADMINISTRATOR}"
mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"