3

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
  • I don't think there is a way to make rsync check ctime. As you already indicated, the only way is to compare the checksums of the files. – Florian Feldhaus Nov 8 '13 at 7:05
  • Over and above of what @FlorianFeldhaus said: I can't think of any event (other than replacing the file with one that has the same mtime as the original) that will modify ctime but not mtime. – tink Sep 1 '15 at 21:23
  • @tink You can use touch to change the mtime to any time while ctime is updated to the current time. – Praveen Yalagandula Jul 6 '16 at 17:46
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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