Linux rsync 如何对 rsync 进行校验和

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15787676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:38:18  来源:igfitidea点击:

rsync how to do a checksum on rsync

linuxbashrsyncchecksum

提问by Grimlockz

When using rsync sometimes the rsync doesn't copy all the files done, below is my code I use. 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 时,有时 rsync 不会复制完成的所有文件,以下是我使用的代码。它们是否是一种在 rsync 之后进行校验和检查以查看是否所有文件都已复制,如果没有再试一次直到所有文件都已复制?

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

rsync $OPTS --stats [email protected]:/home/user/Local $TEMP

采纳答案by slezica

I think this is best solved by configuring rsyncproperly. Read the manpage :) there's options (like --checksumfor this).

我认为这最好通过rsync正确配置来解决。阅读man页面 :) 有选项(比如--checksum这个)。

You can do this on your own as well:

您也可以自己执行此操作:

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

If you do that on both sides (local/remote), you'll have a a checksum to compare against.

如果你在双方(本地/远程)都这样做,你将有一个校验和来比较。

回答by Tom

As hinted at by u?op ?p?sdn's answer, rsync -cor rsync --checksummay do what you need.

正如 u?op ?p?sdn 的回答所暗示的那样,rsync -c或者rsync --checksum可以做你需要的。

-c, --checksum: skip based on checksum, not mod-time & size

This forces the sender to checksum every regular file using a 128-bit MD4 checksum. 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?" check.

-c, --checksum:根据校验和跳过,而不是修改时间和大小

这会强制发送方使用 128 位 MD4 校验和对每个常规文件进行校验和。它在初始文件系统扫描期间执行此操作,因为它会构建所有可用文件的列表。接收方然后对每个文件的版本进行校验和(如果它存在并且与发送方对应的文件大小相同)以确定需要更新哪些文件:选择大小改变或校验和改变的文件转移。由于除了文件传输期间发生的自动校验和验证之外,还会对连接两端的所有文件进行整个文件校验和,因此此选项可能非常慢。

请注意,rsync 始终通过检查其整个文件校验和来验证每个传输的文件是否在接收端正确重建,但自动传输后验证与此选项的传输前“此文件是否需要要被更新?” 查看。

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.

如今,对这种速度缓慢的担忧可能并不重要,当您不能或不想依赖修改时间时,这似乎是一个不错的选择。

回答by Gaia

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

sedremoves directories from the checksum verification. teeoutputs to the screen and to the file at the same time.

sed从校验和验证中删除目录。 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

来源