Duplicity backup with hard-links

Hi there!

–°urrent version of Duplicity doesn’t preserve hard-links, so I’ve created a workaround to make it possible.

Why hard-links are important ? Any Linux distribution has many system hard-links. If you want to do a Full System Backup of Linux you must backup hard-links carefully, or you will meet nasty problems after restore. For example my Gentoo Linux has >3000 hard-links! Imagine what will happen if I ignore that.

I have written a small script which can backup/restore structure of hard-links.

You can download it: duplicity-hardlinks.py (modify python version in the first line if it fails to run. It requires Duplicity installation to work correctly.)

Usage:

$ duplicity-hardlinks.py [options] dump source_dir dump_file
$ duplicity-hardlinks.py restore dump_file target_dir

So, generally you should save hard-links structure into the dump_file, add dump_file into your backup, and use that file after restore.

Script is not stupid, it respects all Duplicity’s filter options.

Example:

$ duplicity-hardlinks.py --include /home --include /etc --exclude '**' dump / /hardlinks_dump.txt

This will save a dump of all hard-links from /home and /etc directories into the file /hardlinks_dump.txt.
Include /hardlinks_dump.txt in the list of files backup-ed by Duplicity. Use Duplicity to backup these files:

$ duplicity full --include /home --include /etc --include /hardlinks_dump.txt --exclude '**' / file:///mnt/backup/

Restore ordinal duplicity backup into some directory, for example /mnt/restore/. The file hardlinks_dump.txt should be there:

$ duplicity restore file:///mnt/backup/ /mnt/restore/

Finally, restore hard-links structure:

$ duplicity-hardlinks.py restore /mnt/restore/hardlinks_dump.txt /mnt/restore

Done!

Leave a Reply