Is There a way to preserve symlink and also copy the actual contents using rsync

Matt McCutchen hashproduct+rsync at gmail.com
Fri Apr 27 01:06:16 GMT 2007


On 4/11/07, Namitha Rao <namithajr at gmail.com> wrote:
>  On the rsync Server we have rsync path set to say, path= /x/y
>
>  where 'y' is symlink to some other directory say 'z' on the same machine.
>
>  Now is there a way to sync 'y' on remote client preserving the symlink as
> it is and also  copy the actual contents from 'z' to say 'z' on the client
> machine.

If the module path in the server's configuration file refers to a
symlink, the client will see the symlink's target directory as the
root of the module; it will never see the symlink itself.  Thus, rsync
won't help you sync a symlink at a module root; of course, you could
write a script yourself that does so.

However, if symlinks to directories appear *inside* the module, you
can sync both the symlinks and the target directories.  Use two
passes, one to sync the symlinks themselves and one to follow them in
order to sync the targets.  If the target directories might not yet
exist on the destination, you need an intermediate step to create
them.  Here's an example of the script you would run on the client:

rsync -a server::module/ dest/
find dir -type l -exec bash -c \
    'mkdir -p "$(readlink --canonicalize-missing "$1")"' x {} \;
rsync -a --copy-dirlinks --keep-dirlinks server::module/ dest/

Matt


More information about the rsync mailing list