why does --size-only not detect change only is size (but also time)?

C Sights csights at fastmail.fm
Thu Apr 19 12:53:36 GMT 2007


> "Transferring" refers specifically to copying the *data* of a regular
> file from sender to receiver and is only one of several things that
> rsync can do to a file.  The others: rsync can "locally create" files
> (usually only non-regular files), hard-link them, delete them, and
> "tweak" their attributes.  The first character of an itemize line
> tells you the kind of processing: ">" or "<" for a transfer, "c" for a
> local creation, "h" for a hard link, "*" for a deletion, and "." for
> none of the preceding.  Attribute tweaks are indicated by additional
> letters after the file type letter.

Thank you, how rsync works is a little more clear to me now. :)

After reading what you both have said, and throwing in some things from 
previous knowledge, it seems as though what rsync does can be broken up into 
a number pieces.

+ Including/Excluding directories and files
+ Detecting changed files
+ What is transferred (including metadata)
+ How files are updated (on receiver)
+ How files are deleted (on receiver)

It might make the rsync manual more understandable if the long options were 
broken up into sections corresponding to these pieces (or other more fitting 
pieces).  In each section rsync's default behavior is explained, followed by 
the switches that change the default behavior.  I have written some example 
sections below to help get the idea across the internets series of tubes. :)

To make it easier to explain how rsync works and easier to write the sections 
I have diverged from rsync's actual behavior.  Mostly, the conscious changes 
were made to the "how files updated" section (which is what started this 
conversation).  I've added an imaginary --tweak option.  This option tweaks 
metadata if that is the only thing that has changed and can be used with 
any "detecting changed files" check.

The conscious changes to the "detecting changed files" part of the manual is 
to add that all metadata specified to be transferred is also used when 
detecting changed files.  I believe this is how rsync behaves.


---------------------------------------------------------------------------
IMAGINARY PARTIAL OPTIONS SECTION OF MANUAL PAGE
---------------------------------------------------------------------------
Options for deciding which file(s) have changed and need to be transferred:

By default rsync checks that both the file's size, last modification time and 
any selected metadata to be transferred match on the sender and receiver.  If 
the size, last modification time, or any metadata does not match, the file is 
transferred.

--size-only
	Instead of the default behavior, rsync checks only that the file's size and 
any selected metadata to be transferred match on sender and receiver.  If the 
sizes (or any metadata) do not match, the file is transferred.  (Last 
modification time is ignored.) This is useful when starting to use rsync 
after using another mirroring system which may not preserve timestamps 
exactly.

-c, --checksum
	Instead of the default behavior, rsync checks that both the file's size, 
checksum, and any selected metadata match on sender and receiver. If the 
size, checksum, or metadata does not match, the file is transferred.  As an 
optimization, checksums are only created if the file's sizes match. 
Generating the 128-bit MD4 checksums means that both sides will expend a lot 
of disk I/O reading the entire content of the files, so this can slow things 
down significantly.

	The sending side generates its checksums while it is doing the file-system 
scan that builds the list of the available files. The receiver generates its 
checksums when it is scanning for changed files, and will checksum any file 
that has the same size as the corresponding sender's file: files with either 
a changed size or a changed checksum are selected for transfer.

	Note that rsync always verifies that each transferred file was correctly 
reconstructed on the receiving side by checking a whole-file checksum that is 
generated when as the file is transferred, but that automatic 
after-the-transfer verification has nothing to do with this option's 
before-the-transfer "Does this file need to be updated?" check.

-I, --ignore-times
	Instead of the default behavior, rsync does no checks and transfers selected 
metadata and the contents of all files.

--modify-window
[...etc....]

----------------------------------------------------------
Options for changing what is transferred:

By default rsync transfers _____??_____.

(metadata)
-p, --perms
	long description here
-E, --executability
	long description here
-A, --acls
	long description here
-o, --owner
	long description here
-g, --group
	long description here
-t, --times
	long description here
-O, --omit-dir-times
	long description here
--numeric-ids
	long description here

(non-metadata, or in separate section)

[....etc........]

----------------------------------------------------------
Options for changing how files are updated on the receiver:

By default rsync creates a temporary file on the receiver, deletes the old 
file, then moves the temporary file to the place of the old file.

--tweak
	When only metadata has changed, update the metadata without changing the file 
contents.

--inplace
	long description here

--delay-updates
	long description here

[....etc....]

-----------------------------------------------------------
Options controlling how files are deleted on receiver:

By default rsync does not delete any files that exist on the receiver but not 
the sender.

--delete                
	delete extraneous files from dest dirs before new files are transferred.
--delete-before         
	same as --delete
--del
	long description here
--delete-during
	long description here
--delete-after
	long description here
--delete-excluded
	long description here
-----------------------------------------------------------


So, using the motivating example (two files have same contents, (same size,) 
different modtimes):

#rsync -ani --tweak Untitled.pdf Untitled-2.pdf
.f..t...... Untitled.pdf
(metadata is tweaked)

#rsync -ani Untitled.pdf Untitled-2.pdf
>f..t...... Untitled.pdf

#rsync -ani --size-only --tweak Untitled.pdf Untitled-2.pdf
.f..t...... Untitled.pdf

#rsync -ani --size-only Untitled.pdf Untitled-2.pdf
>f..t...... Untitled.pdf
(for consistency, default behavior without --tweak)

#rsync -ani --size-only --no_t --tweak Untitled.pdf Untitled-2.pdf
(nothing)

#rsync -ani --no_t Untitled.pdf Untitled-2.pdf
>f..T...... Untitled.pdf
(because default "detect file change" compares timestamps, and --no_t means 
don't transfer modtime metadata)

#rsync -ani --no_t --tweak Untitled.pdf Untitled-2.pdf
.f..T...... Untitled.pdf
(because default "detect file change" compares timestamps, --no_t means don't 
transfer modtime metadata, and --tweak is used)

Thanks for reading all that,
	C.



More information about the rsync mailing list