1

I'd love rsync to copy symlinks to dirs specified on the cmdline as dirs but leave all symlinks in the copied tree as is - like find -H, but the only way is a nasty hack of

rsync -aR --rsync-path='cd /sender/parent/dir/of/tree; rsync' symlinkeddir/ target

the issue there is that this becomes an exception in my rsync backup scripts just for this one set of paths so I can't use the same command (or more so, just ONE rsync) to do what I want. find -H -like behaviour would do it very nicely. :/

1 Answer 1

0

If somelink is a symbolic link to a directory somedir, then

rsync -a somelink/. target/

copies the content of somedir into target.

If you only have relative symlinks that stay inside the source, then you can use

rsync -a --copy-unsafe-links somelink target/

If you want to preserve the symlink path inside the target, I don't think what you want to do can be done with rsync alone. You can do it with rsync plus a bit of shell code: loop over the sources, and specify the target subdirectory explicitly.

mkdir -p target/somelink
rsync -a somelink/. target/somelink
2
  • yes, quite - problem is i want the literal portion of 'somelink' copied too - mostly because ive got somelink1 2 and 3, so i need dirs somelink1 2 and 3 created in the target, thus the -R in my eg. (beware! rsync -a somelink*/ target will merge somelink*'s contents into one dir with whatever's copied first taking precedence!)
    – math
    Sep 3, 2014 at 5:35
  • @math Unless you can use the absolute/relative symlink trick (second proposal in my answer), I don't think you can do it with rsync alone. There are many possible workarounds, but not seamless ones. A loop over the sources where you specify the target subdirectory each time seems easiest to me. Sep 3, 2014 at 6:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .