Friday, 17 August 2012

rsync incremental backups

A directory holds incremental backups (I've mounted a remote directory locally to ease the command but ssh could also be used), in numerical order.  If the last backup number was 5, the next will be 6.  rsync is used to create the incremental backup:

$ crontab -e

Add this for nightly backup:


0 0 * * * i=`ls /mnt/Apollo/archive | tail -n 1`; i=${i%/}; j=$((i+1)); rsync -azm --delete --progress --include='*/' --include='*.tex *.dat *.DAT' --exclude='*' --link-dest=/mnt/Apollo/archive/$i/ /home/me/ /mnt/Apollo/archive/$j

which breaks down as,

0 0 * * *
  : at 0 minutes, 0 hours every day every month every year execute:

i=`ls /mnt/Apollo/archive | tail -n 1`
  : get listing of archive directory in increasing number order (I hope!)

 i=${i%/}
  : Remove the trailing slash from the directory name

j=$((i+1)) 
 : Add one to it and assign to j.

rsync:

-a
(rchive) : preserve file parameters (owner, read/write/execute etc)
-z
(ip) : compress during transmit.
-m
 : do not create empty directories on the backup.
--delete
  : if a file is deleted on the source, remove it on the backup (I hope from the incremental!)

--include='*/' 
 : required to get this to work!
--include='*.tex *.dat *.DAT'
   : files to archive.
--exclude='*' 
  : don't archive anything else.
--link-dest=/mnt/Apollo/archive/$i
    : the reference archive directory used to generate deltas from.
/home/me/
   : start point for information to be backed up.
/mnt/Apollo/archive/$j 
  :  target for incremental data.



No comments:

Post a Comment