我想知道如何使用 rsync 递归同步到文件夹,但我只需要更新新文件或更新的文件(仅内容,而不是所有者、组或时间戳),并且我想删除源中不存在的文件.
slm*_*slm 129
我想你可以使用-no-选项rsync来不复制的所有权或文件你正在同步的权限。
--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).
Run Code Online (Sandbox Code Playgroud)
查看手册页,我相信您会想要使用以下内容:
$ rsync -avz --no-perms --no-owner --no-group ...
Run Code Online (Sandbox Code Playgroud)
要删除不存在的文件,您可以使用--delete开关:
$ rsync -avz --no-perms --no-owner --no-group --delete ....
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
For timestamps, --no-times might do what you're looking for.
小智 17
我认为避免-a选项更容易
$ -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
Run Code Online (Sandbox Code Playgroud)
并只设置您想要的选项。
如果您喜欢所有选项,但不喜欢 user -o、 group -g、 time -t和 permissions -p的修改,那么您可以从存档等效项中减去这四个选项。
$ -rlD
Run Code Online (Sandbox Code Playgroud)
要删除目标文件,请使用选项--delete。
对于您的问题:但我认为将检查所有文件 - rsync 无法仅传输/检查仅由内容更改的文件。
rub*_*o77 13
我认为您正在寻找的是选项
rsync -r --size-only
Run Code Online (Sandbox Code Playgroud)
从手册页:
--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.
Run Code Online (Sandbox Code Playgroud)
如果您真的想删除源目录中丢失的文件,请使用--delete.
小智 7
您可以强制 rsync 忽略基于文件修改时间和大小的检查,并使用带有“-c”开关的基于 chksum 的方法。
-c, --checksum skip based on checksum, not mod-time & size
Run Code Online (Sandbox Code Playgroud)
这确实意味着无论文件时间和大小是否匹配,它都需要以块的形式比较整个文件(并在源和目标之间来回传输相关元数据以实现这一点),但只会传输不同的块源和目标之间。
将此开关与其他人建议的其他开关结合使用应限制复制的内容(仅复制已更改的内容),并且具有在源和目标之间进行一致性检查的好处,但根据您的链接速度,它确实需要更长的时间它必须对双方的文件块进行 chksum 和比较)。