]> git.sesse.net Git - backup.sh/commitdiff
Support native GNU tar incremental backups instead of using --newer.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 4 Oct 2014 22:21:49 +0000 (00:21 +0200)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 4 Oct 2014 22:21:49 +0000 (00:21 +0200)
backup.sh

index 1c188b2dc8441f575d692c2970b187521aee1281..e7c04c0f9b06183156dbf798fc8638278b80e7a4 100755 (executable)
--- 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