From a2863a4217f657c16498a5266ea3aee7df5a2a52 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 5 Oct 2014 00:21:49 +0200 Subject: [PATCH] Support native GNU tar incremental backups instead of using --newer. --- backup.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/backup.sh b/backup.sh index 1c188b2..e7c04c0 100755 --- a/backup.sh +++ b/backup.sh @@ -77,12 +77,26 @@ backup() echo -n `date` >&2 printf " $computer: $computer:$filesystem $backuplevel backup\n" >&2 + SNARFILE="${storagedir}/${computer}/${sfilesystem}/.incremental.snar" + incrementalsnar="/root/.backup/${sfilesystem}.snar" if [ "$backuplevel" = "daglig" ] then - lastd=`cat ../.date` - lastcmd="--newer='$lastd'" + # If incremental backup, we need to copy the incremental status to $computer. + # 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 + fi + lastcmd="--listed-incremental=$incrementalsnar --no-check-device" + else + echo `date`" $computer: Missing incremental.snar for $filesystem, doing date-based backup instead until next full backup" >&2 + incrementalsnar="" + lastd=`cat ../.date` + lastcmd="--newer='$lastd'" + fi else - lastcmd="" + lastcmd="--listed-incremental=$incrementalsnar" fi # expand the exclude-path for use with tar @@ -107,8 +121,14 @@ backup() if [ $? -eq 0 ] && [ -s $TARFILE ]; then # 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 + fi + # Move tar file in place mv $TARFILE $DATE.tgz + mv $SNARFILE.tmp $SNARFILE # Update timestamp echo $DATEs > ../.date && touch -t $DATE ../.date -- 2.39.2