I'm trying to understand what the difference is between two options
rsync --size-only
and
rsync --ignore-times
It is my understanding that by default rsync will compare both the timestamps and the file sizes in order to decide whether or not a file should be synchronized or not. The options above allow the user to influence this behavior.
Both options seem, at least verbally to result in the same thing: comparing by size only.
Am I missing something subtle here?
This question is related to
rsync
On a Scientific Linux 6.7 system, the man page on rsync says:
--ignore-times don't skip files that match size and time
I have two files with identical contents, but with different creation dates:
[root@windstorm ~]# ls -ls /tmp/master/usercron /tmp/new/usercron
4 -rwxrwx--- 1 root root 1595 Feb 15 03:45 /tmp/master/usercron
4 -rwxrwx--- 1 root root 1595 Feb 16 04:52 /tmp/new/usercron
[root@windstorm ~]# diff /tmp/master/usercron /tmp/new/usercron
[root@windstorm ~]# md5sum /tmp/master/usercron /tmp/new/usercron
368165347b09204ce25e2fa0f61f3bbd /tmp/master/usercron
368165347b09204ce25e2fa0f61f3bbd /tmp/new/usercron
With --size-only
, the two files are regarded the same:
[root@windstorm ~]# rsync -v --size-only -n /tmp/new/usercron /tmp/master/usercron
sent 29 bytes received 12 bytes 82.00 bytes/sec
total size is 1595 speedup is 38.90 (DRY RUN)
With --ignore-times
, the two files are regarded different:
[root@windstorm ~]# rsync -v --ignore-times -n /tmp/new/usercron /tmp/master/usercron
usercron
sent 32 bytes received 15 bytes 94.00 bytes/sec
total size is 1595 speedup is 33.94 (DRY RUN)
So it does not looks like --ignore-times
has any effect at all.
You are missing that rsync can also compare files by checksum.
--size-only
means that rsync will skip files that match in size, even if the timestamps differ. This means it will synchronise fewer files than the default behaviour. It will miss any file with changes that don't affect the overall file size. If you have something that changes the dates on files without changing the files, and you don't want rsync to spend lots of time checksumming those files to discover they haven't changed, this is the option to use.
--ignore-times
means that rsync will checksum every file, even if the timestamps and file sizes match. This means it will synchronise more files than the default behaviour. It will include changes to files even where the file size is the same and the modification date/time has been reset to the original value. Checksumming every file means it has to be entirely read from disk, which may be slow. Some build pipelines will reset timestamps to a specific date (like 1970-01-01) to ensure that the final build file is reproducible bit for bit, e.g. when packed into a tar file that saves the timestamps.
The short answer is that --ignore-times
does more than its name implies. It ignores both the time and size.
In contrast, --size-only
does exactly what it says.
The long answer is that rsync
has three ways to decide if a file is outdated:
These checks are performed before transferring data. Notably, this means the static checksum is distinct from the stream checksum - the later is computed while transferring data.
By default, rsync
uses only 1 and 2. Both 1 and 2 can be acquired together by a single stat
, whereas 3 requires reading the entire file (this is independent from reading the file for transfer). Assuming only one modifier is specified, that means the following:
By using --size-only
, only 1 is performed - timestamps and checksum are ignored. A file is copied unless its size is identical on both ends.
By using --ignore-times
, neither of 1, 2 or 3 is performed. A file is always copied.
By using --checksum
, 3 is used in addition to 1, but 2 is not performed. A file is copied unless size and checksum match. The checksum is only computed if size matches.
Source: Stackoverflow.com