6

This is related to this question but I don't think the answer exactly applies here.

I have two servers that sync directories between each other. These directories contain files and symlinks. On server B, I sync from server A with this command: rsync -auv A:dir/ dir/

What I want: Any file or symlink on A that is different and newer than the corresponding file or symlink on B is synced.

What actually happens: Any file on A that is different and newer than the corresponding file on B is synced. Any symlink on A that is different than the corresponding symlink on B is synced, regardless of timestamp.

The man page for rsync has this (emphasis mine):

-u, --update

This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file's, it will be updated if the sizes are different.) Note that this does not affect the copying of symlinks or other special files.

So this is the expected behavior. Why is this? Is there a way around it? Or, is there an alternate solution to the overall goal, which is to get these directories in sync after a server has been offline for some time and missed data?

My rsync version is 3.0.9.

Example: I set up 2 directories, Adir and Bdir, each containing a file and a symlink with different contents:

$ ls -l Adir/ Bdir/ Adir/: total 0 -rw-r--r-- 1 kevin kevin 5 May 27 18:00 file lrwxrwxrwx 1 kevin kevin 10 May 27 18:00 symlink -> /some/file Bdir/: total 0 -rw-r--r-- 1 kevin kevin 6 May 27 17:00 file lrwxrwxrwx 1 kevin kevin 16 May 27 17:00 symlink -> /some/other/file 

Running rsync --dry-run -auv Adir/ Bdir/ outputs this:

sending incremental file list ./ file symlink -> /some/file sent 101 bytes received 21 bytes 244.00 bytes/sec total size is 15 speedup is 0.12 (DRY RUN) 

Which is what I expect. It copies (or would if not in dry run) both the file and symlink because they are newer. However running rsync --dry-run -auv Bdir/ Adir/ outputs this:

sending incremental file list ./ symlink -> /some/other/file sent 104 bytes received 18 bytes 244.00 bytes/sec total size is 22 speedup is 0.18 (DRY RUN) 

Even though Bdir/symlink is older than Adir/symlink it still gets syned.

1
  • "the overall goal, which is to get these directories in sync after a server has been offline for some time and missed data" - do you want to get B to look like A, or A to look like B? Either way, I don't understand why the fact that the reverse operation doesn't work is a problem. Commented Sep 7, 2020 at 21:23

1 Answer 1

1

One way out may be to ignore symlinks in rsync and do them separately with, for example, tar which can be asked not to overwrite newer targets. Eg

( cd Adir; find . -type l | tar cf - -T- ) | tar xvvf - --keep-newer-files -C Bdir 
2
  • This sounds like it would be a messy solution because the directories are on different servers. But I could probably work with this is there aren't any better options. Commented May 28, 2018 at 23:09
  • I was also looking for a cleaner, solution, but in the edn just chaining tar, with ssh, seems to work ok cd / ; ssh remote tar -cz /var/folder | tar -xz --keep-newer-files. Its inneffient that transfers all data over the 'wire' even if not ultimatly extracted. A slight hack is to perhaps look for the newest file on local (ie when last run) and then just add '--after-date ' to the first tar, to only tranfer new files more incrementally - still not as effient as rsync. Commented Sep 16, 2020 at 16:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.