I want to know how use rsync for sync to folders recursive but I only need to update the new files or the updated files (only the content not the owner, group or timestamp) and I want to delete the files that not exist in the source.
I think you can use the
-no- options to
rsync to NOT copy the ownership or permissions of the files you're sync'ing.
Excerpt From rsync Man Page
--no-OPTION You may turn off one or more implied options by prefixing the option name with "no-". Not all options may be pre‐fixed with a "no-": only options that are implied by other options (e.g. --no-D, --no-perms) or have different defaults in various circumstances (e.g. --no-whole-file, --no-blocking-io, --no-dirs). You may specify either the short or the long option name after the "no-" prefix (e.g. --no-R is the same as --no-relative). For example: if you want to use -a (--archive) but don’t want -o (--owner), instead of converting -a into -rlptgD, you could specify -a --no-o (or -a --no-owner). The order of the options is important: if you specify --no-r -a, the -r option would end up being turned on, the opposite of -a --no-r. Note also that the side-effects of the --files-from option are NOT positional, as it affects the default state of several options and slightly changes the meaning of -a (see the --files-from option for more details).
Ownership & Permissions
Looking through the man page I believe you'd want to use something like this:
$ rsync -avz --no-perms --no-owner --no-group ...
To delete files that don't exist you can use the
$ rsync -avz --no-perms --no-owner --no-group --delete ....
As for the timestamp I don't see a way to keep this without altering how you'd do the comparison of SOURCE vs. DEST files. You might want to tell
rsync to ignore timestamps using this switch:
-I, --ignore-times Normally rsync will skip any files that are already the same size and have the same modification timestamp. This option turns off this "quick check" behavior, causing all files to be updated.
--no-times might do what you're looking for.
I think it´s easier to avoid the -a option
$ -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
and set only the options do you want.
If you like all options but not the modifications of user -o, group -g, time -t and permissions -p so you could subtract these four options from the archive equivalent.
To delete the files on destination please use option --delete.
To your question: But I think all files will be checked - rsync can´t transfer/check only files that changed only by content.
I think what you are looking for is the option
rsync -r --size-only
from the man page:
--size-only This modifies rsync’s "quick check" algorithm for finding files that need to be transferred, changing it from the default of transferring files with either a changed size or a changed last-modified time to just looking for files that have changed in size. This is useful when starting to use rsync after using another mirroring system which may not preserve timestamps exactly.
If you really want to delete files missing in the source dir, use
You can force rsync to ignore checks based on file mod time and size and use a chksum based approach with the "-c" switch.
-c, --checksum skip based on checksum, not mod-time & size
This does mean that it needs to compare the entire file in chunks (and transfer the relevant metadata back and forth between source and destination for this to happen) regardless of whether or not file time and size match, but will only transfer the chunks that differ between the source and destination.
Using this switch in conjunction with the other switches suggested by others should limit what's copied (only copying that which has changed), and has the benefit of doing a consistency check between source and destination, BUT it does take longer depending on your link speed as it has to chksum the file chunks on both sides and compare).
We had a situation where rsync changes would result in things being reset further down the line, which was only desirable if the file contents had changed, not if they had just been touched.
It turned out that
--ignore-times did not work for this scenario, but telling rsync to be much more lenient with regards to whether two timestamps were equal worked. Up to a difference of a billion seconds is around 31 years which is fine for our use.
rsync --archive --itemize-changes --modify-window=1000000000 --delete-after A B
(the --itemize-changes is to be able to count the changes, and skip if none)