]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/mtx-changer.in
c5d202cc34371904660a4951fcdaf2ede40638ae
[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 #                  $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=@MTX@
31
32 case "$2" in 
33    unload)
34 #     echo "Doing mtx -f $1 unload $3 $5"
35 #
36 # enable the following line if you need to eject the cartridge
37 #     mt -f $4 offline
38       ${MTX} -f $1 unload $3 $5
39       ;;
40
41    load)
42 #     echo "Doing mtx -f $1 load $3 $5"
43       ${MTX} -f $1 load $3 $5
44       rtn=$?
45 #
46 # Increase the sleep time if you have a slow device
47       sleep 15
48       exit $rtn
49       ;;
50
51    list) 
52 #     echo "Requested list"
53       ${MTX} -f $1 status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
54       ;;
55
56    loaded)
57       ${MTX} -f $1 status >/tmp/mtx.$$
58       rtn=$?
59       cat /tmp/mtx.$$ | grep "^Data Transfer Element $5:Full" | awk "{print \$7}"
60       cat /tmp/mtx.$$ | grep "^Data Transfer Element $5:Empty" | awk "{print 0}"
61       rm -f /tmp/mtx.$$
62       exit $rtn
63       ;;
64
65    slots)
66 #     echo "Request slots"
67       ${MTX} -f $1 status | grep " *Storage Changer" | awk "{print \$5}"
68       ;;
69 esac