rsync仅复制更改的文件;忽略文件修改时间戳

rsync仅复制更改的文件;忽略文件修改时间戳

我可以让 rsync 在以下条件下工作吗?

if len(f1) != len(f2) then rsync
if len(f1) == len(f2) and md5sum(f1) != md5sum(f2) then rsync

最接近的是--checksum选项??


答案1

摘自rsync联机帮助页:

描述

Rsync 是一种快速且用途广泛的文件复制工具。它可以通过任何远程 shell 在本地复制到/从另一台主机复制,或者复制到/从远程 rsync 守护进程复制。它提供了大量的选项来控制其行为的各个方面,并允许非常灵活地指定要复制的文件集。它以其增量传输算法而闻名,该算法通过仅发送源文件与目标中现有文件之间的差异来减少通过网络发送的数据量。 Rsync 广泛用于备份和镜像,并作为日常使用的改进复制命令。

Rsync 使用 lqquick checkrq 算法(默认)查找需要传输的文件查找大小或上次修改时间已更改的文件。当快速检查表明文件的数据不需要更新时,将直接在目标文件上对其他保留的属性(根据选项的请求)进行任何更改。

因此,我们在描述中看到的默认行为是:

  • 复制工具,可在本地或远程工作
  • 很多选择
  • 默认情况下的增量传输算法,仅传输不同的文件集以减少网络使用量
  • 广泛使用的镜像和备份工具
  • checkrq 算法在条件 1 上执行您想要的操作: 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.

的描述--checksum正是您想要的if len(f1) == len(f2) and md5sum(f1) != md5sum(f2) then rsync。它将对每个大小匹配的文件执行 128 位校验和。

但要小心,因为根据具体情况,此选项会显着增加 I/O。

相关内容