3 # Bacula interface to chio autoloader
4 # (by Rudolf Cejka <cejkar@fit.vutbr.cz>)
8 # If you set in your Device resource
9 # Changer Command = "path-to-this-script/chio-changer %c %o %S %a %d"
10 # you will have the following input to this script:
11 # chio-changer "changer-device" "command" "slot" "tape-device" "drive-index"
13 # for example (on a FreeBSD system):
14 # chio-changer /dev/ch0 load 1 /dev/nsa0 0
16 # If you change the script, take care to return either the chio exit
17 # code or a 0. If the script exits with a non-zero exit code, Bacula
18 # will assume the request failed.
21 # Uncomment the following line, if you need to eject a tape before moving
25 # Uncomment the following line, if you need to wait for some time
26 # (in seconds) after (un)loading a tape.
29 # Uncomment the following line, if you do not have a changer with volume
31 #FAKE_BARCODES=/usr/local/etc/bacula-barcodes
33 PROGNAME=`basename $0`
38 Usage: ${PROGNAME} <changer-device> <cmd> [slot] [tape-device] [drive-index]
41 unload Unloads a tape into the slot from where it was loaded.
42 load <slot> Loads a tape from the slot <slot> (1-based).
43 list Lists full storage slots.
44 loaded Gives slot from where the tape was loaded (0 = empty drive).
45 slots Gives number of available slots.
48 ${PROGNAME} /dev/ch0 load 1 Loads a tape from first slot 1.
80 if [ "${OFFLINE}" = yes ]; then
81 ${MT} -f ${TAPE} offline
83 if [ -n "${SLEEP}" ]; then
86 if [ -z "${SLOT}" ]; then
87 ${CHIO} -f ${CHANGER} return drive ${DRIVE}
89 ${CHIO} -f ${CHANGER} move drive ${DRIVE} slot $((${SLOT} - 1))
92 # Try to unload the cartridge to the first free slot.
93 FREE=`${CHIO} -f ${CHANGER} status slot | \
94 sed -ne '/FULL/d;s/^slot *\([0-9]*\):.*/\1/p' | head -1`
95 if [ -n "${FREE}" ]; then
96 ${CHIO} -f ${CHANGER} move drive ${DRIVE} slot ${FREE}
103 ${CHIO} -f ${CHANGER} move slot $((${SLOT} - 1)) drive ${DRIVE}
105 if [ -n "${SLEEP}" ]; then
111 if [ -z "${FAKE_BARCODES}" ]; then
112 ${CHIO} -f ${CHANGER} status -v slot | \
113 sed -ne 's/^slot *\([0-9]*:\).*FULL.*voltag.*<\(.*\):.*/\1\2/p' | \
114 awk -F: '{print $1 + 1 ":" $2 }'
116 if [ -f "${FAKE_BARCODES}" ]; then
117 grep -v -e "^#" -e "^$" < ${FAKE_BARCODES}
119 echo "${PROGNAME}: Barcode file ${FAKE_BARCODES} is missing"
125 FREE=`${CHIO} -f ${CHANGER} status slot | \
126 sed -ne '/FULL/d;s/^slot *\([0-9]*\):.*/\1/p' | \
127 awk 'BEGIN { n = 0 } { n = $1 + 1 ; exit } END { print n }'`
128 ${CHIO} -f ${CHANGER} status -S drive | \
129 sed -ne 's/^drive *'${DRIVE}':.*FULL.*source.*<[^0-9]*\([0-9]*\)>.*/\1/p' \
130 | awk 'BEGIN { n = 0 } { n = ($1 == "") ? '${FREE}' : $1 + 1 } \
134 ${CHIO} -f ${CHANGER} status | grep -c "^slot "