13

I've been using tar with its "--use-compress-prog=pbzip2" function to archive my files then compress them with pbzip2 to get an "*.tar.bz" archive.

Afterwards I checked the resulting file with pbzip2's "-t" switch, and it passed the test. However, to great surprise, I got "file incomplete" or other integrity errors when trying to extract the archive!

Is it because there might be something wrong with the tar file, but not when it was compressed by pbzip2? If so, is there a way to check the tar file itself? If not, what other problem might this be? Also, are there ways to recover data from tar files with errors?

I am afraid I might have already lost some important data through this process...

The point is, I would like to know a method to test the integrity of my archives after they are created.

3
  • 2
    Try uncompressing with normal bunzip2 instead of pbzip2. Also there are alternative programs for tar such as 'star' or Winrar
    – golimar
    Apr 19, 2012 at 14:45
  • 3
    Please post the commands you are running. Did you pass --use-compress-prog=pbzip2 when doing the extraction?
    – Mikel
    Apr 19, 2012 at 14:50
  • Hello. I just like to know a way to test the integrity of a tar archive after it has been created and compress via bzip2.
    – hpy
    Apr 19, 2012 at 23:44

2 Answers 2

11

First test bzip2 compression, It should output OK.

bzip2 -tv FILE.tar.bz2

Next uncompress the tarball, to get just the tar.

bunzip2 FILE.tar.bz2

Finally verify the tar file,

tar -tvWf FILE.tar

Truthfully the best indicator of a problem, is a failed extraction. Hopefully you can narrow down the cause. I should also mention I have had the occasional archive fail verification, yet still correctly extract.

6
  • 2
    Very glad I was able to point you towards your path! Apr 20, 2012 at 19:22
  • sadly bzip2 -tv takes about as long as decompression, I wish there was a way to test possibly truncated files faster
    – user30750
    Jan 21, 2013 at 15:07
  • 1
    Instead of extracting the .tar.bz2 file, you can also use tar's -j switch in addition to tvfW, which (in sufficiently recent version) can directly read bzip2 files Oct 30, 2013 at 9:25
  • @TobiasKienzler, you're absolutely correct about using tar options together, it's faster, and it was also my first thought.... But considering the OP was being somewhat 'unconventional' with his compression options, I thought it may be best to additionally verify the bzip2 compression. As combining the options would specifically verify the tar, decompressing the bzip2, hence pre-assuming its compression was already valid. Nov 4, 2013 at 23:57
  • @TobiasKienzler, but yea if it's just the tar itself in question, the extra step is unnecessary. So I +1'd your comment, as it's normally the prefered action. Nov 5, 2013 at 0:00
0

In addition to the solutions above, you always can use pipes with tar:

pbzip2 -dc FILE.tar.bz2 | tar -tvfW -
2
  • 1
    why the downvote? Please explain...
    – sekmo
    Apr 20, 2016 at 15:47
  • @sekmo On CentOS (and probably other distros with GNU tar), xz -dc file.tar.xz | tar -tvWf - gives the error cannot verify stdin/stdout archive. (I changed the order of the options because tar -tvfW - tries to read from a file called W with the error W: cannot open.)
    – Eponymous
    Oct 25, 2022 at 21:31

You must log in to answer this question.

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