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.