8

When attempting to extract all files from a tar file, I get the following error message:

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

Some of the files extract properly before this error message is printed, and the process results in a garbled file that seems to contain the rest of the archive. All of the files in this archive are text files.

Is there anything I can try to recover the rest of the files?

1
  • If they are text files, just open the tar file with vi.
    – midnite
    Mar 7, 2022 at 22:21

3 Answers 3

5

You could try your extract with the -i option to ignore zeros:

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
  • Same error message, but thanks for the suggestion.
    – Scottie T
    Jun 25, 2009 at 18:15
  • Thanks. This helped for archive created with toybox's tar.
    – domen
    Jul 11, 2018 at 11:56
1

You could try other versions of tar: gnu tar, star, bsdtar, etc. One of them might handle errors better.

You say your files are all text files, so you should be able to manually edit the file and select each file and copy/paste it to a new file. Look for tar's separator between each file, it looks like a block of ASCII NULLs with the file's metadata (name, permissions, timestamps, etc.) embedded in it.

1
  • cpio can also read .tar, and is a little more low level. Jun 25, 2009 at 18:56
0

It's not pretty, but it'll work as a last resort:

Install "photorec" which may be included in the "testdisk" package on your distribution (both can be found here).

Type "photorec <foo.tar>" and follow the prompts (choose "None -- non partitioned media" and "other" for the filesytem option). It should be able to recover many of the files, though you'll have to identify and rename them all by hand. At least it beats losing everything. (For reference, I tar'ed up my /etc dir and tried this. Even on an un-damaged tar file, it only got 225 of 337 files, and even some of those were pretty munged up.)

An even more brute force approach would be to run "strings foo.tar > out.txt" to recover text data from the file, which would then need to be sorted through and put back into separate files by hand.

BTW... a google on "recover corrupt tar file" yielded several tools specific to your problem.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .