Do not use hard links for incremental backups

I’ve read in many places that a good simple incremental backup approach is to use rsync to sync your files to a backup destination and then hard link the backup to a copy via cp -al so that you have historical snapshots.

It works as follows:

rm -rf mirror.2
mv mirror.1 mirror.2
cp -al mirror mirror.1
rsync -a --delete source/ mirror/

Or apparently you can use rsync’s --link-dest option to do the hard linking (instead of cp -al).

This works just fine if you assume that the contents of each file is always correct. You will have “mirrors” of your source, with any files that were deleted in ‘mirror’ preserved in ‘mirror.1’ and any files that were deleted in ‘mirror.1’ preserved in ‘mirror.2’.

The problem

The problem is what happens when you (or an application) accidentally screw up the contents of a file. In this case, all of the hard-linked files will also change, because a hard link is just a pointer to some stored data, it doesn’t duplicate the data. This means that ‘mirror’, ‘mirror.1’ and ‘mirror.2’ will all have the same screwed up file.

This means hard linking is not a good solution for incremental backups.

Last modified: 30/11/2015 Tags: ,

Related Pages

Other pages possibly of interest:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top