symlinks and different $HOME variables

Matt McCutchen hashproduct+rsync at gmail.com
Thu Feb 15 01:33:22 GMT 2007


On 2/14/07, reader4 <brace at cae.wisc.edu> wrote:
> On the desktop, my data is separate from the $HOME folder... $HOME =
> /remote/home/desktop/ and the data is at /data/.  Within /data/, I have
> several directories that are inter-related... eg, /data/pub1/figs is a link
> pointing to /data/imgs/pub1.  It makes life easier when I'm writing.
>
> On the laptop, the $HOME directory (/home/laptop/) should be the same as
> /data/, with the exception of several large sets of data, videos, etc.  The
> problem is that when I rsync /data/ to /home/laptop/, the symlinks point to
> the wrong location.

I assume you mean that the symlinks in /home/laptop/ point to files in
/data/ and you want them to point to the corresponding files in
/home/laptop/ .  The obvious fix is to use relative symlinks instead
of absolute ones.  For example, if you want /data/pub1/figs to point
to /data/imgs/pub1 , create a symlink with path ../../imgs/pub1 .  The
symlinks(8) program can convert absolute symlinks to relative ones for
you in bulk.

> Is there any workaround for this - a way to specify the
> symlinks as $HOME/... rather than the absolute directory tree?

Do you really want $HOME?  I thought $HOME on the desktop was
/remote/home/desktop/ , but the symlinks point into /data/ .  Anyway,
the answer is no: no filesystem I know of supports symlinks relative
to environment variables, and rsync doesn't support rewriting symlinks
paths.  But maybe ordinary relative symlinks (which are relative to
the directory containing them) will do what you want.

> Similarly, if I want to ease syncing even further, I can create a directory
> $HOME/sync/home/ that contains symlinks to each of the actual directories I
> want to sync and use the -L option to transfer the actual directories.  This
> makes entering the commands easy, but runs into problems with the other
> symlinks.  Any easier way to do this?

I don't understand exactly what you are trying to do (an example might
help), but I have a guess.  To make rsync follow a few specified
symlinks to directories (but not other symlinks) in the source, use
--relative and list each symlink to follow as a source argument with a
trailing slash.  For example, if you want rsync to copy src/ to dest/
, following the symlink at src/link1 , do this:

rsync -rl --relative src/./ src/./link1/ dest/

This trick requires rsync 2.6.7 or newer for the ./ syntax, or you
could cd into src/ first.  See this message for why the trick works:

http://lists.samba.org/archive/rsync/2006-February/014838.html

Matt


More information about the rsync mailing list