Rsync: how to relocate absolute symlinks

rsyncsymlink

I've pored over the rsync manpage as well as on several related questions here on serverfault. I've played with -R and -L and -l options, but no luck.

Here is the question: when sending a dir from local to remote, is there an option (or option combo) that relocates symlinks relative to the local dir so that they become relative to the destination dir on the remote machine?

Here is a minimal example of what I want to send:

local dir: /home/bob/foo

/home/bob/foo/a --> /home/bob/foo/bar
/home/bob/foo/bar

and here is how I would like it to materialize in the

remote dir: /u/apps/foo

/u/apps/foo/a --> /u/apps/foo/bar
/u/apps/foo/bar

For example, rsync -az /home/bob/foo/ remote:/u/apps/foo/ doesn't quite do it; we end up with:

/u/apps/foo/a --> /home/bob/foo/bar
/u/apps/foo/bar

Whether /home/bob/foo/bar exists or not on the remote machine is irrelevant; in either case, the result is definitely not what I need.

Best Answer

If the links are to absolute paths, no there's no way around it. You can get around it by making the symlinks relative:

/home/bob/foo/a --> ./bar
/home/bob/foo/bar

but that may prove difficult, depending on how you generate those links and how many of them there are.