将Tarball存档的校验和原始目录进行比较

发布于 2025-02-09 02:11:26 字数 726 浏览 4 评论 0原文

我想知道如何在创建后用原始目录验证倒数备份的校验和。

是否可以这样做,而不会提取它是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

Get checksum of directory:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2025-02-16 02:11:26

您的目录校验和正在计算每个文件内容的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文