加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 是否真的不可能将数据添加到磁带?

发布时间:2020-12-15 18:29:56 所属栏目:安全 来源:网络整理
导读:我想使用dd或tar为每个文件保存我写入磁带的文件日志.然后在运行结束时,使用dd将该日志添加到磁带的开头.如果它工作,我可以通过读取前几个块看到任何磁带的内容,然后使用“mt fsf”将磁带定位在指定的文件.日志看起来像: 1 file1.gz2 file2.gz3 ... 也许我
我想使用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

不幸的是,虽然我可以从磁带上读取日志,但我似乎无法提取任何进一步的数据,从而产生下面的输出.如果我不尝试使用进程日志覆盖第一个文件,它会在test目录中生成一个文件的名称.

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

这真的没办法吗?我知道我可以统计所有文件,然后将一个应该放在磁带上的文件列表(基于已知/估计的磁带容量),然后先写入;那不是那么聪明.

我认为你可以做到,但是你不能像这样在TAR档案的开头贴一个文件;他们确实有标题.我怀疑如果你要将tar存档的当前内容向前移动到磁盘上并将另一个文件(标题然后是数据块)写入这样释放的空间,你可以这样做.除非你有办法移动文件的开头而不实际移动数据,否则这样的操作将非常昂贵(相当于每次重写整个磁带).

Here is the GNU description of a TAR header.

否则,忘记使用TAR写入文件,并使用DD,同时以某种方式管理文件分配.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读