1

rsync has a --hard-links option:

   -H, --hard-links
          This tells rsync to look for hard-linked files in the source and
          link together the corresponding files on the destination.  With-
          out  this option, hard-linked files in the source are treated as
          though they were separate files.

However, when I tried to copy hard linked files from one volumn to another, I found the hard-links are gone at destination -- each of the hard-linked file have a link count of 1 (instead of >=2).

I copied hard-linked files together in a single rsync command.

Is there anything that I'm missing or rsync can't preserve hard links at destination?

  • Can you edit your post to include a simple, reproducible example? You say you used an rsync command, and you ask if there's anything you're missing, but unless you show us what you used, how can we know if there's anything missing? – Jim L. Aug 3 at 21:40
  • 1
    What is destination FS and does it support hard links? – xenoid Aug 3 at 21:48
1

It works here. As @xenoid hinted in their comment above, you never will be able to preserve hard links if the destination filesystem is, say, FAT32, or some other FS that doesn't support hard links.

$ file test /tmp/test
test:      directory
/tmp/test: cannot open `/tmp/test' (No such file or directory)
$ rsync -Ha test /tmp/
$ ls -li test /tmp/test
/tmp/test:
total 3
110995 -rw-------  2 james  james  0 Aug  3 14:40 file1
110996 -rw-------  2 james  james  0 Aug  3 14:40 file2
110994 -rw-------  1 james  james  0 Aug  3 14:40 file3
110995 -rw-------  2 james  james  0 Aug  3 14:40 hard-link-to-file1
110996 -rw-------  2 james  james  0 Aug  3 14:40 hard-link-to-file2

test:
total 3
106655 -rw-------  2 james  james  0 Aug  3 14:40 file1
106656 -rw-------  2 james  james  0 Aug  3 14:40 file2
106657 -rw-------  1 james  james  0 Aug  3 14:40 file3
106655 -rw-------  2 james  james  0 Aug  3 14:40 hard-link-to-file1
106656 -rw-------  2 james  james  0 Aug  3 14:40 hard-link-to-file2
  • Thanks for the confirmation. My source filesystem is ext4 and destination filesystem is ext2. I think it should be OK... Well, after quiet a wild-chase, I have pin-point where the problem is -- see superuser.com/questions/1467451. – xpt Aug 4 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.