Note that the rsync '-a' (archive mode) does not preserve hard links:
$ ls -li inc* 107256 -rw------- 3 tong tong 10 03-23 10:33 inc.txt 107544 lrwxrwxrwx 1 tong tong 7 03-23 12:13 inc2.txt -> inc.txt 107256 -rw------- 3 tong tong 10 03-23 10:33 inc31.txt 107256 -rw------- 3 tong tong 10 03-23 10:33 inc32.txt
rsync -vua . /tmp/lnk_tst cd /tmp/lnk_tst
$ ls -li inc* 217084 -rw------- 1 tong tong 10 03-23 10:33 inc.txt 217061 lrwxrwxrwx 1 tong tong 7 06-02 11:47 inc2.txt -> inc.txt 217085 -rw------- 1 tong tong 10 03-23 10:33 inc31.txt 217086 -rw------- 1 tong tong 10 03-23 10:33 inc32.txt
For the rsync command to preserve hard links, use an extra -H:
-H, --hard-links preserve hard links
rm -rf /tmp/lnk_tst rsync -vuaH . /tmp/lnk_tst cd /tmp/lnk_tst
$ ls -li inc* 217067 -rw------- 3 tong tong 10 03-23 10:33 inc.txt 216974 lrwxrwxrwx 1 tong tong 7 06-28 16:44 inc2.txt -> inc.txt 217067 -rw------- 3 tong tong 10 03-23 10:33 inc31.txt 217067 -rw------- 3 tong tong 10 03-23 10:33 inc32.txt
$ rsync -v rsync version 2.6.9 protocol version 29
To copy files while preserving hard links, use tar:
mkdir /tmp/lnk_tst2 tar -cSf - . | tar -xvSpf - -C /tmp/lnk_tst2 cd /tmp/lnk_tst2
$ ls -li inc* 217117 -rw------- 3 tong tong 10 03-23 10:33 inc.txt 217118 lrwxrwxrwx 1 tong tong 7 06-02 11:55 inc2.txt -> inc.txt 217117 -rw------- 3 tong tong 10 03-23 10:33 inc31.txt 217117 -rw------- 3 tong tong 10 03-23 10:33 inc32.txt
$ tar --version tar (GNU tar) 1.16
Well, actually 'cp -a' preserves hard links as well:
cp -a . /tmp/lnk_tst
$ ls -li /tmp/lnk_tst/inc* 217074 -rw------- 3 tong tong 10 03-23 10:33 /tmp/lnk_tst/inc.txt 217075 lrwxrwxrwx 1 tong tong 7 06-14 15:37 /tmp/lnk_tst/inc2.txt -> inc.txt 217074 -rw------- 3 tong tong 10 03-23 10:33 /tmp/lnk_tst/inc31.txt 217074 -rw------- 3 tong tong 10 03-23 10:33 /tmp/lnk_tst/inc32.txt
documented on: 2008-06-02