我想保留一个日志文件,我正在写磁带使用dd或tar为每个文件。 然后在运行结束时,使用dd将该日志前置到磁带的开头。 如果有效,我可以通过读取前几个块来看到任何磁带的内容,然后使用“mt fsf”将磁带放在指定的文件中。 日志看起来像这样:
1 file1.gz 2 file2.gz 3 ...
也许我会包括一个有用的例子:
to restore the second file from the this list: mt -f /dev/nst0 fsf 2; tar xf /dev/nst0
我通过向磁带写入一个空格开始运行:
## 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
不幸的是,虽然我可以从磁带上读取日志,但我似乎无法获得更多的数据,产生下面的输出。 如果我不尝试用进程日志覆盖第一个文件,它将产生testing目录中文件的名称。
tar: This does not look like a tar archive tar: Error exit delayed from previous errors
这真的没有办法吗? 我知道我可以统计所有的文件,然后把适合磁带的文件列表(根据已知的/估计的磁带容量),然后把它写出来。 那几乎没有那么聪明
我认为你可以做到这一点,但是你不能像这样在TAR档案的开头粘贴一个文件; 他们有标题。 我怀疑,如果要将tar归档文件的当前内容向前移动到磁盘上,并将另一个文件(头文件,然后是数据块)写入到已释放的空间中,则可以这样做。 除非你有办法在没有实际移动数据的情况下移动文件的开始,否则这样的操作将非常昂贵(相当于每次重写整个磁带)。
这是一个TAR头文件的GNU描述。
否则,忘记使用TAR来编写文件,并使用DD,而不知怎的pipe理文件分配。