]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/autochangers/chio-changer.Sony-TSL-SA300C
Tweak TRU64 xattr code.
[bacula/bacula] / bacula / examples / autochangers / chio-changer.Sony-TSL-SA300C
1 #!/bin/sh
2 #
3 # Bacula interface to mtx autoloader
4 # (By Lars Köller, lars+bacula@koellers.net)
5 #
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.
9 #
10 #  If you set in your Device resource
11 #
12 #  Changer Command = "path-to-this-script/chio-bacula %c %o %S %a"
13 #    you will have the following input to this script:
14 #
15 #  chio-bacula "changer-device" "command" "slot" "archive-device"
16 #
17 #  for example:
18 #
19 #  chio-bacula /dev/ch0 load 1 /dev/nst0 (on a FreeBSD system)
20 #
21 #  If you need to to an offline, refer to the drive as $4
22 #    e.g.   mt -f $f offline
23 #
24 #  Many changers need an offline after the unload. Also many
25 #   changers need a sleep 60 after the mtx load.
26 #
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.
30 #
31
32 # This simulates a barcode reader in the changer.
33 # The labels of the virtual barcode reader are located in the BARCODE_FILE
34 SIMULATE_BARCODE=true
35 BARCODE_FILE=/usr/local/etc/bacula-barcodes
36
37 me=$(basename $0)
38 fullpath_me=$0
39
40 # Debug
41 logger -p user.err "$fullpath_me $@"
42
43 if [ -z "$1" ] ; then
44     usage;
45 fi
46
47 if [ -z "$2" ] ; then
48     usage;
49 fi
50
51 MTX=/bin/chio
52 CHANGER=$1
53 COMMAND=$2
54 if [ ! -z "$3" ]; then
55     SLOT=$3
56 fi
57 if [ ! -z "$4" ]; then
58     TAPE=$4
59 else
60     TAPE=/dev/nrsa1
61 fi
62
63 # Time to wait for loading
64 SLEEP=20
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
67 DRIVE=0
68
69 usage()
70 {
71   echo ""
72   echo "The $me script for bacula"
73   echo "--------------------------------------"
74   echo ""
75   echo "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
76   echo ""
77   echo "Valid commands:"
78   echo ""
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."
87   echo ""
88   echo "Example:"
89   echo "  mtx-changer /dev/changer load 1   loads a tape from slot 1"
90   echo ""
91   exit 2
92 }
93
94
95 case ${COMMAND} in
96     unload)
97         # enable the following line if you need to eject the cartridge
98         #mt -f ${TAPE} off
99         #sleep 2
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
105         fi
106         ;;
107
108     load)
109         ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
110         rtn=$?
111         # Increase the sleep time if you have a slow device
112         sleep $SLEEP
113         exit $rtn
114         ;;
115
116     list)
117         if [ "${SIMULATE_BARCODE}" = "true" ]; then
118             if [ -f "$BARCODE_FILE" ]; then
119                 cat $BARCODE_FILE | grep -v "^#"
120                 exit 0
121             else
122                 echo "Barcode file $BARCODE_FILE missing ... exiting!"
123                 exit 1
124             fi
125         else
126             ${MTX} -f ${CHANGER} status | grep "^slot .*: .*FULL>" | awk '{print $2}' | awk -F: '{print $1+1" "}' | tr -d "[\r\n]"
127         fi
128       ;;
129
130     loaded)
131         # echo "Request loaded"
132         ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
133         rtn=$?
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
137                 echo 0
138         fi
139         rm -f /tmp/mtx.$$
140         exit $rtn
141         ;;
142
143     slots)
144         # echo "Request slots"
145         ${MTX} -f ${CHANGER} status | grep "^slot " | tail -1 | awk '{print $2+1}' | tr -d ":"
146       ;;
147
148     *)
149         usage
150       ;;
151 esac