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 echo "$me $@" > /dev/console
49 if [ ! -z "$3" ]; then
52 if [ ! -z "$4" ]; then
58 # Time to wait for loading
60 # What drive of the autochanger should be used primary
61 # At the moment bacula (1.31a) could not deal with more drives
67 echo "The $me script for bacula"
68 echo "--------------------------------------"
70 echo "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
72 echo "Valid commands:"
74 echo "unload Unloads a tape into the slot"
75 echo " from where it was loaded."
76 echo "load <slot> Loads a tape from the slot <slot>"
77 echo " (slot-base is calculated to 1 as first slot)"
78 echo "list Lists full storage slots"
79 echo "loaded Gives slot from where the tape was loaded."
80 echo " 0 means the tape drive is empty."
81 echo "slots Gives Number of available slots."
84 echo " mtx-changer /dev/changer load 1 loads a tape from slot 1"
92 # enable the following line if you need to eject the cartridge
95 ${MTX} -f ${CHANGER} return drive ${DRIVE}
99 ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
101 # Increase the sleep time if you have a slow device
107 if [ "${SIMULATE_BARCODE}" = "true" ]; then
108 if [ -f "$BARCODE_FILE" ]; then
109 cat $BARCODE_FILE | grep -v "^#"
112 echo "Barcode file $BARCODE_FILE missing ... exiting!"
116 ${MTX} -f ${CHANGER} status | grep "^slot .*: .*FULL>" | awk '{print $2}' | awk -F: '{print $1+1" "}' | tr -d "[\r\n]"
121 # echo "Request loaded"
122 ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
124 cat /tmp/mtx.$$ | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
125 cat /tmp/mtx.$$ | grep "^drive ${DRIVE}: source: <>" | awk "{print 0}"
131 # echo "Request slots"
132 ${MTX} -f ${CHANGER} status | grep "^slot " | tail -1 | awk '{print $2+1}' | tr -d ":"