Saturday, October 24, 2009

How to know the status of tape in a tape drive

Sometime we unknowingly enter the tape in tape drive with write protection on. And when we try to take backup of any file with the below command then we get error :

root@dc # tar cvf /dev/rmt/0 /tmp/template_161009.tar.gz
tar: /dev/rmt/0: Permission denied
In unix to know what causing this problem we have a command mt.
root@dc # mt -f /dev/rmt/0 status
HP DDS-4 DAT (Sun) tape drive:
sense key(0x7)= Write Protected residual= 0 retries= 0
file no= 0 block no= 0

The above command clearly shows that the problem was write protection of the tape drive. After correcting the protection level of tape(that you have to do manually i.e eject the tape and shift the write protection button) the above command will show the status as

root@dc # mt -f /dev/rmt/0 status
HP DDS-4 DAT (Sun) tape drive:
sense key(0x0)= No Additional Sense residual= 0 retries= 0
file no= 0 block no= 0