我可以让 rsync 在以下条件下工作吗?
if len(f1) != len(f2) then rsync
if len(f1) == len(f2) and md5sum(f1) != md5sum(f2) then rsync
Run Code Online (Sandbox Code Playgroud)
最接近的是--checksum
选项?
小智 8
取自手册rsync
页:
描述
Rsync 是一种快速且非常通用的文件复制工具。它可以在本地、通过任何远程 shell 复制到另一台主机或从远程 rsync 守护程序复制到/从另一个主机复制。它提供了大量选项来控制其行为的各个方面,并允许非常灵活地指定要复制的文件集。它以其增量传输算法而闻名,该算法通过仅发送源文件与目标中现有文件之间的差异来减少通过网络发送的数据量。Rsync 广泛用于备份和镜像,并作为日常使用的改进复制命令。
Rsync 使用 lqquick checkrq 算法(默认情况下)查找需要传输的文件,该算法查找大小或上次修改时间已更改的文件。当快速检查表明不需要更新文件的数据时,其他保留属性的任何更改(根据选项的要求)都会直接在目标文件上进行。
因此,我们在描述中看到的默认行为是:
if len(f1) != len(f2) then rsync
现在,只需寻找与校验和相关的选项即可。在手册中搜索:
-c, --checksum
This changes the way rsync checks if the files have been changed and are in
need of a transfer. Without this option, rsync uses a lqquick checkrq that
(by default) checks if each file's size and time of last modification match
between the sender and receiver. This option changes this to compare a 128-
bit checksum for each file that has a matching size. Generating the checksums
means that both sides will expend a lot of disk I/O reading all the data in
the files in the transfer (and this is prior to any reading that will be
done to transfer changed files), so this can slow things down significantly.
Run Code Online (Sandbox Code Playgroud)
的描述--checksum
正是您想要的if len(f1) == len(f2) and md5sum(f1) != md5sum(f2) then rsync
。它将对每个大小匹配的文件进行 128 位校验和。
但要小心,因为此选项会根据情况显着增加您的 I/O。