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.
33 if test $# -lt 2 ; then
34 echo "usage: mtx-changer ctl-device command slot archive-device drive"
35 echo " Insufficient number of arguments arguments given."
36 echo " Mimimum usage is first two arguments ..."
45 # If drive not given, default to 0
53 while ! mt -f $1 status >/dev/null 2>/dev/null; do
54 # echo "Device $1 - not ready, retrying..."
59 LOCKFILE="${LOCKDIR}/mtx-changer:`echo $ctl | tr / _'"
62 echo "$$" >$LOCKFILE.$$
64 while ! ln -n $LOCKFILE.$$ $LOCKFILE 2>/dev/null; do
65 echo "$0: changer lock busy, retrying in 30 seconds..."
73 LOCKPID="`cat $LOCKFILE 2>/dev/null`"
74 if [ "$LOCKPID" != $$ ]; then
75 echo "$0: Invalid lock file (${LOCKFILE}) - not owned by us!"
84 # Check for special cases where only 2 arguments are needed,
85 # all others are a minimum of 3
96 if test $# -lt 3; then
97 echo "usage: mtx-changer ctl-device command slot archive-device drive"
98 echo " Insufficient number of arguments arguments given."
99 echo " Mimimum usage is first three arguments ..."
109 # echo "Doing mtx -f $ctl unload $slot $drive"
111 # enable the following line if you need to eject the cartridge
112 mt -f $device offline
113 if test x$slot = x; then
114 ${MTX} -f $ctl unload
117 ${MTX} -f $ctl unload $slot $drive
123 # echo "Doing mtx -f $ctl load $slot $drive"
124 ${MTX} -f $ctl load $slot $drive
127 wait_for_drive $device
133 # echo "Requested list"
134 ${MTX} -f $ctl status | tr ':=' ' ' | nawk '($1 == "Storage" && $2 == "Element" && $4 == "Full") { printf "%s:%s\n", $3, $6 }'
139 ${MTX} -f $ctl status >/tmp/mtx.$$
141 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
142 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
149 # echo "Request slots"
150 ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"