比较两个服务器之间文件的校验和并报告不匹配 [英] Compare checksum of files between two servers and report mismatch

查看:183
本文介绍了比较两个服务器之间文件的校验和并报告不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将machineA/primary/secondary文件夹中的所有文件的校验和与此远程服务器machineB中的该文件夹/bat/snap/中的文件进行比较.远程服务器将包含很多文件以及我们在machineA中拥有的文件.

I have to compare checksum of all files in /primary and /secondary folders in machineA with files in this folder /bat/snap/ which is in remote server machineB. The remote server will have lots of files along with the files we have in machineA.

  • 如果校验和有任何不匹配,那么我想报告所有在machineA中有问题的文件,并具有完整路径,并以非零状态代码退出.
  • 如果所有内容都匹配,则退出零.
  • If there is any mismatch in checksum then I want to report all those files that have issues in machineA with full path and exit with non zero status code.
  • If everything is matching then exit zero.

我在machineA上运行了一个命令(不确定是否有更好的写法),但是它非常慢.有什么方法可以使其更快?

I wrote one command (not sure whether there is any better way to write it) that I am running on machineA but its very slow. Is there any way to make it faster?

(cd /primary && find . -type f -exec md5sum {} +; cd /secondary && find . -type f -exec md5sum {} +) | ssh machineB '(cd /bat/snap/ && md5sum -c)'

它也打印出像这样的文件名./abc_monthly_1536_proc_7.data: OK.有什么方法可以在machineA上打印出该文件的完整路径名?

Also it prints out file name like this ./abc_monthly_1536_proc_7.data: OK. Is there any way by which it can print out full path name of that file on machineA?

ssh传输到每个文件的远程主机肯定不是非常有效. parallel可以通过同时执行更多文件来加快速度,但是更有效的方法可能是稍微调整一下命令,以便它对sshB进行ssh并一次性获得所有md5sum.这可能吗?

ssh to remote host for every file definitely isn't very efficient. parallel could speed it up by doing it concurrently for more files, but the more efficient way is likely to tweak the command a bit so it does ssh to machineB and gets all the md5sum in one shot. Is this possible to do?

推荐答案

如果您的主要目标不是计算校验和而是列出差异,则也许更快(更容易)的方法是使用--dry-run选项运行rsync .如果列出了任何文件,则它们会有所不同,例如:

If your primary goal is not to count the checksums but list differences, perhaps faster (and easier) way would be to run rsync with --dry-run option. If any files listed, they differs, for example:

MBP:~ jhartman$ rsync -avr --dry-run rsync-test 192.168.1.100:/tmp/; echo $?
building file list ... done
rsync-test/file1.txt

sent 172 bytes  received 26 bytes  396.00 bytes/sec
total size is 90  speedup is 0.45

当然,由于--dry-run,目标上的文件没有更改.

Of course, because of --dry-run no files changed on the target.

我希望它会有所帮助, 杰瑞克(Jarek)

I hope it will help, Jarek

这篇关于比较两个服务器之间文件的校验和并报告不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆