0

on server1: /dir1 is a symlink to dir2

on server2: /dir1 is a directory with its own content

I want to use rsync to make server2:/dir1 be a symlink to dir2, just as it is on server1.

If I do this on server1:

rsync -azvs --delete /dir1 user@server2:/dir1

then I actually get a new (broken) symlink on server2:

/dir1/dir1 -> dir2

(so it's copying the symlink into the existing /dir1 directory instead of replacing it)

Can I instead get rsync to trample the existing /dir1 directory with the symlink?

Edit: I thought the above command would work because of this comment in the man for rsync under the --copy-dirlinks section:

Without this option, if the sending side has replaced a directory with a symlink to a directory, the receiving side will delete anything that is in the way of the new symlink, including a directory hierarchy (as long as --force or --delete is in effect).

However, the behavior appears the same with and without --force, and with and without -k.

1
+50

The problem is that you are specifying /dir1 as the destination. You need to go up one level.

rsync -azvs --delete /dir1 user@server2:/
  • Be sure not to append a final / to your source path, or you will be very sad. – njahnke Jul 5 '18 at 3:29
  • Crap. I don't even need to test this to know I'm an idiot. Thanks. And your warning made me chuckle... I'd be sad indeed. – dlo Jul 5 '18 at 21:37
0

I don't understand why you would use Rsync to make a symlink in the same server. Maybe I'm misunderstanding your question, but if you want to make a symlink inside server2 with source in /dir2 and link in /dir1, you should simply run: ln -s /dir2 /dir1.

Just in case, as stated in the other answer and extending the issue with your line.

Deconstructing your command:

rsync -azvs --delete /dir1 user@server2:/dir1

You are doing an rsync, archive mode (recursive, owner, group, include symlinks as symlinks, among others) , compressing, verbose and no space-splitting:

    -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
    -z, --compress              compress file data during the transfer
    -v, --verbose               increase verbosity
    -s, --protect-args          no space-splitting; wildcard chars only

Also, you are deleting your destination differences:

        --delete                delete extraneous files from dest dirs

Then you are using as origin /dir1, which means the whole directory, not just the contents (because there is no trailing slash "/").

And the destination is user@server2:/dir1, considering /dir1 was a symlink and you were using the -a flag for archive, you are copying the symlink inside the root /dir1, ending with this:

server2:/dir1/dir1
  • Sorry the explanation was a bit confusing. See the accepted answer to see what a dummy I was. – dlo Jul 5 '18 at 21:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.