3 # Bacula interface to autoloader
5 # By Pascal Pederiva <freebsd@paped.com>
7 # Known to work on FreeBSD 5.2 with a TZ875 changer.
9 # This script mimics mtx-changer with the following differences
10 # - it automatically stows the cartridge to the slot it came from when
12 # - a load will automatically unload the drive if there is a
13 different cartridge loaded.
14 # - it uses chio instead of mtx (which is
15 available as a package)
17 # If you set in your Device resource
19 # Changer Command = "path-to-this-script/chio-changer" %c %o %S %a
20 # you will have the following input to this script:
22 # chio-changer "changer-device" "command" "slot" "archive-device"
26 # chio-changer /dev/sg0 load 1 /dev/nst0 (on a Linux system)
28 # If you need to to an offline, refer to the drive as $4
29 # e.g. mt -f $4 offline
31 # Many changers need an offline after the unload. Also many
32 # changers need a sleep 60 after the chio load.
34 # N.B. If you change the script, take care to return either
35 # the chio exit code or a 0. If the script exits with a non-zero
36 # exit code, Bacula will assume the request failed.
39 # chio-changer load 1 ; load slot 1 into drive 0 (and unload old cartridge if necessary)
40 # chio-changer unload N ; unload drive into source slot (slot number is ignored)
41 # chio-changer loaded N ; Return loaded slot #
42 # chio-changer /dev/ch0 loaded N /dev/nsa0 ; has the same effect
45 #echo `date` "chio: $*" >>/tmp/changer
47 # If the first parameter is not a device, assume it is a command
48 # and you want to use the default changer
63 ##############################################################################
68 # enable the following line if you need to eject the cartridge
69 # mt -f $DRIVE offline
70 SOURCE=`${MTX} status -S | grep drive | grep FULL | cut -d: -f 3 | tr -d '<>a-z '`
71 if [ ! -z "$SOURCE" ]; then
72 echo -n "Unloading Data Transfer Element into Storage Element $ELEMENT..."
73 ${MTX} -f $CHANGER move drive 0 slot $SOURCE
77 echo "Storage Element $ELEMENT is Already Full"
83 if [ -z "$ELEMENT" ]; then
84 echo "ERROR: load <element> reguired"
88 if [ $TARGET -le 0 ]; then
91 TARGET=`expr $TARGET - 1`
93 SOURCE=`${MTX} status -S | grep drive | grep FULL | cut -d: -f 3 | tr -d '<>a-z '`
94 if [ ! -z "$SOURCE" ]; then
95 if [ "$SOURCE" != "$TARGET" ]; then
96 # Only unload if there is something different in the drive
97 ${MTX} -f $CHANGER move drive 0 slot $SOURCE
101 if [ "$SOURCE" != "$TARGET" ]; then
102 ${MTX} -f $CHANGER move slot $TARGET drive 0
109 ${MTX} -f $CHANGER status slot | grep "FULL" | awk '{print $2+1":"}'
113 SOURCE=`${MTX} status -S | grep drive | grep FULL | cut -d: -f 3 | tr -d '<>a-z '`
115 if [ -z "$SOURCE" ]; then
118 echo `expr 1 + ${SOURCE}`
123 ${MTX} -f $CHANGER status slot | wc -l