Debian Codegraph @

examples/autochangers/chio-bacula

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 #
3 # Bacula interface to mtx autoloader
4 # (By Lars Koeller, [email protected])
5 #
6 # If you set in your Device resource
7 #
8 # Changer Command = "path-to-this-script/chio-bacula %c %o %S %a"
9 # you will have the following input to this script:
10 #
11 # chio-bacula "changer-device" "command" "slot" "archive-device"
12 #
13 # for example:
14 #
15 # chio-bacula /dev/sg0 load 1 /dev/nst0 (on a FreeBSD system)
16 #
17 # If you need to to an offline, refer to the drive as $4
18 # e.g. mt -f $f offline
19 #
20 # Many changers need an offline after the unload. Also many
21 # changers need a sleep 60 after the mtx load.
22 #
23 # N.B. If you change the script, take care to return either
24 # the mtx exit code or a 0. If the script exits with a non-zero
25 # exit code, Bacula will assume the request failed.
26 #
27
28 # This simulates a barcode reader in the changer.
29 # The labels of the virtual barcode reader are located in the BARCODE_FILE
30 SIMULATE_BARCODE=true
31 BARCODE_FILE=/usr/local/etc/bacula-barcodesscip-shell filesystem . . `/usr/local/etc/bacula-barcodes`.
32 TMPDIR=/tmpscip-shell filesystem . . `/tmp`.
33
34 make_temp_filescip-shell shell bacula 15.0.3-5 make_temp_file().()
35 {
36 TMPFILE=`mktempscip-shell system . . mktemp. ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/nullscip-shell filesystem . . `/dev/null`.`
37 if testscip-shell system . . test. $? -ne 0 || testscip-shell system . . test. x${TMPFILE} = x; then
38 TMPFILE="${TMPDIR}/mtx$1.$$"
39 if testscip-shell system . . test. -f ${TMPFILE}; then
40 echoscip-shell system . . echo. "ERROR: Temp file security problem on: ${TMPFILE}"
41 exit 1
42 fi
43 fi
44 }
45
46 me=$(basenamescip-shell system . . basename. $0)
47
48 # Debug
49 echoscip-shell system . . echo. "$me $@" > /dev/consolescip-shell filesystem . . `/dev/console`.
50
51 if [scip-shell system . . `[`. -z "$1" ] ; then
52 usagescip-shell shell bacula 15.0.3-5 usage().;
53 fi
54
55 if [scip-shell system . . `[`. -z "$2" ] ; then
56 usagescip-shell shell bacula 15.0.3-5 usage().;
57 fi
58
59 MTX=/bin/chioscip-shell filesystem . . `/bin/chio`.
60 CHANGER=$1
61 COMMAND=$2
62 if [scip-shell system . . `[`. ! -z "$3" ]; then
63 SLOT=$3
64 fi
65 if [scip-shell system . . `[`. ! -z "$4" ]; then
66 TAPE=$4
67 else
68 TAPE=/dev/nrsa2scip-shell filesystem . . `/dev/nrsa2`.
69 fi
70
71 # Time to wait for loading
72 SLEEP=20
73 # What drive of the autochanger should be used primary
74 # At the moment bacula (1.31a) could not deal with more drives
75 DRIVE=1
76
77 usagescip-shell shell bacula 15.0.3-5 usage().()
78 {
79 echoscip-shell system . . echo. ""
80 echoscip-shell system . . echo. "The $me script for bacula"
81 echoscip-shell system . . echo. "--------------------------------------"
82 echoscip-shell system . . echo. ""
83 echoscip-shell system . . echo. "usage: $me <changer-device> <command> [slot] [devicename of tapedrive]"
84 echoscip-shell system . . echo. ""
85 echoscip-shell system . . echo. "Valid commands:"
86 echoscip-shell system . . echo. ""
87 echoscip-shell system . . echo. "unload Unloads a tape into the slot"
88 echoscip-shell system . . echo. " from where it was loaded."
89 echoscip-shell system . . echo. "load <slot> Loads a tape from the slot <slot>"
90 echoscip-shell system . . echo. " (slot-base is calculated to 1 as first slot)"
91 echoscip-shell system . . echo. "list Lists full storage slots"
92 echoscip-shell system . . echo. "loaded Gives slot from where the tape was loaded."
93 echoscip-shell system . . echo. " 0 means the tape drive is empty."
94 echoscip-shell system . . echo. "slots Gives Number of available slots."
95 echoscip-shell system . . echo. ""
96 echoscip-shell system . . echo. "Example:"
97 echoscip-shell system . . echo. " mtx-changer /dev/changer load 1 loads a tape from slot 1"
98 echoscip-shell system . . echo. ""
99 exit 2
100 }
101
102
103 case ${COMMAND} in
104 unload)
105 # enable the following line if you need to eject the cartridge
106 #mt -f ${TAPE} off
107 #sleep 2
108 ${MTX} -f ${CHANGER} return drive ${DRIVE}
109 ;;
110
111 load)
112 ${MTX} -f ${CHANGER} move slot $((${SLOT}-1)) drive ${DRIVE}
113 rtn=$?
114 # Increase the sleep time if you have a slow device
115 sleepscip-shell system . . sleep. $SLEEP
116 exit $rtn
117 ;;
118
119 list)
120 if [scip-shell system . . `[`. "${SIMULATE_BARCODE}" = "true" ]; then
121 if [scip-shell system . . `[`. -f "$BARCODE_FILE" ]; then
122 catscip-shell system . . cat. $BARCODE_FILE | grepscip-shell system . . grep. -v "^#"
123 exit 0
124 else
125 echoscip-shell system . . echo. "Barcode file $BARCODE_FILE missing ... exiting!"
126 exit 1
127 fi
128 else
129 ${MTX} -f ${CHANGER} status | grepscip-shell system . . grep. "^slot .*: .*FULL>" | awkscip-shell system . . awk. '{print $2}' | awkscip-shell system . . awk. -F: '{print $1+1" "}' | trscip-shell system . . tr. -d "[\r\n]"
130 fi
131 ;;
132
133 loaded)
134 # echo "Request loaded"
135 make_temp_filescip-shell shell bacula 15.0.3-5 make_temp_file().
136 ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
137 rtn=$?
138 catscip-shell system . . cat. ${TMPFILE} | grepscip-shell system . . grep. "^drive ${DRIVE}: <FULL>" | awkscip-shell system . . awk. '{print $6+1}' | trscip-shell system . . tr. -d ">"
139 catscip-shell system . . cat. ${TMPFILE} | grepscip-shell system . . grep. "^drive ${DRIVE}: source: <>" | awkscip-shell system . . awk. "{print 0}"
140 rmscip-shell system . . rm. -f ${TMPFILE}
141 exit $rtn
142 ;;
143
144 slots)
145 # echo "Request slots"
146 ${MTX} -f ${CHANGER} status | grepscip-shell system . . grep. "^slot " | tailscip-shell system . . tail. -1 | awkscip-shell system . . awk. '{print $2+1}' | trscip-shell system . . tr. -d ":"
147 ;;
148
149 *)
150 usagescip-shell shell bacula 15.0.3-5 usage().
151 ;;
152 esac