rsync always uploads all files from macOS => Linux

2

1

I'm testing rsync with WebDAV server in Docker container:

  • local directory: /Users/user/files/
  • "remote" mounted server: /Volumes/webdav/

Here's the initial state:

# remote
➜  cat /Volumes/webdav/remotefile
change
➜  ls -la  /Volumes/webdav/remotefile
-rwx------  1 user  staff  7 Dec  2 01:39 /Volumes/webdav/remotefile

# local
➜  cat /Users/user/files/remotefile
change
➜  ls -la  /Users/user/files/remotefile
-rwx------  1 user  staff  7 Dec  2 01:39 /Users/user/files/remotefile

Now let's change local file and upload it to "remote" server:

➜  files echo 'add#0' > ./remotefile
➜  files cat remotefile
add#0
➜  files \rsync -varP /Users/user/files/* /Volumes/webdav/ --delete
building file list ...
1 file to consider
remotefile
           6 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 132 bytes  received 42 bytes  348.00 bytes/sec
total size is 6  speedup is 0.03

File uploads successfully, as it was changed. But if I run rsync again local => remote, it re-uploads it:

➜  files \rsync -varP /Users/user/files/* /Volumes/webdav/ --delete
building file list ...
1 file to consider
remotefile
           6 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 132 bytes  received 42 bytes  348.00 bytes/sec
total size is 6  speedup is 0.03

Now I test opposite direction:

➜  files \rsync -varP /Volumes/webdav/* /Users/user/files/ --delete
building file list ...
1 file to consider
remotefile
           6 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 132 bytes  received 42 bytes  348.00 bytes/sec
total size is 6  speedup is 0.03

File downloads succesfully. And one more time...

➜  files \rsync -varP /Volumes/webdav/* /Users/user/files/ --delete
building file list ...
1 file to consider

sent 80 bytes  received 20 bytes  200.00 bytes/sec
total size is 6  speedup is 0.06

...shows 0 transfers, as file was not changed. Thats the expected behavour.

Why it doesn't work with local => remote upload and always re-uploads file?

Thanks.

f1nn

Posted 2016-12-01T22:58:55.927

Reputation: 35

Answers

2

Have you confirmed that the clocks are in sync on both local and remote?

From the rsync man page:

 Rsync finds files that need to be transferred using a lqquick checkrq algorithm 
 (by default) that looks for files that have changed in size 
 or in last-modified time.

If the clocks are out of sync, and you are not able to edit one, try telling rsync to be a little "fuzzier" with how it checks for time. Again from the man page for rsync

 --modify-window
    When comparing two timestamps, rsync treats the timestamps 
    as being equal if they differ by no more than the modify-window value. 
    This is normally 0 (for an exact match), but you may find it useful 
    to set this to a larger value in some situations. 
    In particular, when transferring to or from an MS Windows FAT filesystem 
    (which represents times with a 2-second resolution), 
    --modify-window=1 is useful (allowing times to differ by up to 1 second).

Try running rsync with the --size-only option and seeing if the behavior of rsync changes.

Another alternative is to use the --checksum option to rsync. This requires more disk I/O and cycles to generate checksums, so it can be slower. It would be interesting to know if it shifts the problem.


StandardEyre

Posted 2016-12-01T22:58:55.927

Reputation: 348

Brilliant guess! date && docker exec 1c3f5cb52a55 date => Fri Dec 2 02:18:09 MSK 2016 Thu Dec 1 23:18:09 UTC 2016 – f1nn – 2016-12-01T23:20:43.477

--size-only works as expected, but if only file symbol in file changed, it obviously considered file was not changed. – f1nn – 2016-12-01T23:22:14.473

Unfortunately, I can't control remote server time as it's third-party webdav server. size-only is unreliable. Are there any workarounds? For example, how Dropbox solves similar problems? I suppose they should use similar algorithm. – f1nn – 2016-12-01T23:24:35.937

Moscow Standard Time (MSK) is UTC +3, which makes me think the clocks are in sync. Maybe something else is at play here. – StandardEyre – 2016-12-01T23:31:41.243

Ah, I've got you. Rsync respects TZ shifts, so the time is technically the same. Right now I'm playing with --checksum option, and it seems to work at first look. But not sure, how it will work with remote 50GB server with millions of files. Thanks for pointing out direction. – f1nn – 2016-12-01T23:38:08.757