3 # Bacula interface to mtx autoloader
4 # (By Lars Koeller, lars+bacula@koellers.net)
6 # If you set in your Device resource
8 # Changer Command = "path-to-this-script/chio-bacula %c %o %S %a"
9 # you will have the following input to this script:
11 # chio-bacula "changer-device" "command" "slot" "archive-device"
15 # chio-bacula /dev/sg0 load 1 /dev/nst0 (on a FreeBSD system)
17 # If you need to to an offline, refer to the drive as $4
18 # e.g. mt -f $f offline
20 # Many changers need an offline after the unload. Also many
21 # changers need a sleep 60 after the mtx load.
23 # N.B. If you change the script, take care to return either
24 # the mtx exit code or a 0. If the script exits with a non-zero
25 # exit code, Bacula will assume the request failed.
28 # This simulates a barcode reader in the changer.
29 # The labels of the virtual barcode reader are located in the BARCODE_FILE
31 BARCODE_FILE=/usr/local/etc/bacula-barcodes
36 TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
37 if test $? -ne 0 || test x${TMPFILE} = x; then
38 TMPFILE="${TMPDIR}/mtx$1.$$"
39 if test -f ${TMPFILE}; then
40 echo "ERROR: Temp file security problem on: ${TMPFILE}"
49 echo "$me $@" > /dev/console
62 if [ ! -z "$3" ]; then
65 if [ ! -z "$4" ]; then
71 # Time to wait for loading
73 # What drive of the autochanger should be used primary
74 # At the moment bacula (1.31a) could not deal with more drives
80 echo "The $me script for bacula"
81 echo "--------------------------------------"
83 echo "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
85 echo "Valid commands:"
87 echo "unload Unloads a tape into the slot"
88 echo " from where it was loaded."
89 echo "load <slot> Loads a tape from the slot <slot>"
90 echo " (slot-base is calculated to 1 as first slot)"
91 echo "list Lists full storage slots"
92 echo "loaded Gives slot from where the tape was loaded."
93 echo " 0 means the tape drive is empty."
94 echo "slots Gives Number of available slots."
97 echo " mtx-changer /dev/changer load 1 loads a tape from slot 1"
105 # enable the following line if you need to eject the cartridge
108 ${MTX} -f ${CHANGER} return drive ${DRIVE}
112 ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
114 # Increase the sleep time if you have a slow device
120 if [ "${SIMULATE_BARCODE}" = "true" ]; then
121 if [ -f "$BARCODE_FILE" ]; then
122 cat $BARCODE_FILE | grep -v "^#"
125 echo "Barcode file $BARCODE_FILE missing ... exiting!"
129 ${MTX} -f ${CHANGER} status | grep "^slot .*: .*FULL>" | awk '{print $2}' | awk -F: '{print $1+1" "}' | tr -d "[\r\n]"
134 # echo "Request loaded"
136 ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
138 cat ${TMPFILE} | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
139 cat ${TMPFILE} | grep "^drive ${DRIVE}: source: <>" | awk "{print 0}"
145 # echo "Request slots"
146 ${MTX} -f ${CHANGER} status | grep "^slot " | tail -1 | awk '{print $2+1}' | tr -d ":"