3 # Bacula interface to mtx autoloader
5 # Created JAN/23/02 by Ludwig Jaffe
7 # Works with the HP A4853 DLT Library
8 # and the Storagetek Timberwolf 9730 DLT Library
10 #TAPEDRIVE0 holds the device/name of your 1st and only DLT drive (Bacula supports only 1 drive currently)
12 #Read TAPEDRIVE from command line parameters
19 #Delay in seconds the tape needs to load the tape. Needed to stop bacula from using the tape too early.
20 TAPEDELAY=65 #The StorageTek Timberwolf 9730 with DLT7000 needs approx. 50 seconds to load. 65 sec gives safety
24 echo "The mtx-changer script for bacula"
25 echo "---------------------------------"
27 echo "usage: mtx-changer <changer-device> <command> [slot] [devicename of tapedrive]"
30 echo "Valid commands:"
32 echo "unload Unloads a tape into the slot"
33 echo " from where it was loaded."
34 echo "load <slot> Loads a tape from the slot <slot>"
35 echo "list Lists full storage slots"
36 echo "loaded Gives slot from where the tape was loaded."
37 echo " 0 means the tape drive is empty."
38 echo "slots Gives Number of aviable slots."
41 echo " mtx-changer /dev/changer load 1 loads a tape from slot1"
49 # At first do mt -f /dev/st0 offline to unload the tape because HP A4853 aka Timberwolf9730
50 # refuses to unload the tape from the drive if the DLT streamer did not unloaded it!!!
52 #Check if you want to fool me
53 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we unload. I Request loaded" ; fi
54 mtx -f $1 status >/tmp/mtx.$$
56 cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
58 read LOADEDVOL </tmp/mtxloaded
59 if [ -z "$LOADEDVOL" ] ; then
61 echo "mtx-changer: *** Don't fool me! *** The Drive $TAPEDRIVE0 is empty."
64 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mt -f $TAPEDRIVE0 offline to rewind and unload the tape!" ; fi
65 mt -f $TAPEDRIVE0 offline
66 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 $2" ; fi
72 #Let's check if drive is loaded before we load it
73 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we load. I Request loaded" ; fi
74 mtx -f $1 status >/tmp/mtx.$$
76 cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
78 read LOADEDVOL </tmp/mtxloaded
79 if [ -z "$LOADEDVOL" ] ; then
81 echo "mtx-changer: The Drive $TAPEDRIVE0 is empty."
83 #Check if you want to fool me
84 if [ $LOADEDVOL -eq $3 ] ; then
85 echo "mtx-changer: *** Don't fool me! *** Tape $LOADEDVOL is already in drive $TAPEDRIVE0!"
89 echo "mtx-changer: The Drive $TAPEDRIVE0 is loaded with the tape from slot $LOADEDVOL"
90 echo "mtx-changer: Unloading..."
91 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mt -f $TAPEDRIVE0 offline to rewind and unload the tape!" ; fi
92 mt -f $TAPEDRIVE0 offline
93 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 unload" ; fi
97 #It is now insured that the drive is empty
99 #Now we can load the drive as desired
100 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 $2 $3" ; fi
102 if [ $? -eq 0 ] ; then
103 #Wait until the tape is fully loaded in the dlt drive. It takes about 50 seconds. For safety wait 65 seconds
104 echo "Successfully loaded tape $3 into drive $TAPEDRIVE0."
105 echo "Waiting $TAPEDELAY seconds for the drive to fully load the tape ..."
107 echo "$TAPEDELAY seconds are gone. The tape should be fully loaded now."
108 echo "Loading finished." ;
111 echo "ERROR loading tape $3 into drive $TAPEDRIVE0. Maybe, slot $3 is empty!"
117 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Requested list"; fi
118 #old mtx -f $1 status | grep "^[ ]*Storage Element [0-9]*:.*Full" | awk "{print \$3}" | sed "s/:.*$/ /g" | tr -d "[\r\n]"
119 #from mtx bacula 1.29:
120 # mtx -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3}" | sed "s/:.*$/ /g" | tr -d "[\r\n]"
121 mtx -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
126 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request loaded" ; fi
127 mtx -f $1 status >/tmp/mtx.$$
128 cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}"
129 cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"
134 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request slots" ; fi
135 mtx -f $1 status | grep "[ ]Storage Changer" | awk "{print \$5}"