Hi guys, I've been struggling with getting --link-dest working for a couple of hours now. I'm using rsync 2.6.9 (protocol 29), on Gentoo Linux. For some strange reason, whenever I recreate the source file, even though it's identical to the old source file --link-dest simply does not create the link. Point in case (starting from a blank directory tmp in my home directory): jkroon@pug ~/tmp $ mkdir a jkroon@pug ~/tmp $ echo foo > a/tmp jkroon@pug ~/tmp $ rsync -va --link-dest=../b.1 a/ b.0/ building file list ... done created directory b.0 ./ tmp sent 142 bytes received 48 bytes 380.00 bytes/sec total size is 4 speedup is 0.02 jkroon@pug ~/tmp $ rm a/tmp jkroon@pug ~/tmp $ echo foo > a/tmp jkroon@pug ~/tmp $ mv b.0 b.1 jkroon@pug ~/tmp $ rsync -va --link-dest=../b.1 a/ b.0/ building file list ... done created directory b.0 ./ tmp sent 143 bytes received 49 bytes 384.00 bytes/sec total size is 4 speedup is 0.02 jkroon@pug ~/tmp $ md5sum b.*/tmp d3b07384d113edec49eaa6238ad5ff00 b.0/tmp d3b07384d113edec49eaa6238ad5ff00 b.1/tmp jkroon@pug ~/tmp $ stat b.*/tmp File: `b.0/tmp' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 306h/774d Inode: 183267 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1001/ jkroon) Gid: ( 100/ users) Access: 2007-03-08 20:50:31.000000000 +0200 Modify: 2007-03-08 20:50:24.000000000 +0200 Change: 2007-03-08 20:50:31.000000000 +0200 File: `b.1/tmp' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 306h/774d Inode: 183111 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1001/ jkroon) Gid: ( 100/ users) Access: 2007-03-08 20:50:12.000000000 +0200 Modify: 2007-03-08 20:49:51.000000000 +0200 Change: 2007-03-08 20:50:12.000000000 +0200 Ok, so perhaps the -a which includes --times mucks things up, so add --no-times: jkroon@pug ~/tmp $ rm -rf * jkroon@pug ~/tmp $ mkdir a jkroon@pug ~/tmp $ echo foo > a/tmp jkroon@pug ~/tmp $ rsync -va --no-times --link-dest=../b.1 a/ b.0/ building file list ... done created directory b.0 ./ tmp sent 142 bytes received 48 bytes 380.00 bytes/sec total size is 4 speedup is 0.02 jkroon@pug ~/tmp $ rm a/tmp jkroon@pug ~/tmp $ echo foo > a/tmp jkroon@pug ~/tmp $ mv b.0 b.1 jkroon@pug ~/tmp $ rsync -va --no-times --link-dest=../b.1 a/ b.0/ building file list ... done created directory b.0 ./ tmp sent 143 bytes received 49 bytes 384.00 bytes/sec total size is 4 speedup is 0.02 jkroon@pug ~/tmp $ md5sum b.*/tmp d3b07384d113edec49eaa6238ad5ff00 b.0/tmp d3b07384d113edec49eaa6238ad5ff00 b.1/tmp jkroon@pug ~/tmp $ stat b.*/tmp File: `b.0/tmp' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 306h/774d Inode: 183267 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1001/ jkroon) Gid: ( 100/ users) Access: 2007-03-08 20:53:03.000000000 +0200 Modify: 2007-03-08 20:53:03.000000000 +0200 Change: 2007-03-08 20:53:03.000000000 +0200 File: `b.1/tmp' Size: 4 Blocks: 8 IO Block: 4096 regular file Device: 306h/774d Inode: 183111 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1001/ jkroon) Gid: ( 100/ users) Access: 2007-03-08 20:52:51.000000000 +0200 Modify: 2007-03-08 20:52:51.000000000 +0200 Change: 2007-03-08 20:52:51.000000000 +0200 jkroon@pug ~/tmp $ Still no hard link ... If someone could just explain to me why this behaviour happens, and if it can be avoided, it would be much appreciated. Jaco
On Thu, Mar 08, 2007 at 08:56:54PM +0200, Jaco Kroon wrote:> For some strange reason, whenever I recreate the source file, even > though it's identical to the old source file --link-dest simply does not > create the link.The file isn't identical enough to hard-link unless every preserved detail is identical. So, when using -a (which implies --times, as you noted), the mtime has to be the same for the files to get hard-linked together. However, adding --no-times is not enough because rsync still has to identify the file as unchanged, and that requires the file to have the same size and mtime UNLESS you use the -c (--checksum) option. Using -c, rsync will read each file, comparing the checksum, and then hard-link any matches (as long as you aren't trying to set a conflicting attribute on the destination file, such as mtime, permissions, group, etc.). Helpful hint: Use -i (--itemize-changes) to see why rsync considers a file to be different: if it mentions the file's name in a link-dest copy, the file is not being hard-linked. This sequence of commands should work for you: mkdir a echo foo > a/tmp rsync -avi a/ b.1/ touch a/tmp rsync -avic --no-t --link-dest=../b.1 a/ b.0/ ..wayne..