I have a big hierarchy of files. Sometimes hardlinks are created within that hierarchy and I know exactly in what folders that happened. I want to replicate the changes with rsync efficiently, by only syncing changed folders.
Speaking in bash, this is my scenario:
#create initial structure and sync it mkdir src src/v1 dst dst/v1 echo some text > src/v1/some-file rsync -avi src/ dst/ #create a new version that links to previous version and sync only that mkdir src/v2 ln src/v1/some-file src/v2/same-file rsync -avi --link-dest=../v1/ src/v2/ dst/v2/ #full sync alternative that works #rsync -avi -H src/ dst/ #list files to see the reference count ls -l src/v2/same-file dst/v2/same-file
The initial structure is a "v1" folder containing a file. Later a "v2" folder is added. It contains a file that is actually a hardlink to the file in "v1". I want to sync only "v2" but "v1" was already synced and the destination has the file so I want a hardlink (or at least avoid transferring the file).
Running the script outputs this at the end:
-rw-r--r-- 1 root root 10 Mar 17 01:53 dst/v2/same-file -rw-r--r-- 2 root root 10 Mar 17 01:53 src/v2/same-file
The reference count on "dst" is 1 so a hardlink was not created. Looking at rsync logs we can also see that the file contents were also transfered.
Replacing the last rsync with the commented version works. This is because a different mechanism is used (determining duplicated within the transfered file set). I can not use this version because I have hundreds of thousands of files.
I can't tell what I'm missing here. This seems to be the basic usage of --link-dest.
I'm using rsync 3.0.3 on Oracle Linux 6.3. My actual setup is on different machines with push over rsync protocol, but I get the same behaviour.