Rsync – How to Use Only mtime Comparison

cprsyncsshtimestamps

Is it possible to sync files via rsync and let rsync only compare mtime informations?

Or is there another tool for this job?

That means that such a tool only copies src to destination if the src is newer than the destination. Comparable to GNU cp --update – but also over ssh …

Best Answer

Yes, it is possible. rsync also has --update, but with it rsync still uses its delta-transfer algorithm in case the src is newer. rsync provides the --whole-file option to disable this algorithm. Thus,

$ rsync --update --whole-file ...

should have the effect that src files are only copied to the destination when they are newer. And only mtime checks should be used for this.

There are several reasons to avoid the delta-transfer algorithm for special use cases. Mainly performance reasons and perhaps transfer volume in very special cases.

To quote from the man-page:

-W, --whole-file

With this option rsync’s delta-transfer algorithm is not used and the whole file is sent as-is instead. The transfer may be faster if this option is used when the bandwidth between the source and destination machines is higher than the bandwidth to disk (especially when the "disk" is actually a networked filesystem). This is the default when both the source and destination are specified as local paths, but only if no batch-writing option is in effect.

The case about networked filesystems should be the most common one.

Also, since the delta-transfer algorithm is a heuristic you can imagine files where the algorithm ends up transferring the whole file and just adds (time and space) overhead.

Related Question