17

I suddenly needed to recover an old tar.gz file, but as soon as I execute so:

tar -zxvf filename.tar.gz

I get this:

gzip: stdin: invalid compressed data--format violated  
tar: Child returned status 1  
tar: Error is not recoverable: exiting now
2
  • 9
    Is that really a gzipped tarball? Try file command on it first.
    – alex
    Commented Jul 27, 2011 at 5:42
  • 3
    Yes, it has happened to me more than once that I got a .tar.gz which was really a .tar, and once even a PDF.
    – vonbrand
    Commented Feb 25, 2014 at 16:39

6 Answers 6

13

What you should try is the following:

  1. Use file command on the archive to see if it's recognized as gzip-ped data.
  2. Run strace gunzip on the file. This will print the last bytes read from the file which might help you identify the point in file where corruption occurs.
  3. Run a debug build of gunzip under gdb. Try to correct the corrupted section (you have to be extra lucky to be able to do that) and see if it can continue to the end of the file.

Depending on the nature of corruption, you might or might not be able to recover your data.

1
  • gunzip filename.tar.gz worked for me. Commented Jan 19, 2015 at 9:00
6

Full recovery is not possible. Formats like .zip provide better protection and recovery options, but not full either.

.tar.gz lumps all files together and then applies a compression. .zip restarts compression for each file. Therefore in .zip file a damage done to compressed block only affects the file to which this block belongs. In .tar.gz the damage will affect all subsequent files until compression is somehow restarted.

1
  • that I was thinking, good explanation thx! I wonder if there are other formats as good as zip (but with better compression), but zip is always recognized everywhere and is probably the best option concerning recovery. Commented Jan 10, 2018 at 3:19
6

Some info about how recovery works can be found at Recovering a damaged .gz file.

There also is a tool that helps you doing this: gzip Recovery Toolkit aka gzrecover.

0
2

Run zcat bad.tar.gz > some.tar, and extract that. Going past the corrupted part of the file will be tricky. The man page gives pointers to the format, but I'd look for other options in Google.

Are you sure this is compressed with gzip? It might be complaining because it doesn't understand the format...

2

use this one : https://github.com/arenn/gzrt

gzrecover foo.tar.gz
cpio -F foo.tar.recovered -i -v
4
  • Your command results in a cpio: illegal option -- F error message.
    – schily
    Commented Jul 4, 2018 at 12:27
  • 1
    cpio --help give you the option : -F, --file=[[USER@]HOST:]FILE-NAME Use this FILE-NAME instead of standard input or output. Optional USER and HOST specify the user and host names in case of a remote archive
    – W4U
    Commented Sep 2, 2018 at 8:25
  • You are not talking abpout cpio, but about a clone with vendor specific options, see e.g. schillix.sourceforge.net/man/man1/cpio.1.html If ypou however talk about a clone instead of the original, you should mention which clone you are using.
    – schily
    Commented Sep 2, 2018 at 10:46
  • 1
    @schilly, i'm talking about cpio include in debian. GNU cpio : link
    – W4U
    Commented Sep 3, 2018 at 20:57
1

All recpies apply only for extracting info from begin of file to point where error occured, or where file is cutted.

Unfortunately no one recipie describies how to recover part of file/stream after corruption area. Has anybody that recipie?

You must log in to answer this question.

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