How do I make rsync also check ctime?

Posted by Benoît on Server Fault See other posts from Server Fault or by Benoît
Published on 2013-11-02T18:00:46Z Indexed on 2013/11/02 21:59 UTC
Read the original article Hit count: 336

Filed under:
|

rsync detects files modification by comparing size and mtime. However, if for any reason, the mtime is unchanged, rsync won't detect the change, although it's possible to spot it by looking at the ctime.

Of course, I can tell rsync do compare the whole files' contents, but that's very very expensive.

Is there a way to make rsync smarter, for example by checking mtime+size are the same AND that ctime isn't newer than mtime (on both source and destination) ? Or should I open a feature request ?


Here's an example:

Create 2 files, same content and atime/mtime

benoit@debian:~$ mkdir d1 && cd d1
benoit@debian:~/d1$ echo Hello > a
benoit@debian:~/d1$ cp -a a b

Rsync them to another (non-exisiting) directory:

benoit@debian:~/d1$ cd ..
benoit@debian:~$ rsync -av d1/ d2
sending incremental file list
created directory d2
./
a
b

sent 164 bytes  received 53 bytes  434.00 bytes/sec
total size is 12  speedup is 0.06

OK, everything is synced

benoit@debian:~$ grep . d*/*
d1/a:Hello
d1/b:Hello
d2/a:Hello
d2/b:Hello

Update file 'b', same size and then reset its atime/mtime

benoit@debian:~$ echo World > d1/b
benoit@debian:~$ touch -r d1/a d1/b

Attempt to rsync again:

benoit@debian:~$ rsync -av d1/ d2
sending incremental file list

sent 63 bytes  received 12 bytes  150.00 bytes/sec
total size is 12  speedup is 0.16

Nope, rsync missed the change.

benoit@debian:~$ grep . d*/*
d1/a:Hello
d1/b:World
d2/a:Hello
d2/b:Hello

Tell rsync the compare the file content

benoit@debian:~$ rsync -acv d1/ d2
sending incremental file list
b

sent 144 bytes  received 31 bytes  350.00 bytes/sec
total size is 12  speedup is 0.07

Gives the correct result:

benoit@debian:~$ grep . d*/*
d1/a:Hello
d1/b:World
d2/a:Hello
d2/b:World

© Server Fault or respective owner

Related posts about rsync

Related posts about timestamp