Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: txomsy@ebi.ac.uk (J. R. Valverde (4423))
Subject: Re: Overwriting a tar file.
Date: Tue, 6 Dec 1994 18:48:30 GMT	[thread overview]
Message-ID: <D0EK8u.Lp1@ebi.ac.uk> (raw)
In-Reply-To: 3bvhsf$4pb@ipgate.le.ac.uk


In article <3bvhsf$4pb@ipgate.le.ac.uk>, cob@ltsun0.star.le.ac.uk (Colin Barber) writes:
>From: cob@ltsun0.star.le.ac.uk (Colin Barber)
>Newsgroups: comp.unix.osf.osf1
>Subject: Overwriting a tar file.
>
>
>I had an exabyte with two large tar files on it. I have accidentally then written
>a small tar file over the beginning of the first large tar file.
>
>I would like to recover what I can from the first tar file and be able to access
>the second tar file. 
>
>Anyone any ideas?
>

Read the contents of the the whole tar tape in raw mode into some dummy
file and then edit it. It shouldn't be too difficult to locate the
start of first file with more, and then insert a file label in front of it
using any editing utility or a simple C program.

Now untar it.

In more detail: you can open the raw device and read from it all the
contents. You should be able even use more on it. Hence locating the
end of the first tar file and the beginning of the damaged one should
not be much of a problem.

Then, first, extract the first file, lest you destroy it without backup.

Now write a tar header in front of the second archive adapted for
the first contents, and go on. I'd suggest to use a binary<->hex
converter to locate the exact positions you need to use:

	1) Position of the end of the first tar archive
	2) Position of the end of the first file in the overwritten
archive.
	3) Position (end of first tar archive - tar header length).***

At this last position write the tar header, so that it does not overwrite
what's left of the ooverwritten archive. Note that this would invalidate
the contents of the first archive too:

  1st archive     overwritten archive        second archive    
+--------------+--------------------------+--------------------+
! 1st archive  | 1st file| ... |     |    |  second archive    |
+--------------+--------------------------+--------------------+
           3   1         2
           <---> tar header length (see tar.h)

Reposition the tar tape at that same last position (the new start of
the tar archive).

Run tar without rewinding the tape.

Alternatively, you can do all this on disk by copying the contents
of the tape first into disk.

*** This last position might vary depending on your tar archiver charac-
teristics: some archivers I have seen padd the file length to blocks
when archiving, and some others don't. But it will be self-evident
from the listing you get with more.

I'd bet that there must be some kind of utility somewhere to do this,
But I don't know of any and never worried about wwriting one.

****************

Note, on second thought, you could try to replace the end of tape
record by a tar file header record and then read through. That could
be even easier and safer. And could render you an usable tar tape too!
Actually I don't remember now the block sizes, but it may actually
turn out that if they are the same size, the first solution turns
out to be the same as this one!

				jr

			Jose R. Valverde
		European Bioinformatics Institute


      reply	other threads:[~1994-12-06 18:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-05 17:15 Overwriting a tar file Colin Barber
1994-12-06 18:48 ` J. R. Valverde (4423) [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox