2009-02-05

incsync – incremental backups with rsync on Unix

Time Machine was always a bit troublesome for me on Mac OS X, so I did some research about how to do incremental backups with open source software. The result is the script presented in this post.

Rsync is really cool for backups (if you need bi-directional file synchronization, take a look at Unison): If you specify a source and a target directory, rsync makes sure that files are copied from target to source or removed from target until both directories have the same content. Thus, whatever the state of source and target, after invoking rsync, the target is an exact copy of the source. Rsync has command line options that allow one to only back up changes relative to a “previous” directory:

  • Usage: incsync.sh [timestamp]
    • No arguments: Perform a new backup with the current time as a timestamp.
    • One argument – a timestamp: Continue a previous backup.
  • What it does: Each time, it is invoked, only what has changed (since the last invocation) is backed up, in a new directory with a time stamp.
  • How it works: incsync uses the open source tool rsync for incremental backups. rsync uses Unix hard links (references to files) to do so: Before creating a new backup, one makes a complete copy of the last backup, but the copy does not contain files, only hard links to files. Then one brings the copy up to date with the source directory. Afterwards, the copy looks like a complete backup, but consumes relatively little space on disk. The kicker is that you could now delete the previous backup and the newly created directory would still contain a complete backup. The reason lies in Unix’s handling of hard links: it only deletes a file after there are no more references to it.
  • Inspiration: This script has been inspired by the article “Time Machine for every Unix out there”.
  • Download: on GitHub at incsync.

5 comments:

monto5 said...

Check out www.rsnapshot.org - basically the same idea, but also offers rotating backups with different frequency. I used it before Time Machine came out and worked well for me.

- Stefan

Axel Rauschmayer said...

Thanks for the tip. I have checked it out and it has some really cool features. But I wanted a simpler solution.

Flo said...

What was the trouble you had with Time Machine?


I haven't had any problems for years now.

Axel Rauschmayer said...

The first time I had trouble with TM was when I moved my home directory to a non-standard path. Then it worked fine for years. Then I switched from a 32bit system to a 64bit system and it became dog slow. I tried all of the suggested fixes I could find on the web, none of them worked. Now I’ll use incsync for a while and will give TM another shot after Lion is out.

yannis said...

Hello and thank you for your script!
I have a nas box whith an external usb disk where I take the backups.
Previously I was doinng full sync with rsync by giving (rsync -av /source /destination).
Now I tried your script because I needed versioning of files.
It created a folder _current and second folder _20121205_05-03 where it looks like it keeps a full sync of source each time I run the backup.
The problem is that under /destination I already have a full tree of my folders and files.Should I delete them and leave just _20121205_05-03 and _current? I can see that now the backup consumes more space than before, is this normal? What about restoring? which command I should use to make a full restore of all files?


thank you

Web Analytics