From Tim's website
Jump to: navigation, search

Debian backup to D2D

I have an HP D2D130 virtual tape drive box, but no HP software to backup my system to it. Fortunately the Linux open-iscsi driver allows the box to be accessed as if it was a normal tape drive. The virtual robotic tape changer can be controlled with mtx, the virtual tape drive can be controlled using mt, and backups can be made using tar. The backup can be performed automatically using a cron job.

Installing open-iscsi

Install the 'open-iscsi' package (using aptitude or apt-get on Debian). View the generated iSCSI initiator name in the /etc/iscsi/initiatorname.iscsi file:

server:~# more /etc/iscsi/initiatorname.iscsi
## DO NOT EDIT OR REMOVE THIS FILE!
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator.  The InitiatorName must be unique
## for each iSCSI initiator.  Do NOT duplicate iSCSI InitiatorNames.
InitiatorName=iqn.1993-08.org.debian:01:7d70b9d2b2e
server:~#

Creating the virtual tape library

Connect to the web based user interface of the D2D box. Select 'Devices' from the menu on the left and click the 'Create' button next to the drop-down box with autoloader selected. Enter the generated iSCSI initiator name, as found in the step above.

It is possible to create your own iSCSI initiator name, but it must be the same on the D2D box and in the initiatorname.iscsi file. Restart the open-iscsi service if you change the file.

Connecting the server to the D2D box

Use the iscsiadm utility to discover the device we created and login to it:

server:~# iscsiadm -m discovery -t st -p 192.168.1.5
192.168.1.5:3260,1 iqn.1986-03.com.hp:storage.d2dbs.hu164808u0.500110a0002a9f34.autoloader1.drive
192.168.1.5:3260,1 iqn.1986-03.com.hp:storage.d2dbs.hu164808u0.500110a0002a9f38.autoloader1.robotics
server:~#

Replace the IP address with the address of your D2D box.

Use the iscsiadm utility to connect to the tape drive identified during the discovery:

server:~# iscsiadm -m node --targetname "iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.drive" --login
Logging in to [iface: default, target: iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.drive, portal: 192.168.1.5,3260]
Login to [iface: default, target: iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.drive, portal: 192.168.1.5,3260]: successful
server:~#

Use the iscsiadm utility to connect to the robotics identified during the discovery:

server:~# iscsiadm -m node --targetname "iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.robotics" --login
Logging in to [iface: default, target: iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.robotics, portal: 192.168.1.5,3260]
Login to [iface: default, target: iqn.1986-03.com.hp:storage.d2dbs.x.x.autoloader1.robotics, portal: 192.168.1.5,3260]: successful
server:~#

Verify the tape device (st) and the robotics (sg) devices have been created successfully:

server:~# ls /dev/st0*
/dev/st0  /dev/st0a  /dev/st0l  /dev/st0m
server:~# ls /dev/sg*
/dev/sg0  /dev/sg1  /dev/sg2  /dev/sg3
server:~#

Loading a tape into the virtual tape drive

Install the 'mtx' package (using aptitude or apt-get on Debian).

Try mtx on each of the /dev/sg* devices to find the tape changer:

server:~# mtx -f /dev/sg0 inquiry | grep "Product Type"
Product Type: Disk Drive
server:~# mtx -f /dev/sg1 inquiry | grep "Product Type"
Product Type: Disk Drive
server:~# mtx -f /dev/sg2 inquiry | grep "Product Type"
Product Type: Tape Drive
server:~# mtx -f /dev/sg3 inquiry | grep "Product Type"
Product Type: Medium Changer
server:~#

Use the status command to view the tape slots:

server:~# mtx -f /dev/sg3 status
Storage Changer /dev/sg3:1 Drives, 9 Slots ( 1 Import/Export )
Data Transfer Element 0:Empty
     Storage Element 1:Full :VolumeTag=Server1
     Storage Element 2:Full :VolumeTag=Server2
     Storage Element 3:Full :VolumeTag=794A3BDE
     Storage Element 4:Full :VolumeTag=794A3BDF
     Storage Element 5:Full :VolumeTag=794A3BE0
     Storage Element 6:Full :VolumeTag=794A3BE1
     Storage Element 7:Full :VolumeTag=794A3BE2
     Storage Element 8:Full :VolumeTag=794A3BE3
     Storage Element 9 IMPORT/EXPORT:Empty
server:~#

I have use the web interface to rename the first two tapes

Use the load command to move a tape into the tape drive:

server:~# mtx -f /dev/sg3 load 1
Loading media from Storage Element 1 into drive 0...done
server:~# mtx -f /dev/sg3 status
Storage Changer /dev/sg3:1 Drives, 9 Slots ( 1 Import/Export )
Data Transfer Element 0:Full (Storage Element 1 Loaded):VolumeTag = Server1
     Storage Element 1:Empty
     Storage Element 2:Full :VolumeTag=Server2
     Storage Element 3:Full :VolumeTag=794A3BDE
     Storage Element 4:Full :VolumeTag=794A3BDF
     Storage Element 5:Full :VolumeTag=794A3BE0
     Storage Element 6:Full :VolumeTag=794A3BE1
     Storage Element 7:Full :VolumeTag=794A3BE2
     Storage Element 8:Full :VolumeTag=794A3BE3
     Storage Element 9 IMPORT/EXPORT:Empty
server:~#

You can verify the operation by selecting 'Cartridges' from the left menu in the web interface

Check the status of the tape using the mt utility on the /dev/st0 device:

server:~# mt -f /dev/st0 status
drive type = 114
drive status = 1140850688
sense key error = 0
residue count = 0
file number = 0
block number = 0
server:~#

Creating a backup to the D2D box

With a tape drive loaded, use tar to backup specified directories to the tape:

tar -cvpf /dev/st0 /home /usr /etc /srv /var

Once complete, unload the tape from the drive:

server:~# mtx -f /dev/sg3 unload
Unloading drive 0 into Storage Element 1...done
server:~#