rsync – incremental backup of files and folders

Just some rsync commands for next time I forget:

Put this in a bash script ie:

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
echo "Mounting backup drive:";
mount /backup
BACKUPDIR=`date  %A`;
nice rsync --progress --force --ignore-errors --delete-excluded 
     --delete --backup --backup-dir=/backup/$BACKUPDIR 
     -a /data/ /backup/current;
echo "All complete, unmounting backup drive";
umount /backup

This will mount a /backup drive (ie: a second hard drive or a network share) and make a copy of all files in /data/ across to /backup/current/ 

It will also make a folder for each day of the week eg: /backup/Monday/ /backup/Tuesday/ these folders will contain files that were changed or removed on that day. So if you delete something or overwrite something on /data/ you have a week to go back and find the old version. Pretty handy 🙂 


If you’re copying files to an external vfat usb hard drive then it will fail on files larger than 4GB (even with –ignore-errors). To fix this, you will just have to skip any large files:

rsync --progress --ignore-errors --max-size=4GB-1 -rt /data/ /usb_backup/

notice using the -rt options here instead of -a. -rt just mean preserve time stamps and recurse into child directories. -a tries to preserve permissions and all other funky stuff which do not work on a fat formatted drive.


Leave a Reply

Your email address will not be published.