From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,9275097542ca04cd X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-12-06 16:02:52 PST Newsgroups: comp.unix.osf.osf1 Path: bga.com!news.sprintlink.net!pipex!sunsite.doc.ic.ac.uk!daresbury!hgmp.mrc.ac.uk!ebi.ac.uk!jr From: txomsy@ebi.ac.uk (J. R. Valverde (4423)) Subject: Re: Overwriting a tar file. Message-ID: Sender: jr@ebi.ac.uk (J. R. Valverde (4423)) Reply-To: Jose.Valverde@ebi.ac.uk Organization: European Bioinformatics Institute (EMBL) - UK X-Newsreader: mxrn 6.18-16 References: <3bvhsf$4pb@ipgate.le.ac.uk> Date: Tue, 6 Dec 1994 18:48:30 GMT 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