如何从损坏的 .tar.gz 存档中恢复文件?

发布于 2024-07-07 09:48:26 字数 316 浏览 8 评论 0原文

我的 .tar.gz 存档中有大量文件。 使用命令检查文件类型

file SMS.tar.gz

会给出响应

gzip compressed data - deflate method , max compression

当我尝试使用 Gunzip 提取存档时,经过一段延迟后,我收到消息

gunzip: SMS.tar.gz: unexpected end of file

是否有任何方法可以恢复存档的一部分?

I have a large number of files in a .tar.gz archive. Checking the file type with the command

file SMS.tar.gz

gives the response

gzip compressed data - deflate method , max compression

When I try to extract the archive with gunzip, after a delay I receive the message

gunzip: SMS.tar.gz: unexpected end of file

Is there any way to recover even part of the archive?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

西瓜 2024-07-14 09:48:26

恢复是可能的,但这取决于导致损坏的原因。

如果文件只是被截断,那么获取部分结果并不太难; 只要运行

gunzip < SMS.tar.gz > SMS.tar.partial

尽管最后出现错误,但

就会给出一些输出。 如果压缩文件有大块缺失块,坏块之后基本就没救了。

如果压缩文件以较小的方式系统性损坏(例如,以 ASCII 模式传输二进制文件,这会破坏整个文件中的回车符和换行符),则可以恢复,但需要相当多的自定义编程,这确实是值得的如果您绝对没有其他资源(没有备份)并且数据值得付出很多努力。 (我已经成功完成了。)我在上一个问题中提到了这种情况。

.zip 文件的答案有所不同,因为 zip 存档有多个单独压缩的成员,因此还有更多希望(尽管大多数商业工具相当虚假,它们通过修补 CRC 来消除警告,而不是通过恢复良好的数据)。 但您的问题是关于 .tar.gz 文件,该文件是一个包含一个大成员的存档。

Recovery is possible but it depends on what caused the corruption.

If the file is just truncated, getting some partial result out is not too hard; just run

gunzip < SMS.tar.gz > SMS.tar.partial

which will give some output despite the error at the end.

If the compressed file has large missing blocks, it's basically hopeless after the bad block.

If the compressed file is systematically corrupted in small ways (e.g. transferring the binary file in ASCII mode, which smashes carriage returns and newlines throughout the file), it is possible to recover but requires quite a bit of custom programming, it's really only worth it if you have absolutely no other recourse (no backups) and the data is worth a lot of effort. (I have done it successfully.) I mentioned this scenario in a previous question.

The answers for .zip files differ somewhat, since zip archives have multiple separately-compressed members, so there's more hope (though most commercial tools are rather bogus, they eliminate warnings by patching CRCs, not by recovering good data). But your question was about a .tar.gz file, which is an archive with one big member.

半枫 2024-07-14 09:48:26

您确定这是一个 gzip 文件吗? 我首先运行“file SMS.tar.gz”来验证这一点。

然后我会阅读 gzip 恢复工具包页面。

Are you sure that it is a gzip file? I would first run 'file SMS.tar.gz' to validate that.

Then I would read the The gzip Recovery Toolkit page.

醉生梦死 2024-07-14 09:48:26

这是我们遇到的一种可能的情况。 我们有一个 tar.gz 文件无法解压,尝试解压时出现错误:

gzip -d A.tar.gz
gzip: A.tar.gz: invalid compressed data--format violated

我发现该文件可能最初是通过非二进制 ftp 连接上传的(我们不确定) )。

使用 unix dos2unix 实用程序解决方案相对简单,

dos2unix A.tar.gz
dos2unix: converting file A.tar.gz to UNIX format ...
tar -xvf A.tar
file1.txt
file2.txt 
....etc.

它成功了!
这是一个很小的可能性,也许值得一试——它可能会帮助那里的人。

Here is one possible scenario that we encountered. We had a tar.gz file that would not decompress, trying to unzip gave the error:

gzip -d A.tar.gz
gzip: A.tar.gz: invalid compressed data--format violated

I figured out that the file may been originally uploaded over a non binary ftp connection (we don't know for sure).

The solution was relatively simple using the unix dos2unix utility

dos2unix A.tar.gz
dos2unix: converting file A.tar.gz to UNIX format ...
tar -xvf A.tar
file1.txt
file2.txt 
....etc.

It worked!
This is one slim possibility, and maybe worth a try - it may help somebody out there.

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