In this blog, we are going to test writing data to a tape library. The tape library is HPE MSL 2024 with 24 tape slots and two tape drives. The tapes are LTO Ultrium 7 with 15 TB capacity. The tape library must be connected to a physical server, in this case we have connected the tape library to the physical server via Fibre Channel. We have setup Cent OS 7 in the physical server.
We can check if the tape devices are present in the server as SCSI devices by running the following commands in the Cent OS server:
[root@backup ~]# lsscsi
[0:0:0:0] tape HP Ultrium 7-SCSI HB81 /dev/st1
[1:0:0:0] storage HP P420i 8.00 -
[1:1:0:0] disk HP LOGICAL VOLUME 8.00 /dev/sda
[4:0:0:0] tape HP Ultrium 7-SCSI HB81 /dev/st0
[4:0:0:1] mediumx HP MSL G3 Series 7.00 /dev/sch0
[root@backup ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: P420i Rev: 8.00
Type: RAID ANSI SCSI revision: 05
Host: scsi1 Channel: 01 Id: 00 Lun: 00
Vendor: HP Model: LOGICAL VOLUME Rev: 8.00
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06
Host: scsi4 Channel: 00 Id: 00 Lun: 01
Vendor: HP Model: MSL G3 Series Rev: 7.00
Type: Medium Changer ANSI SCSI revision: 05
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06
We can see in the above output that three tape devices are present in the server:
- The first device is a "Sequential-Access" tape drive, present as /dev/st0.
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06
2. The second device is a "Sequential-Access" tape drive, present as /dev/st1.
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06
3. The third device is the "Medium Changer" or the tape library hosting the tapes and the tape drives.
Host: scsi4 Channel: 00 Id: 00 Lun: 01
Vendor: HP Model: MSL G3 Series Rev: 7.00
Type: Medium Changer ANSI SCSI revision: 05
It is important to note that Linux presents the tape drives with two types of device files:
- /dev/st0 and /dev/st1.
- /dev/nst0 and /dev/nst1.
The "n" in the second file type stands for non-rewinding tape. If we use /dev/st0 and write data to the tape, the tape will auto rewind to the beginning of the tape and the data will be overwritten with new data while writing data the second time.
However, if we use /dev/nst0 and write data to the tape, the tape will not auto rewind to the beginning of the tape and new data can be written sequentially after the previous data.
For management of tape drive, we will run the "mt" commands and "tar" commands to write data to the tapes.
For checking the status of the two tape drives the following commands are run:
[root@backup ~]# mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x5c (no translation).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN
[root@backup ~]# mt -f /dev/nst1 status
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 (50000):
DR_OPEN IM_REP_EN
The first tape drive /dev/nst0 status, indicates that the tape is loaded from it's slot to the first tape drive. The tape is ready for data to be written and the general status indicates BOT ONLINE IM_REP_EN. BOT means Beginning Of Tape.
The second tape drive /dev/nst1 status, indicates the tape drive is empty with the general status DR_OPEN IM_REP_EN.
For this test we have run the commands as root user, however, we should create a different user with privileges for production systems.
[root@backup ~]# ls
anaconda-ks.cfg devices scsi tape test1 test2 test3 test4 test5
Now, we write these test files to the first tape drive using tar.
[root@backup ~]# tar -cvzf /dev/nst0 test1 test2 test3 test4 test5
test1
test2
test3
test4
test5
After writing data, the tape needs to be rewind to check and verify that data has been written.
[root@backup ~]# mt -f /dev/nst0 rewind
Then, we check the status of the tape drive to verify that the tape is at the beginning.
[root@backup ~]# mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x5c (no translation).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN
Now, we verify the test data by running tar.
[root@backup ~]# tar -tzf /dev/st0
test1
test2
test3
test4
test5
After checking the data by running above command, the tape will wind to the end of the data. We again rewind the tape:
[root@backup ~]# mt -f /dev/nst0 rewind
[root@backup ~]# mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x5c (no translation).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN
Then, we go to the end of the data:
[root@backup ~]# mt -f /dev/nst0 eod
And check the status of the tape drive to verify the tape is at the end of data denoted by general status EOD ONLINE IM_REP_EN.
[root@backup ~]# mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=1, block number=-1, partition=0.
Tape block size 0 bytes. Density code 0x5c (no translation).
Soft error count since last status=0
General status bits on (9010000):
EOD ONLINE IM_REP_EN
For a final test we erase the contents of the tape. Since we are at the end of data, we need to rewind again.
[root@backup ~]# mt -f /dev/nst0 rewind
Now, we erase the contents of the tape in the first tape drive.
[root@backup ~]# mt -f /dev/nst0 erase
So, we have tested by writing data to tape drives from Linux server successfully. These are basic operations required to manually write data to a single tape drive or a tape library. However, in practice, it is preferred to use a backup software solution where a backup configuration is done once according to the company's backup policy for automatic backup and to prevent potential human error.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.