如何创建一个省略其内容时间戳的 tar 文件? [英] How to create a tar file that omits timestamps for its contents?

查看:32
本文介绍了如何创建一个省略其内容时间戳的 tar 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法创建一个 .tar 文件,省略其文件/目录的 atime/ctime/mtime 值?

Is there a way to create a .tar file that omits the values of atime/ctime/mtime for its files/directories?

我们在构建过程中有一个步骤,即生成一个打包到 tarfile 中的工件目录.我们希望构建步骤是幂等的——给定相同的输入,它每次生成完全相同的文件/输出.

We have a step in our build process that generates a directory of artifacts that gets packaged into a tarfile. We expect that build step to be idempotent -- given the same inputs, it produces exactly the same files/output each time.

理想情况下,我们还希望该步骤在干净的构建中按位幂等,以便我们可以使用连续构建的散列来检查没有任何变化.但是因为 tar 文件包含每个条目的时间戳 (atime/ctime/mtime),该构建步骤创建的 tar 文件永远不会与前一次运行在位上完全相同,即使存档中每个文件的内容都是em> 按位相同.

Ideally, we would like also like the step to be bitwise idempotent across clean builds, so that we can use hashes of successive builds to check that nothing has changed. But because tar files include timestamps (atime/ctime/mtime) for each entry, the tar files created by that build step are never bitwise identical to the previous run, even though the contents of every file inside the archive are bitwise identical.

有没有办法生成一个省略其条目时间戳的 tarfile,以便生成存档的步骤 可以按位幂等?(我们希望利用 tar 保留的其他文件元数据,例如文件模式位和符号链接.)

Is there a way to generate a tarfile that omits the timestamps of its entries, so that the step that generates the archive could be bitwise idempotent? (We want to leverage other file metadata that tar preserves, such as file mode bits and symlinks.)

推荐答案

要获得真正的幂等 tar,mtime 是一个很好的步骤,但还不够.您还需要为 mtime 设置排序顺序、所有者和组(连同它们的映射)以及适当的时区(否则 Mac 和 Linux 之间也会出现问题).

To have a truly idempotent tar, mtime is a good step but not enough. You also need to set the sort order, the owner and group (together with their mapping) and a proper timezone for mtime (since otherwise you're gonna have issues as well between Mac and Linux).

我结束了

tar --sort=name --owner=root:0 --group=root:0 --mtime='UTC 2019-01-01' ... | gzip -n

这篇关于如何创建一个省略其内容时间戳的 tar 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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