I wanted to share a solution I came up with awhile back that uses Dropbox, a few bash scripts, and some ingenuity to make a free, daily, encrypted, incremental off-site backup to keep track of important files that are changed daily.
The idea: For those not yet acquainted, Dropbox is a free service which allows you to sync 2.25 gigs of information (which can be increased by referrals or money) in a specific folder with their offsite server. You are able to access this info from any computer and from many Mobile devices (including iPhone).
Why bother? It’s important to back up data because eventually all drives will die. Incremental backups are important because it allows you to track changes from day to day. The solution I have here isn’t perfect, but it allows for a few folders to be saved for 30 days before they are overwritten. The benefit of this is that if a huge error is caught 5 days after it was made, then you can revert to the file that was saved 6 days ago.
Here’s the code that does the job. I named this file backup.sh and had it run every day at 3am, when nobody is likely to be editing or messing with files. The result of the code is a disk image (.dmg) that will be password protected, and will have the name of backup[1-31].dmg (based on the current date). Downloadable file after the code:
dropboxdir="~/Dropbox/backups/" #change this as needed, make sure it exists
backupfolders="/path/to/folder /path/to/second/folder /and/so/on"
#seems dumb and redundant, but it is sorta needed
mkdir /tmp/Backups; cd /tmp/Backups
tar -czf backup$datestring.tgz $backupfolders
tar -zxf backup$datestring.tgz
# hdiutil won't overwrite files, so if it exists, delete it.
if [ -f $dropboxdir/backup$datestring.dmg ]
# create the .dmg file
hdiutil create -srcfolder '/tmp/Backups' -encryption -passphrase $password -fs HFS+ -volname Backup$thismonth.$datestring.$thisyear $dropboxdir/backup$datestring
# clean up our mess so tomorrow we can start fresh
rm -rf /tmp/Backups
Here’s the file you can download: backup.sh
Just put that file somewhere, make the necessary edits at the top of the file: set a password, your dropbox backup folder location, and the folders you’d like to backup. Then make sure the bash script can run (chmod +x backup.sh), and then set crontab to make it run once a day (Google crontab).
To use it or see if it’s working, navigate to the Dropbox folder that you set in the script, and double click on the .dmg disk image file, entering your password when asked. Copy the file(s) that you need off the newly mounted disk, and then eject it. Simple pie.
Update #1: Please note that in order to use folders with spaces in them, such as “Business Contacts” you would enter in
(Note the backslash before the space.) Thanks to @MagerValp in tuaw’s comments for pointing that out.
Questions in the comments.
Disclaimer #1: I’m not responsible if this causes problems. Sorry
Disclaimer #2: If you click on the link to Dropbox and signup, you and I both get an extra 250mb of storage. Not bad.