3 # Bacula interface to mtx autoloader
7 # If you set in your Device resource
9 # Changer Command = "path-to-this-script/mtx-changer" %c %o %S %a %d
10 # you will have the following input to this script:
12 # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
17 # mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
19 # If you need to an offline, refer to the drive as $4
20 # e.g. mt -f $4 offline
22 # Many changers need an offline after the unload. Also many
23 # changers need a sleep 60 after the mtx load.
25 # N.B. If you change the script, take care to return either
26 # the mtx exit code or a 0. If the script exits with a non-zero
27 # exit code, Bacula will assume the request failed.
32 if test $# -lt 2 ; then
33 echo "usage: mtx-changer ctl-device command slot archive-device drive"
34 echo " Insufficient number of arguments arguments given."
35 echo " Mimimum usage is first two arguments ..."
44 # If drive not given, default to 0
52 # Check for special cases where only 2 arguments are needed,
53 # all others are a minimum of 3
64 if test $# -lt 3; then
65 echo "usage: mtx-changer ctl-device command slot archive-device drive"
66 echo " Insufficient number of arguments arguments given."
67 echo " Mimimum usage is first three arguments ..."
76 # echo "Doing mtx -f $ctl unload $slot $drive"
78 # enable the following line if you need to eject the cartridge
79 # mt -f $device offline
80 if test x$slot = x; then
83 ${MTX} -f $ctl unload $slot $drive
88 # echo "Doing mtx -f $ctl load $slot $drive"
89 ${MTX} -f $ctl load $slot $drive
92 # Increase the sleep time if you have a slow device
98 # echo "Requested list"
99 ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$slot \$device}" | sed "s/Full *\(:VolumeTag=\)*//"
103 ${MTX} -f $ctl status >/tmp/mtx.$$
105 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
106 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
112 # echo "Request slots"
113 ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$drive}"