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 # So Bacula will always call with all the following arguments, even though
13 # in come cases, not all are used.
15 # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
20 # mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
22 # will request to load the first cartidge into drive 0, where
23 # the SCSI control channel is /dev/sg0, and the read/write device
26 # If you need to an offline, refer to the drive as $4
27 # e.g. mt -f $4 offline
29 # Many changers need an offline after the unload. Also many
30 # changers need a sleep 60 after the mtx load.
32 # N.B. If you change the script, take care to return either
33 # the mtx exit code or a 0. If the script exits with a non-zero
34 # exit code, Bacula will assume the request failed.
38 TMPFILE=`mktemp mtx.XXXXXXXXXX`
39 if test x${TMPFILE} = x; then
40 TMPFILE="@working_dir@/mtx.$$"
41 if test -f ${TMPFILE}; then
42 echo "Temp file security problem on: ${TMPFILE}"
48 # The purpose of this function to wait a maximum
49 # time for the drive. It will
50 # return as soon as the drive is ready, or after
51 # waiting a maximum of 300 seconds.
52 # Note, this is very system dependent, so if you are
53 # not running on Linux, you will probably need to
54 # re-write it, or at least change the grep target.
58 while [ $i -le 300 ]; do # Wait max 300 seconds
59 if mt -f $1 status | grep ONLINE >/dev/null 2>&1; then
62 # echo "Device $1 - not ready, retrying..."
69 if test $# -lt 2 ; then
70 echo "usage: mtx-changer ctl-device command slot archive-device drive"
71 echo " Insufficient number of arguments arguments given."
72 echo " Mimimum usage is first two arguments ..."
85 # Check for special cases where only 2 arguments are needed,
86 # all others are a minimum of 3
93 if test $# -lt 5; then
94 echo "usage: mtx-changer ctl-device command slot archive-device drive"
95 echo " Insufficient number of arguments arguments given."
104 # echo "Doing mtx -f $ctl unload $slot $drive"
106 # enable the following line if you need to eject the cartridge
107 # mt -f $device offline
108 ${MTX} -f $ctl unload $slot $drive
112 # echo "Doing mtx -f $ctl load $slot $drive"
113 ${MTX} -f $ctl load $slot $drive
116 # Increase the sleep time if you have a slow device
117 # or remove the sleep and add the following:
118 # wait_for_drive $device
124 # echo "Doing mtx -f $ctl -- to list volumes"
125 ${MTX} -f $ctl status >${TMPFILE}
127 cat ${TMPFILE} | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
128 cat ${TMPFILE} | grep "^Data Transfer Element [0-9]*:Full (Storage Element [0-9]" | awk '{printf "%s:%s\n",$7,$10}'
129 rm -f ${TMPFILE} 2>&1 >/dev/null
131 # If you have a VXA PacketLoader and the above does not work, try
132 # turning it off and enabling the following line.
133 # ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | sed "s/*Storage Element //" | sed "s/Full :VolumeTag=//"
138 # echo "Doing mtx -f $ctl $drive -- to find what is loaded"
139 ${MTX} -f $ctl status >${TMPFILE}
141 cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
142 cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
143 rm -f ${TMPFILE} 2>&1 >/dev/null
148 # echo "Doing mtx -f $ctl -- to get count of slots"
149 ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"