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 logger -p user.err "$fullpath_me $@"
54 if [ ! -z "$3" ]; then
57 if [ ! -z "$4" ]; then
63 # Time to wait for loading
65 # What drive of the autochanger should be used primary
66 # At the moment bacula (1.31a) could not deal with more than one drive
72 echo "The $me script for bacula"
73 echo "--------------------------------------"
75 echo "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
77 echo "Valid commands:"
79 echo "unload Unloads a tape into the slot"
80 echo " from where it was loaded."
81 echo "load <slot> Loads a tape from the slot <slot>"
82 echo " (slot-base is calculated to 1 as first slot)"
83 echo "list Lists full storage slots"
84 echo "loaded Gives slot from where the tape was loaded."
85 echo " 0 means the tape drive is empty."
86 echo "slots Gives Number of aviable slots."
89 echo " mtx-changer /dev/changer load 1 loads a tape from slot 1"
97 # enable the following line if you need to eject the cartridge
100 # If the changer is power cycled with a tape loaded in a drive
101 if [ `${fullpath_me} ${CHANGER} loaded` -gt 0 ]; then
102 free_slot=`${fullpath_me} ${CHANGER} loaded`
103 free_slot=`expr $free_slot - 1`
104 ${MTX} -f ${CHANGER} move drive ${DRIVE} slot $free_slot
109 ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
111 # Increase the sleep time if you have a slow device
117 if [ "${SIMULATE_BARCODE}" = "true" ]; then
118 if [ -f "$BARCODE_FILE" ]; then
119 cat $BARCODE_FILE | grep -v "^#"
122 echo "Barcode file $BARCODE_FILE missing ... exiting!"
126 ${MTX} -f ${CHANGER} status | grep "^slot .*: .*FULL>" | awk '{print $2}' | awk -F: '{print $1+1" "}' | tr -d "[\r\n]"
131 # echo "Request loaded"
132 ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
134 cat /tmp/mtx.$$ | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
135 drive=`cat /tmp/mtx.$$ | grep "^drive .: <ACCESS>"`
136 if [ -n "$drive" ]; then
144 # echo "Request slots"
145 ${MTX} -f ${CHANGER} status | grep "^slot " | tail -1 | awk '{print $2+1}' | tr -d ":"