How to make rsync also check ctime

rsynctimestamp

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

Best Answer

chmod and other commands that change the file's attributes but not its contents will update ctime.

That said, modifying the file's contents will change its mtime. So unless someone has gone back and reset the mtime to its earlier value, a checksum won't tell you anything that comparing mtimes won't.

Note that ctime gets updated on every change. You can't override that and you can't manually modify ctime. This means that the -t option has no effect on ctime.

I'm guessing that the authors of rsync figured that for this reason, comparing ctimes would not be very useful.

IMHO, they're wrong about that. First, you might want rsync to update a file if its attributes were changed. Second, Windows file systems don't have an mtime, so the ability to compare ctimes would be very useful when working with mounted Windows file systems. As it stands, you have to use the checksum option when syncing from a Windows file system.