3 # /bin/sh isn't always compatible so use /bin/bash
5 # Bacula interface to mtx autoloader
9 # If you set in your Device resource
11 # Changer Command = "path-to-this-script/mtx-changer %c %o %S %a %d"
12 # you will have the following input to this script:
14 # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
19 # mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
21 # If you need to an offline, refer to the drive as $4
22 # e.g. mt -f $4 offline
24 # Many changers need an offline after the unload. Also many
25 # changers need a sleep 60 after the mtx load.
27 # N.B. If you change the script, take care to return either
28 # the mtx exit code or a 0. If the script exits with a non-zero
29 # exit code, Bacula will assume the request failed.
32 # Sun sed/awk etc are not sufficient, working versions are in /usr/xpg4/bin
33 export PATH="/usr/local/bin:/usr/sfw/bin:/usr/xpg4/bin:/usr/bin"
39 # The purpose of this function to wait a maximum
40 # time for the drive. It will
41 # return as soon as the drive is ready, or after
42 # waiting a maximum of 180 seconds.
43 # Note, this is very system dependent, so if you are
44 # not running on Linux, you will probably need to
47 # If you have a FreeBSD system, you might want to change
48 # the $(seq 180) to $(jot 180) -- tip from Brian McDonald
51 for i in $(seq 180); do # Wait max 180 seconds
52 if ( mt -f $1 status | grep 0x0 ) >/dev/null 2>&1; then
53 #echo "Device $1 READY"
56 #echo "Device $1 - not ready, retry ${i}..."
62 if test $# -lt 2 ; then
63 echo "usage: mtx-changer ctl-device command slot archive-device drive"
64 echo " Insufficient number of arguments arguments given."
65 echo " Mimimum usage is first two arguments ..."
74 # If drive not given, default to 0
82 # Check for special cases where only 2 arguments are needed,
83 # all others are a minimum of 3
94 if test $# -lt 3; then
95 echo "usage: mtx-changer ctl-device command slot archive-device drive"
96 echo " Insufficient number of arguments arguments given."
97 echo " Mimimum usage is first three arguments ..."
106 # echo "Doing mtx -f $ctl unload $slot $drive"
108 # enable the following line if you need to eject the cartridge
109 #mt -f $device offline
110 mt -f $device rewoffl
111 if test x$slot = x; then
112 ${MTX} -f $ctl unload
114 ${MTX} -f $ctl unload $slot $drive
119 # echo "Doing mtx -f $ctl load $slot $drive"
120 ${MTX} -f $ctl load $slot $drive
123 # Increase the sleep time if you have a slow device
124 # or remove the sleep and add the following:
126 wait_for_drive $device
131 # echo "Requested list"
132 # Some tape changers lose track of their inventory (well, mine does) so
133 # do one before trying to get a status out of it.
134 ${MTX} -f $ctl inventory
135 ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
136 # Comment out the previous line and add a line here
137 # to print "fake" barcodes.
139 # If you have a VXA PacketLoader and the above does not work, try
140 # turning it off and enabling the following line.
141 # ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | sed "s/*Storage Element //" | sed "s/Full :VolumeTag=//"
145 ${MTX} -f $ctl status >/tmp/mtx.$$
147 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
148 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
154 # echo "Request slots"
155 ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"