Easy backup to USB drive in Linux
After a super-fun episode in which Ubuntu’s Simple Backup didn’t restore successfully after a hard drive failure, I went searching for a better solution to back up my /home directory to a (1.5 TB w00t!) external USB hard drive.
I found this lovely solution using rsync. It’s worth reading the whole page if you don’t know how hard links work in *nix, but basically the solution has four backup slots, which get moved by one in the queue every backup, and if the files haven’t changed across all four, there’s only one copy of the files, because everything is done with ln. And the most recent backup is always the full backup, which is ridiculously cool.
Here’s the whole thing:
rm -rf backup.3
mv backup.2 backup.3
mv backup.1 backup.2
cp -al backup.0 backup.1
rsync -a --delete source_directory/ backup.0/
Careful with the trailing slashes: include them where included, omit them where omitted. The “backup.2″ would really look like “/media/disk/backup/backup.2″ or whatever, and “source_directory/” would really look like “/home/you/”, but you can fill those in.
I put those five lines in a script called backup.sh, chmodded it +x, and put the following line in my crontab:
00 04 * * * /home/joshua/bin/backup.sh
And — yeah — that’s it. Awesome. Now all I need is a second, larger hard drive to backup the first backup drive. (“Big fleas … little fleas … ad infinitum“)
[ Replace this ad for $1/month ]
|
One Response to “Easy backup to USB drive in Linux”
Leave a Reply, but read first
- Feel free to leave replies even to very old posts.
- Is your comment not specifically about this post? Great! Go here.
- Flame, swear, rant, shout — just don't spam! You won't increase your PageRank, even temporarily (the URLs are tagged 'nofollow'), and I'll delete it anyway. Save us both time.



















February 12th, 2010 at 16h06
It looks like this works best in root’s crontab.