]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/autochangers/mtx-changer.Adic-Scalar-24
Fix bug #1812 cannot run Copy/Migrate jobs from bat
[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 TMPDIR=/tmp
33
34 make_temp_file() 
35 {
36   TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
37   if test $? -ne 0 || test x${TMPFILE} = x; then
38      TMPFILE="${TMPDIR}/mtx$1.$$"
39      if test -f ${TMPFILE}; then
40         echo "ERROR: Temp file security problem on: ${TMPFILE}"
41         exit 1
42      fi
43   fi
44 }
45
46
47 if test $# -lt 2 ; then
48   echo "usage: mtx-changer ctl-device command slot archive-device drive"
49   echo "  Insufficient number of arguments arguments given."
50   echo "  Mimimum usage is first two arguments ..."
51   exit 1
52 fi
53
54 # Setup arguments
55 ctl=$1
56 cmd="$2"
57 slot=$3
58 device=$4
59 # If drive not given, default to 0
60 if test $# = 5 ; then
61   drive=$5
62 else
63   drive=0
64 fi
65
66 ${MTX} -f $1 inventory
67
68 #
69 # Check for special cases where only 2 arguments are needed,
70 #  all others are a minimum of 3
71 case $cmd in
72    loaded)
73      ;;
74    unload)
75      ;;
76    list)
77      ;;
78    slots)
79      ;;
80    *)
81      if test $# -lt 3; then
82         echo "usage: mtx-changer ctl-device command slot archive-device drive"
83         echo "  Insufficient number of arguments arguments given."
84         echo "  Mimimum usage is first three arguments ..."
85         exit 1
86      fi
87      ;;
88 esac
89
90
91 case $cmd in
92    unload)
93 #     echo "Doing mtx -f $ctl unload $slot $drive"
94 #
95 # enable the following line if you need to eject the cartridge
96 #     mt -f $device offline
97       if test x$slot = x; then
98          ${MTX} -f $ctl unload
99       else
100          ${MTX} -f $ctl unload $slot $drive
101       fi
102       ;;
103
104    load)
105 #     echo "Doing mtx -f $ctl load $slot $drive"
106       ${MTX} -f $ctl load $slot $drive
107       rtn=$?
108 #
109 # Increase the sleep time if you have a slow device
110       sleep 15
111       exit $rtn
112       ;;
113
114    list)
115 #     echo "Requested list"
116       ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk '{print $3 $4}' | sed "s/Full *\(:VolumeTag=\)*//"
117       ;;
118
119    loaded)
120       make_temp_file
121       ${MTX} -f $ctl status > ${TMPFILE}
122       rtn=$?
123       cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full"  | awk '{print $7}'
124       cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
125       rm -f ${TMPFILE}
126       exit $rtn
127       ;;
128
129    slots)
130 #     echo "Request slots"
131       ${MTX} -f $ctl status | grep " *Storage Changer" | awk '{print $5}'
132       ;;
133 esac