简体   繁体   English

rsync如何对rsync执行校验和

[英]rsync how to do a checksum on rsync

When using rsync sometimes the rsync doesn't copy all the files done, below is my code I use. 使用rsync时有时rsync不会复制完成的所有文件,下面是我使用的代码。 Is they a way to do a checksum or check after the rsync to see if all the files have been copied and if not try again until all files have been copied? 它们是一种在rsync之后进行校验和检查的方法,看看是否所有文件都已被复制,如果没有复制,直到所有文件都被复制了?

TEMP="/home/user/temp"
OPTS="-rav -h"

rsync $OPTS --stats user@example.com:/home/user/Local $TEMP

As hinted at by uʍop ǝpısdn's answer, rsync -c or rsync --checksum may do what you need. 正如uʍopǝpısdn的回答所暗示的那样, rsync -crsync --checksum可能会满足您的需求。

-c, --checksum: skip based on checksum, not mod-time & size -c, - checksum:基于校验和跳过,而不是模态时间和大小

This forces the sender to checksum every regular file using a 128-bit MD4 checksum. 这会强制发送方使用128位MD4校验和对每个常规文件进行校验和。 It does this during the initial file-system scan as it builds the list of all available files. 它在初始文件系统扫描期间执行此操作,因为它构建了所有可用文件的列表。 The receiver then checksums its version of each file (if it exists and it has the same size as its sender-side counterpart) in order to decide which files need to be updated: files with either a changed size or a changed checksum are selected for transfer. 接收器然后校验其每个文件的版本(如果它存在并且它具有与其发送方对应的相同的大小)以便决定需要更新哪些文件:具有改变的大小或改变的校验和的文件被选择用于传递。 Since this whole-file checksumming of all files on both sides of the connection occurs in addition to the automatic checksum verifications that occur during a file's transfer, this option can be quite slow. 由于除了在文件传输期间发生的自动校验和验证之外,还会发生连接两端所有文件的整个文件校验和,因此该选项可能非常慢。

Note that rsync always verifies that each transferred file was correctly reconstructed on the receiving side by checking its whole-file checksum, but that automatic after-the-transfer verification has nothing to do with this option's before-the-transfer "Does this file need to be updated?" 请注意,rsync始终通过检查其整个文件校验和来验证每个传输文件是否在接收端正确重建,但是自动传输后验证与此选项在传输之前无关“此文件是否需要要被更新?” check. 校验。

The concerns about this being slow are probably not relevant these days, and this seems to be a good option when you can't or don't want to rely on modification times. 对于这种缓慢的担忧现在可能不相关,当你不能或不想依赖修改时间时,这似乎是一个很好的选择。

I think this is best solved by configuring rsync properly. 我认为通过正确配置rsync可以最好地解决这个问题。 Read the man page :) there's options (like --checksum for this). 阅读man页:)有选项(比如--checksum )。

You can do this on your own as well: 你也可以自己做这件事:

  1. find all files in the rsync'd directory. find rsync'd目录中的所有文件。
  2. xargs md5sum to get a checksum for all files xargs md5sum获取所有文件的校验和
  3. md5sum the checksums md5sum校验和

If you do that on both sides (local/remote), you'll have aa checksum to compare against. 如果你在双方(本地/远程)这样做,你将有一个校验和进行比较。

Use rsync -Pahn --checksum /path/to/source /path/to/destination | sed '/\\/$/d' | tee migration.txt 使用rsync -Pahn --checksum /path/to/source /path/to/destination | sed '/\\/$/d' | tee migration.txt rsync -Pahn --checksum /path/to/source /path/to/destination | sed '/\\/$/d' | tee migration.txt

sed removes directories from the checksum verification. sed从校验和验证中删除目录。 tee outputs to the screen and to the file at the same time. tee输出到屏幕和文件。

Keep in mind that this might not be a suitable method if you have very large files, as the verification will take a long time. 请记住,如果您有非常大的文件,这可能不是一个合适的方法,因为验证需要很长时间。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM