symlinks that become directories question
Matt McCutchen
matt at mattmccutchen.net
Tue Oct 30 05:17:36 GMT 2007
On Mon, 2007-10-29 at 13:15 -0400, rob at mangiafico.net wrote:
> If I have a backup script that does the following:
> (latest 2.6.9 rsync)
>
> rsync --archive --hard-links --force --ignore-errors --numeric-ids
> --keep-dirlinks --delete / /backup
>
> I've found that if there is a symlink in place that gets backed up (which
> goes fine), i.e.:
> homelink -> /home/
>
> and then that symlink gets changed into an actual directory, i.e.:
> rm homelink
> mkdir homelink
I assume this directory is empty?
> rsync will actually delete everything in the directory that the symlink
> pointed to (in the above case it deletes /home).
Rsync's behavior, however surprising, is correct. Since you passed
--keep-dirlinks, rsync is mapping the source's "homelink" directory to
the target directory of the destination's "homelink" symlink,
i.e., /home. (Without --keep-dirlinks, rsync would first replace the
destination's "homelink" with an actual directory.) Since you passed
--delete, rsync deletes any and all files from /home that lack
counterparts in the source's "homelink".
> Is the workaround to use --delete-after to avoid this behavior, or is my
> logic flawed in using rsync with the command above to produce a mirror
> copy of an entire server to a backup drive?
--delete-after gives the same behavior. To stop rsync from following
the destination's symlink to /home, you will have to remove
--keep-dirlinks. Unfortunately, if there are other dirlinks that you
*do* need to keep, you will have to do something more complicated.
Matt
More information about the rsync
mailing list