[comp.unix.questions] Trashed Tar tape

0004068145@mcimail.com (Ari Kahan) (09/21/90)

In re:
>Can someone help?  A full tape was made unreadable.  The error probably
>was someone typing 'tar cv <filename>' instead of 'tar xv <filename>'.
>Since the file was not on the harddrive at that point, a 'file does
>not exist' came up and the data on the tape is now inaccesible.  Since
>the tape has not been advanced, it stands to reason that the data is
>still on it, but unix has placed some sort of maer  at the beginning of the t
>I have tried the mt comands to forward over EOF markers, but no luck.
>If anyone can help, please contact me directly, since I am not a
>regular subscriber to this list.  Vikram_varma@cc.sfu.ca
>Thanks.  Vik.


Here's a solution which, in theory, should allow you to
get back everything except the first file on the tar tape.
Since I don't know what flavor of UNIX you're using, it's
hard to know for sure whether it'll work on yours.

As you suspected, the only part of the tape that should be lost
is the very beginning.  Since each file on the tartape has
its own header, the idea is to skip over the first file and
its header to the second file.  So, the concept is to run the contents
of the tape through stdin to tar, but hide the first (mangled)
portion of the contents of the tape from tar.

Tar (unless it's some weird version) stores files in 512 byte
blocks.  So, the first file (with its header) will be sized at
a multiple of 512, regardless of the actual size of the file.  To eliminate
the mangled first file, you can use dd to
skip the first block on the tape, or the first two blocks, or
the first three blocks, until you get something that makes sense.

The command should look something like this:

dd if=/dev/fd1 skip=1 ibs=512 | tar tv
             ^(or however you identify your tape drive)

Try this, changing the value of the skip to skip=2, skip=3,
etc. (you may want to use a batchfile) until you get something
looking like normal output from tar.
(Obviously, this process will go a lot faster if you have some idea
of the size of the first file on the tape.)
Once you know how many blocks to skip, you can use tar as normal.
You just won't get that first file.

Ari Kahan
 

ucbked@athena.berkeley.edu (Earl H. Kinmonth) (09/21/90)

[How to recover a damaged tar tape when the damage is at the
header.]

This is a common enough problem that one would think that someone would
add this as an option to tar.

[k]tar, my heavily modified version of GNUtar (of serveral years) ago
has a recovery option built in.  It will skip blocks until it finds one
that passes the header check sum test and then start extracting.

A more sophisticated approach would be to allow looking for file names
and trying the block in which a pattern is found as a header.