将Tarball存档的校验和原始目录进行比较
我想知道如何在创建后用原始目录验证倒数备份的校验和。
是否可以这样做,而不会提取它是20GB备份的大型备份?
示例,一个带有两个文件的目录:
mkdir test &&
echo "one" > test/one.txt &&
echo "two" > test/two.txt
get 目录的校验和目录:
find test/ -type f -print0 | sort -z | xargs -0 shasum | shasum
目录内容的结果校验和
d191c793cacc4bec1f070eb96fa68524cca566f8 -
chreach tarball:create tarball:
tar -czf test.tar.gz test/
校验和 目录内容保持恒定。
但是,在创建档案并获得档案的校验和校验和时,我注意到结果会有所不同。这是为什么?
我将如何获得Tarball内容的校验和与目录内容校验和进行比较?
或者,更好的解决方案是检查存档是否包含原始目录中的所有必要内容(如果不大的话)?
I'm wondering how to verify the checksum of a tarball backup with the original directory after creation.
Is it possible to do so without extracting it for example if it's a large 20GB backup?
Example, a directory with two files:
mkdir test &&
echo "one" > test/one.txt &&
echo "two" > test/two.txt
find test/ -type f -print0 | sort -z | xargs -0 shasum | shasum
Resulting checksum of directory content:
d191c793cacc4bec1f070eb96fa68524cca566f8 -
Create tarball:
tar -czf test.tar.gz test/
The checksum of the directory content stays constant.
But when creating the archive and getting the checksum of the archive I noticed that the results vary. Why is that?
How would I go about getting the checksum of the tarball content to compare to the directory content checksum?
Or what's a better solution to check that the archive contains all the necessary content from the original directory (without extracting it if it's large)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的目录校验和正在计算每个文件内容的SHA-1。您需要阅读和解压缩整个TAR存档以进行相同的计算。这并不意味着您需要在任何地方保存存档的内容。您只需要将其顺序读取到内存中,然后在此进行计算即可。
Your directory checksum is calculating the SHA-1 of each file's contents. You would need to read and decompress the entire tar archive to do the same calculation. That doesn't mean you'd need to save the contents of the archive anywhere. You'd just need to read it sequentially into memory, and do the calculation there.