]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/autochangers/mtx-changer.Adic-Scalar-24
Apply patch from Felix Schwarz <Felix.Schwarz@web.de> that allows
[bacula/bacula] / bacula / examples / autochangers / mtx-changer.Adic-Scalar-24
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 #                  $1              $2       $3        $4               $5
14 #
15 #  for example:
16 #
17 #  mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
18 #
19 #  If you need to an offline, refer to the drive as $4
20 #    e.g.   mt -f $4 offline
21 #
22 #  Many changers need an offline after the unload. Also many
23 #   changers need a sleep 60 after the mtx load.
24 #
25 #  N.B. If you change the script, take care to return either
26 #   the mtx exit code or a 0. If the script exits with a non-zero
27 #   exit code, Bacula will assume the request failed.
28 #
29
30 MTX=/usr/sbin/mtx
31
32 if test $# -lt 2 ; then
33   echo "usage: mtx-changer ctl-device command slot archive-device drive"
34   echo "  Insufficient number of arguments arguments given."
35   echo "  Mimimum usage is first two arguments ..."
36   exit 1
37 fi
38
39 # Setup arguments
40 ctl=$1
41 cmd="$2"
42 slot=$3
43 device=$4
44 # If drive not given, default to 0
45 if test $# = 5 ; then
46   drive=$5
47 else
48   drive=0
49 fi
50
51 ${MTX} -f $1 inventory
52
53 #
54 # Check for special cases where only 2 arguments are needed,
55 #  all others are a minimum of 3
56 case $cmd in
57    loaded)
58      ;;
59    unload)
60      ;;
61    list)
62      ;;
63    slots)
64      ;;
65    *)
66      if test $# -lt 3; then
67         echo "usage: mtx-changer ctl-device command slot archive-device drive"
68         echo "  Insufficient number of arguments arguments given."
69         echo "  Mimimum usage is first three arguments ..."
70         exit 1
71      fi
72      ;;
73 esac
74
75
76 case $cmd in
77    unload)
78 #     echo "Doing mtx -f $ctl unload $slot $drive"
79 #
80 # enable the following line if you need to eject the cartridge
81 #     mt -f $device offline
82       if test x$slot = x; then
83          ${MTX} -f $ctl unload
84       else
85          ${MTX} -f $ctl unload $slot $drive
86       fi
87       ;;
88
89    load)
90 #     echo "Doing mtx -f $ctl load $slot $drive"
91       ${MTX} -f $ctl load $slot $drive
92       rtn=$?
93 #
94 # Increase the sleep time if you have a slow device
95       sleep 15
96       exit $rtn
97       ;;
98
99    list)
100 #     echo "Requested list"
101       ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk '{print $3 $4}' | sed "s/Full *\(:VolumeTag=\)*//"
102       ;;
103
104    loaded)
105       ${MTX} -f $ctl status >/tmp/mtx.$$
106       rtn=$?
107       cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk '{print $7}'
108       cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
109       rm -f /tmp/mtx.$$
110       exit $rtn
111       ;;
112
113    slots)
114 #     echo "Request slots"
115       ${MTX} -f $ctl status | grep " *Storage Changer" | awk '{print $5}'
116       ;;
117 esac