]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/mtx-changer.in
Fix sql path length=0 bug
[bacula/bacula] / bacula / scripts / mtx-changer.in
1 #!/bin/sh
2 #
3 # Bacula interface to mtx autoloader
4 #
5 #  $Id$
6 #
7 #  If you set in your Device resource
8 #
9 #  Changer Command = "path-to-this-script/mtx-changer" %c %o %S %a %d
10 #    you will have the following input to this script:
11 #
12 #  mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
13 #
14 #  for example:
15 #
16 #  mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
17 #
18 #  If you need to an offline, refer to the drive as $4
19 #    e.g.   mt -f $4 offline
20 #
21 #  Many changers need an offline after the unload. Also many
22 #   changers need a sleep 60 after the mtx load.
23 #
24 #  N.B. If you change the script, take care to return either 
25 #   the mtx exit code or a 0. If the script exits with a non-zero
26 #   exit code, Bacula will assume the request failed.
27 #
28
29 MTX=@MTX@
30
31 case "$2" in 
32    unload)
33 #     echo "Doing mtx -f $1 unload $3 $5"
34 #
35 # enable the following line if you need to eject the cartridge
36 #     mt -f $4 offline
37       ${MTX} -f $1 unload $3 $5
38       ;;
39
40    load)
41 #     echo "Doing mtx -f $1 load $3 $5"
42       ${MTX} -f $1 load $3 $5
43       rtn=$?
44 #
45 # Increase the sleep time if you have a slow device
46       sleep 15
47       exit $rtn
48       ;;
49
50    list) 
51 #     echo "Requested list"
52       ${MTX} -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
53       ;;
54
55    loaded)
56       ${MTX} -f $1 status >/tmp/mtx.$$
57       rtn=$?
58       cat /tmp/mtx.$$ | grep "^Data Transfer Element $5:Full" | awk "{print \$7}"
59       cat /tmp/mtx.$$ | grep "^Data Transfer Element $5:Empty" | awk "{print 0}"
60       rm -f /tmp/mtx.$$
61       exit $rtn
62       ;;
63
64    slots)
65 #     echo "Request slots"
66       ${MTX} -f $1 status | grep " *Storage Changer" | awk "{print \$5}"
67       ;;
68 esac