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.

Anthon
  • 78,313
  • 42
  • 165
  • 222
hpy
  • 4,517
  • 8
  • 53
  • 73
  • 2
    Try uncompressing with normal bunzip2 instead of pbzip2. Also there are alternative programs for tar such as 'star' or Winrar – golimar Apr 19 '12 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 '12 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 '12 at 23:44

2 Answers2

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.

Keilaron
  • 143
  • 4
J. M. Becker
  • 4,831
  • 3
  • 28
  • 40
  • 2
    Very glad I was able to point you towards your path! – J. M. Becker Apr 20 '12 at 19:22
  • sadly bzip2 -tv takes about as long as decompression, I wish there was a way to test possibly truncated files faster –  Jan 21 '13 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 – Tobias Kienzler Oct 30 '13 at 09: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. – J. M. Becker Nov 04 '13 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. – J. M. Becker Nov 05 '13 at 00:00
  • Ah, I didn't consider the possibility of a defective bzip2 vs tar - I don't know if `tar` would yield a meaningful error message to deduce the source of error – Tobias Kienzler Nov 05 '13 at 07:23
0

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

pbzip2 -dc FILE.tar.bz2 | tar -tvfW -
garethTheRed
  • 33,289
  • 4
  • 92
  • 101
  • 1
    why the downvote? Please explain... – sekmo Apr 20 '16 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 '22 at 21:31