Peter's Blog

Redefining the Impossible

Revised Backup Strategy


I was using rdiff-backup for incremental backups but I'm fed up with it raising meaningless assertion errors (ref rdiff-backup woes,Backup Strategy).

A quick google found this article with a nice simple incremental backup strategy. I've written this bash script to implement this strategy:

   1  #!/bin/bash
   2  # $1 = source dir
   3  # $2 = backup dir
   4  
   5  # Compare directory trees: if no changes then do not backup as this wastes a backup slot
   6  diff -r --brief $1 $2/Backup0 &> /tmp/DailyDiff
   7  
   8  if [ $? == 1 ]; then
   9      # Ripple old backups
  10      rm -rf $2/Backup9
  11      mv $2/Backup8 $2/Backup9
  12      mv $2/Backup7 $2/Backup8
  13      mv $2/Backup6 $2/Backup7
  14      mv $2/Backup5 $2/Backup6
  15      mv $2/Backup4 $2/Backup5
  16      mv $2/Backup3 $2/Backup4
  17      mv $2/Backup2 $2/Backup3
  18      mv $2/Backup1 $2/Backup2
  19      mv $2/Backup0 $2/Backup1
  20      # Copy current version to Backup 0, creating hard links where files have not changed.
  21      rsync -a --delete --link-dest=../Backup1 $1/  $2/Backup0/
  22  else
  23      # Report any diff errors.
  24      if [ $? == 2 ]; then
  25          echo Diff returned an error
  26          cat /tmp/DailyDiff
  27      fi
  28  fi
  29  
  30  rm /tmp/DailyDiff
Toggle Line Numbers

I created all the Backup? directories by hand to avoid errors, all empty to begin with.

Adding this to crontab:

15  23 * * 1-5 /home/pcw/DailyBackup /home/pcw/Projects /home/pcw/Backup/Projects

gives me incremental backups every weekday using just rsync, a tool that has not let me down so far.


Filed under: google rsync

Sorry but comments on this post are now closed.