Prevent rsync from changing ctime

rsync

I have the following scenario:

I have files in one directory where there is a process that is changing some files and updating the ctime on all files. I want to rsync all files to a target directory but preserve the ctime of those files that only got their ctime updated.

I have tried the following (~/source/test.txt is my source file and ~/target/test.txt is my target file).

chmod a+w source/test.txt (updates ctime but not mtime)
rsync -a -v -c --copy-dirlinks --delete --partial --inplace source/test.txt target

My expectation was that those files that have only their ctime updated in the source directory do not get rsync'd and apparently that is the case. But the corresponding file in the target directory still gets its ctime updated – which is currently causing trouble with my backup process.

Is there any way to have rsync not update the ctime for files that have not been modified?

Best Answer

You could try if the --checksum option does what you want:

-c, --checksum

This changes the way rsync checks if the files have been changed and are in need of a transfer. Without this option, rsync uses a "quick check" that (by default) checks if each file's size and time of last modification match between the sender and receiver. This option changes this to compare a 128-bit checksum for each file that has a matching size. Generating the checksums means that both sides will expend a lot of disk I/O reading all the data in the files in the transfer (and this is prior to any reading that will be done to transfer changed files), so this can slow things down significantly.

When doing a short test, this worked, but not when using the shortcut -a option, maybe because it includes -t, which preserves mod times.