如何创建同一文件的相同 gzip?
我有一个文件,其内容是相同的。 它被传递到 gzip 中并且仅存储压缩形式。 我希望能够再次生成 zip,并且仅在它们不同时更新我的副本。 目前比较工具(diff、xdelta、subversion)将文件视为已更改。
前提是,我将一个重要数据库的 mysqldump 存储到一个 subversion 存储库中。 我的目的是让 cronjob 定期转储数据库、对其进行 gzip 压缩并提交文件。 目前,每次转储文件然后进行 gzip 压缩时,都会将其视为不同的。 我不希望我的版本号每 15m 不必要地增加一次。
我意识到我可以将文件转储为纯文本,但我不希望这样做,因为它相当大。
我当前用于生成转储的命令是:
mysqldump $DB --skip-extended-insert | sed '$d' | gzip -n > $REPO/$DB.sql.gz
-n
指示 gzip 删除文件名/时间戳信息。 sed '$d'
删除 mysqldump 放置时间戳的文件的最后一行。
此时,我可能会恢复以纯文本方式存储它,但我很好奇有什么样的解决方案。
已解决,先生。 Bright 是正确的,当正确的参数是小写的时候,我错误地使用了大写的 N。
I have a file, its contents are identical. It is passed into gzip and only the compressed form is stored. I'd like to be able to generate the zip again, and only update my copy should they differ. As it stands diffing tools (diff, xdelta, subversion) see the files as having changed.
Premise, I'm storing a mysqldump of an important database into a subversion repository. It is my intention that a cronjob periodically dump the db, gzip it, and commit the file. Currently, every time the file is dumped and then gzipped it is considered as differing. I'd prefer not to have my revision numbers needlessly increase every 15m.
I realize I could dump the file as just plain text, but I'd prefer not as it's rather large.
The command I am currently using to generate the dumps is:
mysqldump $DB --skip-extended-insert | sed '$d' | gzip -n > $REPO/$DB.sql.gz
The -n
instructs gzip to remove the filename/timestamp information. The sed '$d'
removes the last line of the file where mysqldump places a timestamp.
At this point, I'm probably going to revert to storing it in a plain text fashion, but I was curious as to what kind of solution there is.
Resolved, Mr. Bright was correct, I had mistakenly used a capital N when the correct argument was a lowercase one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,这样做恰恰相反。
-n
告诉它忘记原始文件名和时间戳。Actually, that does just the opposite.
-n
is what tells it to forget the original file name and time stamp.我认为 gzip 保留了文件的原始日期和时间戳,这将导致它生成不同的存档。
I think gzip is preserving the original date and timestamp on the file(s) which will cause it to produce a different archive.
但请注意:在不同时间对同一个未更改的文件制作的两个 gzip 是不同的。 这是因为 gzip 本身带有 gzip 创建日期的时间戳 - 这被写入 gzip 文件的标头。 因此,明显不同的 gzip 可以包含完全相同的内容。
But watchout: two gzips made at different times of the same unchanged file differ. This is because the gzip is itself timestamped with the gzip creation date - this is written to the header of the gzip file. Thus the apparently different gzips can contain the exact same content.