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
18 TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
19 if test $? -ne 0 || test x${TMPFILE} = x; then
20 TMPFILE="${TMPDIR}/mtx$1.$$"
21 if test -f ${TMPFILE}; then
22 echo "ERROR: Temp file security problem on: ${TMPFILE}"
36 #Delay in seconds the tape needs to load the tape. Needed to stop bacula from using the tape too early.
37 TAPEDELAY=65 #The StorageTek Timberwolf 9730 with DLT7000 needs approx. 50 seconds to load. 65 sec gives safety
41 echo "The mtx-changer script for bacula"
42 echo "---------------------------------"
44 echo "usage: mtx-changer <changer-device> <command> [slot] [devicename of tapedrive]"
47 echo "Valid commands:"
49 echo "unload Unloads a tape into the slot"
50 echo " from where it was loaded."
51 echo "load <slot> Loads a tape from the slot <slot>"
52 echo "list Lists full storage slots"
53 echo "loaded Gives slot from where the tape was loaded."
54 echo " 0 means the tape drive is empty."
55 echo "slots Gives Number of aviable slots."
58 echo " mtx-changer /dev/changer load 1 loads a tape from slot1"
66 # At first do mt -f /dev/st0 offline to unload the tape because HP A4853 aka Timberwolf9730
67 # refuses to unload the tape from the drive if the DLT streamer did not unloaded it!!!
69 #Check if you want to fool me
70 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we unload. I Request loaded" ; fi
72 mtx -f $1 status >${TMPFILE}
74 cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
76 read LOADEDVOL </tmp/mtxloaded
77 if [ -z "$LOADEDVOL" ] ; then
79 echo "mtx-changer: *** Don't fool me! *** The Drive $TAPEDRIVE0 is empty."
82 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mt -f $TAPEDRIVE0 offline to rewind and unload the tape!" ; fi
83 mt -f $TAPEDRIVE0 offline
84 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 $2" ; fi
90 #Let's check if drive is loaded before we load it
91 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we load. I Request loaded" ; fi
93 mtx -f $1 status >${TMPFILE}
95 cat ${TMPFILE}| grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
97 read LOADEDVOL </tmp/mtxloaded
98 if [ -z "$LOADEDVOL" ] ; then
100 echo "mtx-changer: The Drive $TAPEDRIVE0 is empty."
102 #Check if you want to fool me
103 if [ $LOADEDVOL -eq $3 ] ; then
104 echo "mtx-changer: *** Don't fool me! *** Tape $LOADEDVOL is already in drive $TAPEDRIVE0!"
108 echo "mtx-changer: The Drive $TAPEDRIVE0 is loaded with the tape from slot $LOADEDVOL"
109 echo "mtx-changer: Unloading..."
110 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mt -f $TAPEDRIVE0 offline to rewind and unload the tape!" ; fi
111 mt -f $TAPEDRIVE0 offline
112 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 unload" ; fi
115 #rm -f /tmp/mtxloaded
116 #It is now insured that the drive is empty
118 #Now we can load the drive as desired
119 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Doing mtx -f $1 $2 $3" ; fi
121 if [ $? -eq 0 ] ; then
122 #Wait until the tape is fully loaded in the dlt drive. It takes about 50 seconds. For safety wait 65 seconds
123 echo "Successfully loaded tape $3 into drive $TAPEDRIVE0."
124 echo "Waiting $TAPEDELAY seconds for the drive to fully load the tape ..."
126 echo "$TAPEDELAY seconds are gone. The tape should be fully loaded now."
127 echo "Loading finished." ;
130 echo "ERROR loading tape $3 into drive $TAPEDRIVE0. Maybe, slot $3 is empty!"
136 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Requested list"; fi
137 #old mtx -f $1 status | grep "^[ ]*Storage Element [0-9]*:.*Full" | awk "{print \$3}" | sed "s/:.*$/ /g" | tr -d "[\r\n]"
138 #from mtx bacula 1.29:
139 # mtx -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3}" | sed "s/:.*$/ /g" | tr -d "[\r\n]"
140 mtx -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
145 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request loaded" ; fi
147 mtx -f $1 status >${TMPFILE}
148 cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}"
149 cat ${TMPFILE} | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"
154 if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request slots" ; fi
155 mtx -f $1 status | grep "[ ]Storage Changer" | awk "{print \$5}"