rsync script for snapshot backups

Dennis Steinkamp dennis at
Sun Jun 19 12:22:10 UTC 2016

Hey guys,

i tried to create a simple rsync script that should create daily backups 
from a ZFS storage and put them into a timestamp folder.
After creating the initial full backup, the following backups should 
only contain "new data" and the rest will be referenced via hardlinks 

This was at least a simple enough scenario to achieve it with my 
pathetic scripting skills. This is what i came up with:


# rsync copy script for rsync pull from FreeNAS to BackupNAS for Buero 

# Set variables
EXPIRED=`date +"%d-%m-%Y" -d "14 days ago"`

# Copy previous timefile to timeold.txt if it exists
if [ -f "/volume1/rsync/Buero/timenow.txt" ]
     yes | cp /volume1/rsync/Buero/timenow.txt 
# Create current timefile
     echo `date +"%d-%m-%Y-%H%M"` > /volume1/rsync/Buero/timenow.txt
# rsync command
if [ -f "/volume1/rsync/Buero/timeold.txt" ]
     rsync -aqzh \
     --delete --stats --exclude-from=/volume1/rsync/Buero/exclude.txt \
+"%d-%m-%Y-%H%M"`.log \
/volume1/rsync/Buero/timeold.txt` \
Test at`date +"%d-%m-%Y-%H%M"`
     rsync -aqzh \
     --delete --stats --exclude-from=/volume1/rsync/Buero/exclude.txt \
+"%d-%m-%Y-%H%M"`.log \
Test at`date +"%d-%m-%Y-%H%M"`

# Delete expired snapshots (2 weeks old)
if [ -d /volume1/Backup_Buero/$EXPIRED-* ]
rm -Rf /volume1/Backup_Buero/$EXPIRED-*

Well, it works but there is a huge flaw with his approach and i am not 
able to solve it on my own unfortunately.
As long as the backups are finishing properly, everything is fine but as 
soon as one backup job couldn`t be finished for some reason, (like it 
will be aborted accidently or a power cut occurs)
the whole backup chain is messed up and usually the script creates a new 
full backup which fills up my backup storage.

What i would like to achieve is, to improve the script so that a backup 
run that wasn`t finished properly will be resumed, next time the script 
Only if that was successful should the next incremental backup be 
created so that the files that didn`t changed from the previous backup 
can be hardlinked properly.

I did a little bit of research and i am not sure if i am on the right 
track here but apparently this can be done with return codes, but i 
honestly don`t know how to do this.
Thank you in advance for your help and sorry if this question may seem 
foolish to most of you people.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the rsync mailing list