rsync mirroring and hardlink issues

Matt McCutchen hashproduct+rsync at gmail.com
Thu Apr 26 23:28:15 GMT 2007


On 4/26/07, Alexander 'Leo' Bergolth <leo at strike.wu-wien.ac.at> wrote:
> Recapitulating, once two files are hardlinked, rsync will break the
> hardlink only if one files _data_ changes, if only the metadata (mode,
> ownership, times) changes, the file will be updated in-place, leading to
> an inconsistent mirror.
>
> Unfortunately I couldn't find an option for rsync to apply even
> metadata-changes to a new copy of the file. (Another option could be
> checking the link-count of the inode and create a new copy of the file
> only if it is greater than one.)

C Sights and I have been discussing the possibility of adding
--no-tweak and --no-tweak-hlinked options that would do those two
things:

http://lists.samba.org/archive/rsync/2007-April/017613.html

> Is there any workaround for this issue?

Receive into a new, temporary destination specifying the original
destination as a --link-dest basis dir.  Files in the original
destination that match the source in both data and preserved
attributes will be hard-linked directly into the temporary
destination, while unmatched source files will be written anew.  Then
move the temporary destination over the real one.  In other words,
replace this:

rsync -a /path/to/src/ rep_a/

with this:

rsync -a --link-dest=../rep_a/ /path/to/src/ rep_a.new/
rm -rf rep_a
mv rep_a.new rep_a

(Note: when you adapt these commands for your setup, remember that if
the link-dest path is relative, rsync interprets it relative to the
destination directory.)

If you're concerned about concurrent access to the repository while
the mirroring is in progress, you can use a symlink to do an atomic
cutover:

# one-time setup (not safe for concurrent access)
mv rep_a rep_a.0
ln -s rep_a.0 rep_a

# sync
oldr=$(readlink rep_a)
newr=${oldr%.*}.$((1-${oldr##*.}))
rsync -a --link-dest=../$oldr/ src/ $newr/
ln -s $newr rep_a.tmp
mv -T rep_a.tmp rep_a
rm -r $oldr

This is a slight improvement of the technique used by the script
"support/atomic-rsync" in the rsync source tree.

Please feel free to reply if you need any more help.

Matt


More information about the rsync mailing list