You know, Apple’s OS X has a number of cool features, and they also create amazing hardware. One of the useful features is Time Machine, a user-friendly and easy way to backup and restore your whole system, nicely integrated into the operating system. And what’s more compelling is that it doesn’t create the whole copy of all the data for each backup, but rather copies only changed files while keeping hard links to the old version for non-changed files. It’s an effective solution for incremental backups.
However, if you’re using Linux, how to setup a similar system?
Turns out, this great tool rsync supports such a mode. It has this advantage of coming with almost every Linux distribution and the OS X. Here’s my bash script that maintains up to 5 backups on an external drive with rsync:
You need to change the destination for the backups (the dst variable). All that follows is done with the superuser’s privileges, which are required for reading system files. First, the script removes the oldest backups. While doing the backup, all the output is teed to the log file as well. The key rsync’s option is --link-dest=${dst}${latest}. At the end, the latest backup is symlinked to latest file.