3 # Bacula interface to mtx autoloader
4 # (By Lars Köller, lars+bacula@koellers.net)
6 # Modified by Jesse D. Guardiani (jesse@wingnet.net) in Feb 2004
7 # to be more error resistant and compatible with my 4 tape SONY
8 # AIT-1 TSL-SA300C autoloader.
10 # If you set in your Device resource
12 # Changer Command = "path-to-this-script/chio-bacula %c %o %S %a"
13 # you will have the following input to this script:
15 # chio-bacula "changer-device" "command" "slot" "archive-device"
19 # chio-bacula /dev/ch0 load 1 /dev/nst0 (on a FreeBSD system)
21 # If you need to to an offline, refer to the drive as $4
22 # e.g. mt -f $f 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 # This simulates a barcode reader in the changer.
33 # The labels of the virtual barcode reader are located in the BARCODE_FILE
35 BARCODE_FILE=/usr/local/etc/bacula-barcodes
41 TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
42 if test $? -ne 0 || test x${TMPFILE} = x; then
43 TMPFILE="${TMPDIR}/mtx$1.$$"
44 if test -f ${TMPFILE}; then
45 echo "ERROR: Temp file security problem on: ${TMPFILE}"
56 logger -p user.err "$fullpath_me $@"
69 if [ ! -z "$3" ]; then
72 if [ ! -z "$4" ]; then
78 # Time to wait for loading
80 # What drive of the autochanger should be used primary
81 # At the moment bacula (1.31a) could not deal with more than one drive
87 echo "The $me script for bacula"
88 echo "--------------------------------------"
90 echo "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
92 echo "Valid commands:"
94 echo "unload Unloads a tape into the slot"
95 echo " from where it was loaded."
96 echo "load <slot> Loads a tape from the slot <slot>"
97 echo " (slot-base is calculated to 1 as first slot)"
98 echo "list Lists full storage slots"
99 echo "loaded Gives slot from where the tape was loaded."
100 echo " 0 means the tape drive is empty."
101 echo "slots Gives Number of aviable slots."
104 echo " mtx-changer /dev/changer load 1 loads a tape from slot 1"
112 # enable the following line if you need to eject the cartridge
115 # If the changer is power cycled with a tape loaded in a drive
116 if [ `${fullpath_me} ${CHANGER} loaded` -gt 0 ]; then
117 free_slot=`${fullpath_me} ${CHANGER} loaded`
118 free_slot=`expr $free_slot - 1`
119 ${MTX} -f ${CHANGER} move drive ${DRIVE} slot $free_slot
124 ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
126 # Increase the sleep time if you have a slow device
132 if [ "${SIMULATE_BARCODE}" = "true" ]; then
133 if [ -f "$BARCODE_FILE" ]; then
134 cat $BARCODE_FILE | grep -v "^#"
137 echo "Barcode file $BARCODE_FILE missing ... exiting!"
141 ${MTX} -f ${CHANGER} status | grep "^slot .*: .*FULL>" | awk '{print $2}' | awk -F: '{print $1+1" "}' | tr -d "[\r\n]"
146 # echo "Request loaded"
148 ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
150 cat ${TMPFILE} | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
151 drive=`cat ${TMPFILE}| grep "^drive .: <ACCESS>"`
152 if [ -n "$drive" ]; then
160 # echo "Request slots"
161 ${MTX} -f ${CHANGER} status | grep "^slot " | tail -1 | awk '{print $2+1}' | tr -d ":"