Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rsync with custom fixing of symlinks

58 views
Skip to first unread message

Travis

unread,
Feb 18, 2009, 7:03:01 PM2/18/09
to
I have a large number of directories and files that I need to rsync
into another directory. There are going to be plenty of symlinks in
the directories that may be broken. If they are broken, know what I
have to do to fix them.

So ideally I'm looking for a way to rsync an entire directory of files
(recursively) and each time a broken symlink is found, resolve it by
changing where it points.

For example is a symlink is broke and points to /usr/local/foo, change
it to /real_source/usr/local/foo.

Icarus Sparry

unread,
Feb 18, 2009, 9:29:27 PM2/18/09
to

Do it in 2 steps?

1) rsync
2) find . -type l | while read ln ; do
D=$(readlink "$ln")
[ -e "$D] || ln -sf /real_source/"$D" "$ln"
done

Some versions of 'find' offer extra help, for example

find . -type l ! -xtype l | xargs....

will find broken links rather better (but not perfectly). Then there are
the standard warnings about newlines etc embeded in filenames. However as
you say these are your own files we can probably not worry about them.

Harry

unread,
Feb 19, 2009, 3:57:52 PM2/19/09
to

From the manpage of rsync:

-l, --links copy symlinks as symlinks
-L, --copy-links copy the referent of symlinks

Would you consider the -L option ?

Travis

unread,
Feb 19, 2009, 7:32:14 PM2/19/09
to

Yeah I've looked into that. The problem is that I am going to be
copying broken links so I need to intervene each time and modify the
link itself.

0 new messages