rm $LOCKFILE
exit 1
}
+diemsg() {
+ echo `date`": $computer: $@"
+ die
+}
# Trap C-c and kill
trap die SIGINT SIGTERM
# If it does not exist, whine a bit and then run date-based instead.
if [ -s "$SNARFILE" ]; then
if ! scp $SNARFILE root@$computer:$incrementalsnar; then
- echo `date`" $computer: Could not copy .incremental.snar to $computer"
- die
+ diemsg "Could not copy .incremental.snar to $computer"
fi
lastcmd="--listed-incremental=$incrementalsnar --no-check-device"
else
# File is >0 in size and neither cat or tar tzvf failed; we assume it worked.
if ! scp root@$computer:$incrementalsnar $SNARFILE.tmp; then
- echo `date`" $computer: Could not copy .incremental.snar from $computer"
- die
+ diemsg "Could not copy .incremental.snar from $computer"
fi
# Move tar file in place
else
# Something wrong happened.
rm $TARFILE
- echo `date`" $computer: $TARFILE empty. $backuplevel backup of $computer:$filesystem failed and deleted"
- die
+ diemsg "tar failed or $TARFILE empty. $backuplevel backup of $computer:$filesystem failed and deleted"
fi
}
# Check that the target filesystem is mounted (actually check that it's not
# the root filesystem)
if [ ! -d "$storagedir/$computer" ]; then
- echo `date`" $computer: Target filesystem ($storagedir/$computer) does not exist. Aborting"
- die
+ diemsg "Target filesystem ($storagedir/$computer) does not exist. Aborting"
fi
rootfilesystem=`df -P /`
targetfilesystem=`df -P "$storagedir/$computer"`
if [ "$rootfilesystem" == "$targetfilesystem" ]; then
- echo `date`" $computer: Target filesystem ($storagedir/$computer) was mounted on /. Aborting"
- die
+ diemsg "Target filesystem ($storagedir/$computer) was mounted on /. Aborting"
fi
echo `date`" $computer: Backing up $computer" >&2
# Try to SSH to the computer without entering a password.
if ! `ssh -n -o NumberOfPasswordPrompts=0 root@$computer /bin/true`; then
- echo `date`" $computer: Could not use passwordless SSH."
- die
+ diemsg "Could not use passwordless SSH."
fi
# Check if pigz is available
# Clean up our dir at this client
if ! ssh root@$computer "rm -r /root/.backup ; mkdir -m 700 /root/.backup"; then
- echo `date`" $computer: Could not create backup staging area at $computer:/root/.backup"
- die
+ diemsg "Could not create backup staging area at $computer:/root/.backup"
fi
# Try to copy $exclude to $computer
if ! scp $exclude root@$computer:/root/.backup/exclude > /dev/null; then
- echo `date`" $computer: Could not copy exclude.txt to $computer"
- die
+ diemsg "Could not copy exclude.txt to $computer"
fi
# Try to copy preeexec and postexec if they exist
if [ -f $confdir/preexec.$computer ]; then
if ! scp $confdir/preexec.$computer root@$computer:/root/.backup/preexec >&2; then
- echo `date`" $computer: Could not copy preexec.$computer to $computer:/root/.backup/preexec"
- die
+ diemsg "Could not copy preexec.$computer to $computer:/root/.backup/preexec"
fi
fi
if [ -f $confdir/postexec.$computer ]; then
if ! scp $confdir/postexec.$computer root@$computer:/root/.backup/postexec >&2; then
- echo `date`" $computer: Could not copy postexec.$computer to $computer:/root/.backup/postexec"
- die
+ diemsg "Could not copy postexec.$computer to $computer:/root/.backup/postexec"
fi
fi
# Try to run preexec if it exists
if ! ssh root@$computer "[ ! -f /root/.backup/preexec ] || /bin/bash -x /root/.backup/preexec" >&2; then
- echo `date`" $computer: Could not run $computer:/root/.backup/preexec"
- die
+ diemsg "Could not run $computer:/root/.backup/preexec"
fi
for filesystem in $filesystems
fi
# We want to be here
- cd $storagedir/$computer/$sfilesystem/$backuplevel || die
+ cd $storagedir/$computer/$sfilesystem/$backuplevelmsg || die "$storagedir/$computer/$sfilesystem/$backuplevel does not exist"
# Perform the actual backup
backup
# Try to run postexec if it exist
if ! ssh root@$computer "[ ! -f /root/.backup/postexec ] || /bin/bash -x /root/.backup/postexec" >&2; then
- echo `date`" $computer: Could not run $computer:/root/.backup/postexec"
- die
+ diemsg "Could not run $computer:/root/.backup/postexec"
fi
# Remove lockfile