4

I would like to keep a log of files that I am writing to tape using dd or tar for each file. Then at the end of the run, prepend that log to the beginning of the tape using dd. If it works, I can see the contents of any tape by reading the first few blocks, and then use "mt fsf" to position the tape at the specified file. The log would look something like:

1 file1.gz
2 file2.gz
3 ...

And maybe I would include a helpful example:

to restore the second file from the this list: mt -f /dev/nst0 fsf 2; tar xf /dev/nst0

I start the run by writing a blank space to the tape:

## prepare a placeholder at the beginning of the tape    
dd if=/dev/zero bs=32k count=1024 of=/dev/nst0

## loop through the files in the directory, writing them to tape and a log
for file in $(ls test_dir); do 
    tar cf /dev/nst0 $file &&
    echo $file >>process.log
done

## rewind the tape and prepend the process.log to the tape
mt -f /dev/nst0 rewi
(dd if=process.log bs=32k; dd if=/dev/zero bs=32k count=1024)|dd of=/dev/nst0 bs=32k conv=noerror,sync,block count=1024

## see if worked
mt -f /dev/nst0 rewi
dd if=/dev/nst0 of=process.log bs=32k
mt -f /dev/nst0 fsf 1
tar tf /dev/nst0

Unfortunately while I can read the log off the tape, I can't seem to pull any further data, producing the output below. If I don't try overwriting the first file with the process log, it produces the name of a file in the test directory.

tar: This does not look like a tar archive
tar: Error exit delayed from previous errors

Is there really no way around this? I know I can stat all the files and then put together a list of files that should fit onto the tape (based on known/estimated tape capacity), then just write that first; that's not nearly as clever.

worfly
  • 41
  • 3
  • 1
    Who cares about clever? All I care about is recoverability. If clever makes it more unreliable, it's useless to me – Magellan Oct 07 '12 at 04:27
  • Have you tried putting an eof before the tar? – Zoredache Oct 07 '12 at 04:55
  • I agree, its not clever if its "more unreliable". I do think it's clever and more "reliable" if you can keep a log of files you actually put on tape, not just ones you hope to fit on tape. – worfly Oct 07 '12 at 14:40
  • okay, impossible (thanks to automatically written eod): http://net.doit.wisc.edu/~plonka/sysadmin/backup.html http://www.linux.org.za/Lists-Archives/glug-9708/msg00015.html – worfly Oct 07 '12 at 19:18

1 Answers1

2

I think you can do it, but you can't stick a file at the beginning of a TAR archive just like that; they do have headers. I suspect that if you were to move the tar archive's current contents forward on disk and write another file (header and then data blocks) into the space thus freed, you could do it. Unless you have a way to move the beginning of the file without actually moving data, such an operation would be very expensive (equivalent to rewriting the entire tape each time).

Here is the GNU description of a TAR header.

Otherwise, forget about using TAR to write the files, and use DD, while managing the file allocations yourself somehow.

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92