Ubuntu 12.04下虚拟磁带库mhvtl的安装和使用

 
项目需要连接一下昆腾虚拟磁带库DXI 6701 ,这玩意太贵,不好得到,先弄个虚拟软件测试了,
网上了一下,有这个软件: mhvtl
 
 
在Ubuntu 下安装
下载当前最新版是 mhvtl-2013-03-22.tgz
上面有rpm版的,在centos下比较好装,网上也有很多教程,
我这次带来Ubuntu版的:
 
apt-get install zlib1g-dev mt-st mtx lsscsisg3_utils liblzo2-dev

tar zxvf mhvtl-2013-03-22.tgz
cd mhvtl-1.4

安装内核
cd kernel
make;
make install;
 
安装成功后可以偿试启动mhvtl了
root@lion-SNS:/opt# service mhvtl start
vtllibrary process PID is 19281
vtllibrary process PID is 19284

查看VTL挂截情况

root@lion-SNS:/opt# lsscsi -g
[0:0:0:0]    disk    ATA      ST500DM002-1BD14 KC45  /dev/sda  /dev/sg0
[2:0:0:0]    cd/dvd  HL-DT-ST DVD+-RW GH82N    A102  /dev/sr0  /dev/sg1
[4:0:0:0]    disk    Generic- SD/MMC           1.00  /dev/sdb  /dev/sg2
[4:0:0:1]    disk    Generic- Compact Flash    1.01  /dev/sdc  /dev/sg3
[4:0:0:2]    disk    Generic- SM/xD Picture    1.02  /dev/sdd  /dev/sg4
[4:0:0:3]    disk    Generic- MS/MS-Pro        1.03  /dev/sde  /dev/sg5
[13:0:0:0]   mediumx STK      L700             0104  /dev/sch0  /dev/sg14
[13:0:1:0]   tape    IBM      ULT3580-TD5      0104  /dev/st0  /dev/sg6
[13:0:2:0]   tape    IBM      ULT3580-TD5      0104  /dev/st1  /dev/sg7
[13:0:3:0]   tape    IBM      ULT3580-TD4      0104  /dev/st2  /dev/sg8
[13:0:4:0]   tape    IBM      ULT3580-TD4      0104  /dev/st3  /dev/sg9
[13:0:8:0]   mediumx STK      L80              0104  /dev/sch1  /dev/sg15
[13:0:9:0]   tape    STK      T10000B          0104  /dev/st4  /dev/sg10
[13:0:10:0]  tape    STK      T10000B          0104  /dev/st5  /dev/sg11
[13:0:11:0]  tape    STK      T10000B          0104  /dev/st6  /dev/sg12
[13:0:12:0]  tape    STK      T10000B          0104  /dev/st7  /dev/sg13

sg14,sg15为两个磁带机,sg6-9,sg11-13分别为他们的磁头

查看磁带机状态:

root@lion-SNS:/home/lion# mtx -f /dev/sg14 status
  Storage Changer /dev/sg14:4 Drives, 43 Slots ( 4 Import/Export )
//四个读写磁头
Data Transfer Element 0:Empty
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
//43个磁带槽
      Storage Element 1:Full :VolumeTag=E01001L4                            
      Storage Element 2:Full :VolumeTag=E01002L4                            
      Storage Element 3:Full :VolumeTag=E01003L4                            
      Storage Element 4:Full :VolumeTag=E01004L4                            
      Storage Element 5:Full :VolumeTag=E01005L4                            
      Storage Element 6:Full :VolumeTag=E01006L4                            
      Storage Element 7:Full :VolumeTag=E01007L4                            
      Storage Element 8:Full :VolumeTag=E01008L4                            
      Storage Element 9:Full :VolumeTag=E01009L4                            
      Storage Element 10:Full :VolumeTag=E01010L4                            
      Storage Element 11:Full :VolumeTag=E01011L4                            
      Storage Element 12:Full :VolumeTag=E01012L4                            
      Storage Element 13:Full :VolumeTag=E01013L4                            
      Storage Element 14:Full :VolumeTag=E01014L4                            
      Storage Element 15:Full :VolumeTag=E01015L4                            
      Storage Element 16:Full :VolumeTag=E01016L4                            
      Storage Element 17:Full :VolumeTag=E01017L4                            
      Storage Element 18:Full :VolumeTag=E01018L4                            
      Storage Element 19:Full :VolumeTag=E01019L4                            
      Storage Element 20:Full :VolumeTag=E01020L4                            
      Storage Element 21:Empty
      Storage Element 22:Full :VolumeTag=CLN101L4                            
      Storage Element 23:Full :VolumeTag=CLN102L5                            
      Storage Element 24:Empty
      Storage Element 25:Empty
      Storage Element 26:Empty
      Storage Element 27:Empty
      Storage Element 28:Empty
      Storage Element 29:Empty
      Storage Element 30:Full :VolumeTag=F01030L5                            
      Storage Element 31:Full :VolumeTag=F01031L5                            
      Storage Element 32:Full :VolumeTag=F01032L5                            
      Storage Element 33:Full :VolumeTag=F01033L5                            
      Storage Element 34:Full :VolumeTag=F01034L5                            
      Storage Element 35:Full :VolumeTag=F01035L5                            
      Storage Element 36:Full :VolumeTag=F01036L5                            
      Storage Element 37:Full :VolumeTag=F01037L5                            
      Storage Element 38:Full :VolumeTag=F01038L5                            
      Storage Element 39:Full :VolumeTag=F01039L5                            
      Storage Element 40 IMPORT/EXPORT:Empty
      Storage Element 41 IMPORT/EXPORT:Empty
      Storage Element 42 IMPORT/EXPORT:Empty
      Storage Element 43 IMPORT/EXPORT:Empty
root@lion-SNS:/home/lion# 
View Code

将磁带装入磁头才能进行读写存储操作

将第1个磁带装入磁头0
root@lion-SNS:/home/lion# mtx -f /dev/sg14 load 1 0
Loading media from Storage Element 1 into drive 0...done

root@lion-SNS:/home/lion# mtx -f /dev/sg14 status
Storage Changer /dev/sg14:4 Drives, 43 Slots ( 4 Import/Export )
Data Transfer Element 0:Full (Storage Element 1 Loaded):VolumeTag = E01001L4
Data Transfer Element 1:Empty
Data Transfer Element 2:Empty
Data Transfer Element 3:Empty
Storage Element 1:Empty
Storage Element 2:Full :VolumeTag=E01002L4
Storage Element 3:Full :VolumeTag=E01003L4
Storage Element 4:Full :VolumeTag=E01004L4
Storage Element 5:Full :VolumeTag=E01005L4

 

进行数据存储,lsscsi -g 可以得到驱动器的设备名称为/dev/st0,1,2,3


[13:0:0:0]   mediumx STK      L700             0104  /dev/sch0  /dev/sg14
[13:0:1:0]   tape    IBM      ULT3580-TD5      0104  /dev/st0  /dev/sg6
[13:0:2:0]   tape    IBM      ULT3580-TD5      0104  /dev/st1  /dev/sg7
[13:0:3:0]   tape    IBM      ULT3580-TD4      0104  /dev/st2  /dev/sg8
[13:0:4:0]   tape    IBM      ULT3580-TD4      0104  /dev/st3  /dev/sg9
 

Linux下使用磁带机的方式有多种,主要有通过Amanda、Tar、cpio、pax、ufsdump等软件进行操作。

Amanda是提供了远程集中备份的功能,通过分别设置客户端、服务器端,实现远程集中存储备份。而Tar主要用于单机环境下,将数据直接写入磁带的备份。

针对单一节点的备份,只要简单的使用Tar命令进行备份、恢复即可。

往磁带中写入文件,和读取文件

root@lion-SNS:~# tar -cvf /dev/st0 restartN* 
restartNetwork.sh
restartNova.sh
root@lion-SNS:~# tar -tvf /dev/st0
-rw-r--r-- root/root       197 2013-04-09 11:14 restartNetwork.sh
-rw-r--r-- root/root        85 2013-04-09 11:11 restartNova.sh
root@lion-SNS:~# 

磁带库其它操作命令

列出磁带机状态
mt -f /dev/st0 status

SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x46 (LTO-4).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN //磁带准备就绪
DR_OPEN //磁带门打开,磁带未准备好

倒带,将磁带卷至起始位置: 
#  mt -f /dev/st0 rewind

擦除,擦掉磁带上的内容,如果是真实磁带,对磁带损伤比较大,一般不用。
mt -f /dev/st0 erase

装磁带从插槽1装入驱动器0
mt -f /dev/sg14 load 1 0
卸载磁带,将磁带从驱动器0卸载放到插槽1: # mtx
-f /dev/sg14 unload 1 0 出带,将磁带卷至初始位置然后从磁带机内弹出 mt –f /dev/st0 offline 列目录操作,假如磁带上没有任何文件,则列目录会报错,忽略即可。 tar tvf /dev/st0 写入数据操作,每次写入都会覆盖之前的文件。 tar cvf /dev/st0 <要写入的文件名> 继续写入数据,不覆盖之前文件,tar cvf 会覆盖之前写入的文件 tar rvf /dev/st0 <要写入的文件名> 读取数据到当前目录 tar xvf /dev/st0 <要读取的文件名>

  检查磁头是否位置磁带的起始位置
  root@lion-SNS:/tmp# mt -f /dev/st0 tell
  At block 0.

  磁带前进n个文件

  mt -f /dev/nst0 fsf n

  磁带后退n个文件

  mt -f /dev/nst0 bsf n

 cpio命令

  cpio 命令用于复制需要跨多个磁带卷的文件、特殊文件或文件系统。可实现不同系统间文件的可移植性,但命令比tar更复杂,其复制机制类似于块复制。

将文件备份到磁带
ls | cpio -ov filename > /dev/st0

备份目录树
find . -print -depth | cpio -ov > tree.cpio

从磁带恢复
cpio -iv 

cpio 常用参数说明

-o :将数据copy到文件或设备上
-i :将数据从文件或设备上还原到系统中
-t :查看cpio建立的文件或设备内容
-c :一种比较新的portableformat方式存储
-v :在屏幕上显示备份过程中的文件名
-B :让预设的blocks可以增加到5120bytes,默认是512bytes,这样可以使备份速度加快
-d :自动建立目录,这样还原时才不会出现找不到路径的问题
-u :更新,用较新的文件覆盖旧的文件

跨磁带备份及恢复文件举例

//mhvtl 默认的磁带大小是 500M,找一个超过500M的文件
root@lion-SNS:/home/lion/下载/pub# ls -lh ubuntu1210-smartvm.iso 
-rw-rw-r-- 1 lion lion 722M  6月  8 17:16 ubuntu1210-smartvm.iso 

//写入磁带
root@lion-SNS:/home/lion/下载/pub# ls ubuntu1210-smartvm.iso | cpio -covB > /dev/st1
磁带已结束。要继续,在准备就绪时输入设备/文件名。
//驱动器1已经写满,提示输入驱动器2的设备号
/dev/st2
ubuntu1210-smartvm.iso
141108//读取文件,因为mhvtl写入st0完毕后,可能会把st0磁带弹出,需要重新装入,确保st0,st1都在线方可读取文件
root@lion-SNS:/home/lion/下载/pub/tmp# cpio -civuB< /dev/st0
磁带已结束。要继续,在准备就绪时输入设备/文件名。
/dev/st1
ubuntu1210-smartvm.iso
141108 块
root@lion-SNS:/home/lion/下载/pub/tmp# ll
总用量 705548
drwxr-xr-x 2 root root 4096 6月 24 16:14 ./
drwxrwxr-x 3 lion lion 4096 6月 24 16:04 ../
-rwxrwxrwx 1 lion lion 722468864 6月 24 16:15 ubuntu1210-smartvm.iso*

TroubleShooting:

编译出错:


root@lion-SNS:/home/lion/Downloads/mhvtl-1.4# make
make -C usr USR=vtl GROUP=vtl MHVTL_HOME_PATH=/opt/mhvtl MHVTL_CONFIG_PATH=/etc/mhvtl
make[1]: 正在进入目录 `/home/lion/Downloads/mhvtl-1.4/usr'
cc -Wall -Wshadow -g -O2 -D_LARGEFILE64_SOURCE  -I../kernel -DMHVTL_VERSION="1.4.7" -D_GNU_SOURCE -DMHVTL_DEBUG -DUSR="vtl" -DMHVTL_HOME_PATH="/opt/mhvtl" -DMHVTL_CONFIG_PATH="/etc/mhvtl"   -c -o vtltape.o vtltape.c
vtltape.c:95:25: 致命错误: lzo/lzoconf.h:没有那个文件或目录
编译中断。
make[1]: *** [vtltape.o] 错误 1
make[1]:正在离开目录 `/home/lion/Downloads/mhvtl-1.4/usr'
make: *** [usr] 错误 2

说明缺少lzo库,这个名字不好找
apt-get install liblzo2-dev

安装后,再继续

make
make install

启动失败(Media .. failed)是因为权限问题:

dmesg
chown -Rf /opt/mhvtl

误删除磁带设备符号 /dev/st0

rm -f /dev/st0
用mt -f /dev/st0 status察看已经说
/dev/st0: Inappropriate ioctl for device

用mt -f /dev/nst0察看提示:
SCSI 2 tape drive:
File number=-1, block number=-1, partition=0.
Tape block size 0 bytes. Density code 0x0 (default).
Soft error count since last status=0
General status bits on (8050000):
EOD DR_OPEN IM_REP_EN

用dmesg看有这样的提示:
mtrr: type mismatch for fc000000,800000 old: uncachable new: write-combining
mtrr: type mismatch for fc000000,800000 old: uncachable new: write-combining
st0: Failed to read 10240 byte block with 512 byte read.
end_request: I/O error, dev 02:00 (floppy), sector 0

//解决办法 
mknod /dev/st0 c 9 0
chmod 660 /dev/st0
chgrp disk /dev/st0
原文地址:https://www.cnblogs.com/biangbiang/p/3148796.html