rsync encrypted backup

Install truecrypt and setup an external usb hard drive with an encrypted partition. Remember the password 🙂 Once the drive is setup and plugged into your server, run the following bash script to create an incremental backup of a folder onto the drive.

Incremental will create a folder for each day of the week, any files that were changed or deleted on that day will be placed into this folder, so you can go back a week in history and recover any mistakes. 

Put this in a bash script ie:

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

echo "Mounting encrypting backup drive:";

# this mounts our external usb hard drive with truecrypt using our password
# i know - not 100% secure - mount it manually if your worried
# the shortname=mixed is so the VFAT partition works nicely on the external drive
truecrypt /dev/sdd1 --protect-hidden=no --fs-options="shortname=mixed"
-k "" -p YourPasswordHere /backup/;
# the folder (todays day) where changed/deleted files will be placed. BACKUPDIR=`date %A`;

echo "Backing up the /data/ directory to the /backup/ directory";
echo "Ignoring /data/somefolder/ and /data/someotherfolder/";

nice rsync --progress --force --ignore-errors --delete-excluded
--delete --backup --max-size=2G --backup-dir=/backup/$BACKUPDIR
--exclude=somefolder --exclude=someotherfolder
--no-p -rtuv /data/ /backup/current;
echo "All complete, unmounting encrypted backup drive";
truecrypt -d;


the above is for a truecrypt’d vfat partition – the rsync options are a little different if you have a better filesystem to play with (eg: preserve permissions & larger than 4gb files)

Leave a Reply

Your email address will not be published. Required fields are marked *