0

According to the rsync man page:

-a, --archive This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission). The only exception to the above equivalence is when --files-from is specified, in which case -r is not implied.

Note that -a does not preserve hardlinks, because finding multiply-linked files is expensive. You must separately specify -H.

It seems that we must use the -H option in order to copy also hard links (really?).

But according to my tests even if I don't use the -H option, rsync copied the hard link successfully from the local directory to another machine. This seems strange to me.

For example

$ ls -ltr
  -rw-r--r-- 1 root root 0 Jan 20 15:06 test.file.hard.link
  -rw-r--r-- 1 root root 0 Jan 20 15:06 test.file

$ rsync -Wav --progress /var/tmp/Backup_test_for_hard_link node1:/var/tmp

In node1 under /var/tmp, I see the hard link files:

-rw-r--r-- 1 root root 0 Jan 20 15:06 test.file.hard.link
-rw-r--r-- 1 root root 0 Jan 20 15:06 test.file

How can this be explained?

0

1 Answer 1

4

Those two are not hardlinks, as the link count would have be 2 if they where indeed links.

Also, if a file was existant with two hard links and you don't use the -H option, rsync would just create two copies of the file, while the additional (expensive) logic of the -H option would recognize that the two files are in reality only one and recreate them accordingly.

To illustrate it:

Source dir (note the link count 2):

total 0
-rw-r--r-- 2 root root 0 Jan 20 13:37 myfile
-rw-r--r-- 2 root root 0 Jan 20 13:37 myfile2

Target dir after rsync -Wav --progress t1/* t2 (note the link count 1):

total 0
-rw-r--r-- 1 root root 0 Jan 20 13:37 myfile
-rw-r--r-- 1 root root 0 Jan 20 13:37 myfile2

Target dir after rsync -WavH --progress t1/* t3 (note the link count is 2 again):

total 0
-rw-r--r-- 2 root root 0 Jan 20 13:37 myfile
-rw-r--r-- 2 root root 0 Jan 20 13:37 myfile2
3
  • According to you experience did the command (rsync -WavH –progress) Can copy the same files exactly from source to target ? or I need to add some other flags to rsync command? , my target to copy large directories withe many files from source machine to target machine
    – yael
    Commented Jan 20, 2011 at 13:47
  • I normally wouldn't use the -W and seldom the -H option (since I don't need it), but other than that rsync is rock solid and I use it daily to keep many TBs of data in sync, ranging from a few MBs of files to 14TB in ~2 million files. What other options you need depend on your usage (i.e. do you need ACLs and other extended attributes? Do you want to follow symlinks?). Tell us a bit about a bit more about your situation so we can help you better.
    – Sven
    Commented Jan 20, 2011 at 14:16
  • OK well, my target is to copy EMC storage partition - usage like 10G-20G , and I have system Red-hat cluster Linux , so need to copy all directories & files & links & symbolic links and so on ....
    – yael
    Commented Jan 20, 2011 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .