0

So I have been searching for this up and down, but must be doing something fundamentally wrong. What I want to do:

I have configured my NAS to make snapshots of my home folder, file system is btrfs. That works as it should and is utilizing hard links.

I want to copy off the whole snapshots directory for backup on an ext4 usb disk, using rsync -aH to preserve the hard links. But hard links are not preserved after rsync completes - I am down to a minimum example where I rsync a file of 2 different snapshots (verified to have identical Inodes) on the btrfs volume - just to another directory - which also creates 2 distinct files. Am I missing an rsync option here to make this work? Or is rsync simply incapable to do this? Wrong tool for the job?

quaylar
  • 2,617
  • 1
  • 17
  • 31

1 Answers1

2

The files have the same inode number, but btrfs presents them in different (virtual) file systems. Check the "stat" output and you should see that the device is different. rsync correctly determines that these are not true hard links.

If you think about it, this makes sense because if you edit a file its inode number does not change (usually), but before and after snapshots will show different content.

The correct way to achieve what you want is to do a normal rsync from inside the first snapshot. Then do another rsync from the second snapshot to a fresh destination directory, but give the --link-dest=<first-dest-dir> option. This will create a new snapshot with hardlinks into the old snapshot, wherever the files are identical.

E.g.

rsync -aH /.snapshot1/ dest1/
rsync -aH --link-dest=dest1/ /.snapshot2/ dest2/
rsync -aH --link-dest=dest2/ /.snapshot3/ dest3/
rsync -aH --link-dest=dest3/ /.snapshot4/ dest4/
rsync -aH --link-dest=dest4/ /.snapshot5/ dest5/
rsync -aH --link-dest=dest5/ /.snapshot6/ dest6/

You can think of it as doing a cp --link dest1 dest2 before rsync (which would have a similar effect, as long as you don't use --inplace).

ams
  • 24,923
  • 4
  • 54
  • 75