当我的文件可能已损坏时,我该如何从该 tar 文件中提取?

当我的文件可能已损坏时,我该如何从该 tar 文件中提取?

当我尝试从 tar 文件中提取所有文件时,出现以下错误消息:

tar: Skipping to next header
tar: Error exit delayed from previous errors

在打印此错误消息之前,某些文件已正确提取,并且该过程导致文件乱码,该文件似乎包含存档的其余部分。此存档中的所有文件都是文本文件。

我可以尝试什么来恢复其余的文件吗?

答案1

您可以尝试使用 -i 选项提取以忽略零:

The --ignore-zeros (-i) option causes tar to ignore blocks of zeros in
the archive. Normally a block of zeros indicates the end of the archive,
but when reading a damaged archive, or one which was created by cat-ing
several archives together, this option allows tar to read the entire
archive. This option is not on by default because many versions of tar
write garbage after the zeroed blocks.

答案2

您可以尝试其他版本的 tar:gnu tar、star、bsdtar 等。其中一个可能可以更好地处理错误。

您说您的文件都是文本文件,因此您应该能够手动编辑文件并选择每个文件并将其复制/粘贴到新文件中。查找每个文件之间的 tar 分隔符,它看起来像是一块 ASCII NULL,其中嵌入了文件的元数据(名称、权限、时间戳等)。

答案3

虽然不太美观,但它可以作为最后的手段:

安装“photorec”,它可能包含在你的发行版的“testdisk”包中(都可以在这里)。

键入"photorec <foo.tar>"并按照提示操作(选择“无 - 非分区媒体”和“其他”作为文件系统选项)。它应该能够恢复许多文件,但您必须手动识别和重命名它们。至少这比丢失所有文件要好。(作为参考,我打包了我的 /etc 目录并尝试了此操作。即使在未损坏的 tar 文件上,它也只能恢复 337 个文件中的 225 个,甚至其中一些文件也非常混乱。)

一种更加强力的方法是运行"strings foo.tar > out.txt"从文件中恢复文本数据,然后需要手动对其进行分类并放回到单独的文件中。

顺便说一句...在谷歌上搜索“恢复损坏的 tar 文件”,你找到了几个专门针对你的问题的工具。

相关内容