3 # Bacula interface to mtx autoloader
5 # This script is not needed with Bacula version 1.38 or later
6 # since the Storage daemon automatically ensures that only one
7 # thread accesses the script at a time.
12 # If you set in your Device resource
14 # Changer Command = "path-to-this-script/mtx-changer %c %o %S %a %d
15 # you will have the following input to this script:
17 # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
22 # mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
24 # If you need to an offline, refer to the drive as $4
25 # e.g. mt -f $4 offline
27 # Many changers need an offline after the unload. Also many
28 # changers need a sleep 60 after the mtx load.
30 # N.B. If you change the script, take care to return either
31 # the mtx exit code or a 0. If the script exits with a non-zero
32 # exit code, Bacula will assume the request failed.
38 if test $# -lt 2 ; then
39 echo "usage: mtx-changer ctl-device command slot archive-device drive"
40 echo " Insufficient number of arguments arguments given."
41 echo " Mimimum usage is first two arguments ..."
50 # If drive not given, default to 0
58 while ! mt -f $1 status >/dev/null 2>/dev/null; do
59 # echo "Device $1 - not ready, retrying..."
64 LOCKFILE="${LOCKDIR}/mtx-changer:`echo $ctl | tr / _'"
67 echo "$$" >$LOCKFILE.$$
69 while ! ln -n $LOCKFILE.$$ $LOCKFILE 2>/dev/null; do
70 echo "$0: changer lock busy, retrying in 30 seconds..."
78 LOCKPID="`cat $LOCKFILE 2>/dev/null`"
79 if [ "$LOCKPID" != $$ ]; then
80 echo "$0: Invalid lock file (${LOCKFILE}) - not owned by us!"
89 # Check for special cases where only 2 arguments are needed,
90 # all others are a minimum of 3
101 if test $# -lt 3; then
102 echo "usage: mtx-changer ctl-device command slot archive-device drive"
103 echo " Insufficient number of arguments arguments given."
104 echo " Mimimum usage is first three arguments ..."
114 # echo "Doing mtx -f $ctl unload $slot $drive"
116 # enable the following line if you need to eject the cartridge
117 mt -f $device offline
118 if test x$slot = x; then
119 ${MTX} -f $ctl unload
122 ${MTX} -f $ctl unload $slot $drive
128 # echo "Doing mtx -f $ctl load $slot $drive"
129 ${MTX} -f $ctl load $slot $drive
132 wait_for_drive $device
138 # echo "Requested list"
139 ${MTX} -f $ctl status | tr ':=' ' ' | nawk '($1 == "Storage" && $2 == "Element" && $4 == "Full") { printf "%s:%s\n", $3, $6 }'
144 ${MTX} -f $ctl status >/tmp/mtx.$$
146 cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
147 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}"