3 # Bacula interface to chio(1) autoloader for OpenBSD
5 # Adapted from NetBSD pkgsrc and examples/autochangers in bacula source)
6 # by Antoine Jacoutot <ajacoutot@openbsd.org> for OpenBSD.
7 # Tested on an LTO-4 device with 1 drive and 8 slots.
8 # The user Bacula is running as needs rw access to the ch(4) and st(4)
11 # If you set in your Device resource:
12 # Changer Command = "/path/to/chio-changer-openbsd %c %o %S %a %d"
13 # you will have the following input to this script:
14 # chio-changer-openbsd "changer-device" "command" "slot" "archive-device" "drive-index"
17 # So Bacula will always call with all the following arguments, even though
18 # in come cases, not all are used.
20 # N.B. If you change the script, take care to return either
21 # the chio exit code or a 0. If the script exits with a non-zero
22 # exit code, Bacula will assume the request failed.
24 # time (in seconds) for the unit to settle after (un)loading a tape
30 echo "usage: ${0##*/} ctl-device command [slot archive-device drive-index]"
33 # check parameters count
37 if test ${pCount} -lt ${pCountNeed}; then
39 echo "!!! insufficient number of arguments given"
41 if test ${pCount} -lt 2; then
43 echo "!!! mimimum usage is the first two arguments"
47 echo "!!! command expected ${pCountNeed} arguments"
55 # check arguments count for specific actions
81 ${CHIO} -f ${ctl} move drive ${drive} slot $((${slot} - 1))
83 [ ${rtn} -eq 0 ] && sleep ${SLEEP}
87 ${CHIO} -f ${ctl} move slot $((${slot} - 1)) drive ${drive}
89 [ ${rtn} -eq 0 ] && sleep ${SLEEP}
93 ${CHIO} -f ${ctl} status -v slot | \
94 sed -ne 's/^slot *\([0-9]*:\).*FULL.*voltag.*<\(.*\):.*/\1\2/p' | \
95 awk -F: '{ print $1 + 1 ":" $2 }'
99 # XXX only one drive is queried
100 _list=$(${0} ${1} list)
101 _loaded_s=$(${0} ${1} loaded ${slot} ${device} ${drive})
102 _loaded_t=$(${CHIO} -f ${ctl} status -v | grep "drive ${drive}" | awk '{ print $NF }' | sed -e 's,<,,' -e 's,:.*,,')
104 [ -n "${_list}" -a -n "${_loaded_s}" -a -n "${_loaded_t}" ] || exit 1
106 (for i in ${_list}; do
107 echo "S:${i}" | sed 's/\(.*\):/\1:F:/'
109 echo S:${_loaded_s}:E
110 if [ "${_loaded_s}" -ne 0 ]; then
111 echo D:${drive}:F:${_loaded_s}:${_loaded_t}
117 # XXX output the first empty slot if the drive is loaded
118 _slot=$(${CHIO} -f ${ctl} status -v | egrep '^slot.*<ACCESS> voltag: <:[0-9]>$' | awk '{ print $2 }' | awk -F: '{ print $1 + 1 }')
120 _loaded=$(${CHIO} -f ${ctl} status -v | egrep "^drive ${drive}: <ACCESS,FULL> voltag: <.*:[0-9]>")
121 [ -z "${_slot}" -o -z "${_loaded}" ] && _slot=0
122 echo ${_slot} | awk '{ print $1 }'
126 ${CHIO} -f ${ctl} params | awk "/slots/{print \$2}"
131 ${CHIO} -f ${ctl} move slot $((${slot} - 1)) slot ${slotdest}