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?
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):
Target dir after
rsync -Wav --progress t1/* t2
(note the link count 1):Target dir after
rsync -WavH --progress t1/* t3
(note the link count is 2 again):