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 廣泛用於備份和鏡像,並作為日常使用的改進複製命令。

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。

相關內容