]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/de/concepts/mtx-changer.txt
Tweak downloads report
[bacula/docs] / docs / manuals / de / concepts / mtx-changer.txt
1 #!/bin/sh
2 #
3 # Bacula interface to mtx autoloader
4 #
5 #   Created  OCT/31/03 by Alexander Kuehn, derived from Ludwig Jaffe's script
6 #
7 #  Works with the HP C1537A L708 DDS3
8 #
9 #set -x
10 # these are the labels of the tapes in each virtual slot, not the slots!
11 labels="PSE-0001 PSE-0002 PSE-0003 PSE-0004 PSE-0005 PSE-0006 PSE-0007 PSE-0008 PSE-0009 PSE-0010 PSE-0011 PSE-0012"
12
13 # who to send a mail to?
14 recipient=root@localhost
15 logfile=/var/log/mtx.log
16
17 # Delay in seconds how often to check whether a new tape has been inserted
18 TAPEDELAY=10    # the default is every 10 seconds
19 echo `date` ":" $@ >>$logfile
20
21 # change this if mt is not in the path (use different quotes!)
22 mt=`which mt`
23 grep=`which grep`
24 #
25 # how to run the console application?
26 console="/usr/local/sbin/console -c /usr/local/etc/console.conf"
27
28 command="$1"
29
30 #TAPEDRIVE0 holds the device/name of your 1st and only drive (Bacula supports only 1 drive currently)
31 #Read TAPEDRIVE from command line parameters
32 if [ -z "$2" ] ; then
33   TAPEDRIVE0=/dev/nsa0 
34 else
35   TAPEDRIVE0=$2 
36 fi
37
38 #Read slot from command line parameters
39 if [ -z "$3" ] ; then
40   slot=`expr 1`
41 else
42   slot=`expr $3`
43 fi
44
45 if [ -z "$command" ] ; then
46   echo ""
47   echo "The mtx-changer script for Bacula"
48   echo "---------------------------------"
49   echo ""
50   echo "usage: mtx-changer <command> <devicename of tapedrive> [slot]"
51   echo "       mtx-changer"
52   echo ""
53   echo "Valid commands:"
54   echo ""
55   echo "unload          Unloads a tape into the slot"
56   echo "                from where it was loaded."
57   echo "load <slot>     Loads a tape from the slot <slot>"
58   echo "list            Lists full storage slots"
59   echo "loaded          Gives slot from where the tape was loaded."
60   echo "                0 means the tape drive is empty."
61   echo "slots           Gives Number of avialable slots." 
62   echo "volumes         List avialable slots and the label of the." 
63   echo "                tape in it (slot:volume)"
64   echo "Example:"
65   echo "  mtx-changer load /dev/nst0 1   loads a tape from slot1"
66   echo "  mtx-changer %a %o %S   "
67   echo ""
68   exit 0
69 fi
70
71
72 case "$command" in 
73         unload)
74                 # At first do mt -f /dev/st0 offline to unload the tape 
75                 #
76                 # Check if you want to fool me
77                 echo "unmount"|$console >/dev/null 2>/dev/null
78                 echo "mtx-changer: Checking if drive is loaded before we unload. Request unload" >>$logfile
79                 if $mt -f $TAPEDRIVE0 status >/dev/null 2>/dev/null ; then              # mt says status ok
80                         echo "mtx-changer: Doing mt -f $TAPEDRIVE0 rewoffl to rewind and unload the tape!" >>$logfile
81                         $mt -f $TAPEDRIVE0 rewoffl
82                 else
83                         echo "mtx-changer:  *** Don't fool me! *** The Drive $TAPEDRIVE0 is empty." >>$logfile
84                 fi
85                 exit 0
86                 ;;
87         
88    load)
89                 #Let's check if drive is loaded before we load it
90                 echo "mtx-changer: Checking if drive is loaded before we load. I Request loaded" >>$logfile
91                 LOADEDVOL=`echo "status Storage"|$console|$grep $TAPEDRIVE0|grep ^Device|grep -v "not open."|grep -v "ERR="|grep -v "no Bacula volume is mounted"|sed -e s/^.*Volume\ //|cut -d\" -f2`
92 #               if [ -z "$LOADEDVOL" ] ; then   # this is wrong, becaus Bacula would try to use the tape if we mount it!
93 #                       LOADEDVOL=`echo "mount"|$console|$grep $TAPEDRIVE0|grep Device|grep -v "not open."|grep -v "ERR="|sed -e s/^.*Volume\ //|cut -d\" -f2`
94 #                       if [ -z "$LOADEDVOL" ] ; then 
95 #                               echo "mtx-changer: The Drive $TAPEDRIVE0 is empty." >>$logfile
96 #                       else                                                    # restore state?
97 #                               if [ $LOADEDVOL = $3 ] ; then           # requested Volume mounted -> exit
98 #                                       echo "mtx-changer: *** Don't fool me! *** Tape $LOADEDVOL is already in drive $TAPEDRIVE0!" >>$logfile
99 #                                       exit
100 #                               else                                    # oops, wrong volume
101 #                                       echo "unmount"|$console >/dev/null 2>/dev/null
102 #                               fi
103 #                       fi
104 #               fi
105                 if [ -z "$LOADEDVOL" ] ; then
106                         echo "unmount"|$console >/dev/null 2>/dev/null
107                         LOADEDVOL=0
108                 else
109                         #Check if you want to fool me
110                         if [ $LOADEDVOL = $3 ] ; then 
111                                 echo "mtx-changer: *** Don't fool me! *** Tape $LOADEDVOL is already in drive $TAPEDRIVE0!" >>$logfile
112                                 exit
113                         fi
114                         echo "mtx-changer: The Drive $TAPEDRIVE0 is loaded with the tape $LOADEDVOL" >>$logfile
115                         echo "mtx-changer: Unmounting..." >>$logfile
116                         echo "unmount"|$console >/dev/null 2>/dev/null
117                 fi
118                 echo "mtx-changer: Unloading..." >>$logfile
119                 echo "mtx-changer: Doing mt -f $TAPEDRIVE0 rewoffl to rewind and unload the tape!" >>$logfile
120                 mt -f $TAPEDRIVE0 rewoffl 2>/dev/null
121                 #Now we can load the drive as desired 
122                 echo "mtx-changer: Doing mtx -f $1 $2 $3" >>$logfile
123                 # extract label for the mail
124                 count=`expr 1`
125                 for label in $labels ; do
126                         if [ $slot -eq $count ] ; then volume=$label ; fi
127                         count=`expr $count + 1`
128                 done
129
130                 mail -s "Bacula needs volume $volume." $recipient <<END_OF_DATA
131 Please insert volume $volume from slot $slot into $TAPEDRIVE0 .
132 Kind regards,
133 Bacula.
134 END_OF_DATA
135                 sleep 15
136                 $mt status >/dev/null 2>/dev/null
137                 while [ $? -ne 0 ] ; do
138                         sleep $TAPEDELAY
139                         $mt status >/dev/null 2>/dev/null
140                 done
141                 mail -s "Bacula says thank you." $recipient <<END_OF_DATA
142 Thank you for inserting the new tape! (I requested volume $volume from slot $slot.)
143 Kind regards,
144 Bacula.
145 END_OF_DATA
146                 echo "Successfully loaded a tape into drive $TAPEDRIVE0 (requested $volume from slot $slot)." >>$logfile
147                 echo "Loading finished." ; >>$logfile
148                 echo "$slot"
149                 exit 0
150                 ;;
151
152         list) 
153                 echo "mtx-changer: Requested list" >>$logfile
154                 LOADEDVOL=`echo "status Storage"|$console|$grep $TAPEDRIVE0|grep ^Device|grep -v "not open."|grep -v "ERR="|grep -v "no Bacula volume is mounted"|sed -e s/^.*Volume\ //|cut -d\" -f2`
155                 if [ -z $LOADEDVOL ] ; then             # try mounting
156                         LOADEDVOL=`echo "mount"|$console|$grep $TAPEDRIVE0|grep Device|grep -v "not open."|grep -v "ERR="|sed -e s/^.*Volume\ //|cut -d\" -f2`
157                         if [ -z $LOADEDVOL ] ; then             # no luck
158                                 LOADEDVOL="_no_tape"
159                         else                                                    # restore state
160                                 echo "unmount"|$console >/dev/null 2>/dev/null
161                         fi
162                 fi
163                 count=`expr 1`
164                 for label in $labels ; do
165                         if [ "$label" != "$LOADEDVOL" ] ; then
166                                 printf "$count "
167                         fi
168                         count=`expr $count + 1`
169                 done
170                 printf "\n"
171       ;;
172
173    loaded)
174                 echo "mtx-changer: Request loaded, dev $TAPEDRIVE0" >>$logfile
175                 LOADEDVOL=`echo "status Storage"|$console|$grep $TAPEDRIVE0|grep ^Device|grep -v "not open."|grep -v "ERR="|grep -v "no Bacula volume is mounted"|sed -e s/^.*Volume\ //|cut -d\" -f2`
176                 if [ -z $LOADEDVOL ] ; then
177                         LOADEDVOL=`echo "mount"|$console|$grep $TAPEDRIVE0|grep Device|grep -v "not open."|grep -v "ERR="|grep -v "no Bacula volume is mounted"|sed -e s/^.*Volume\ //|cut -d\" -f2`
178                         if [ -z "$LOADEDVOL" ] ; then           # no luck
179                                 echo "$TAPEDRIVE0 not mounted!" >>$logfile
180                         else                                                    # restore state
181                                 echo "unmount"|$console >/dev/null 2>/dev/null
182                         fi
183                 fi
184                 if [ -z "$LOADEDVOL" ] ; then 
185                         LOADEDVOL="_no_tape" >>$logfile
186                         echo "0"
187                 else
188                         count=`expr 1`
189                         for label in $labels ; do
190                                 if [ $LOADEDVOL = $label ] ; then echo $count ; fi
191                                 count=`expr $count + 1`
192                         done
193                 fi
194                 exit 0
195                 ;;
196
197    slots)
198                 echo "mtx-changer: Request slots" >>$logfile
199                 count=`expr 0`
200                 for label in $labels ; do
201                         count=`expr $count + 1`
202                 done
203                 echo $count
204       ;;
205
206    volumes)
207                 echo "mtx-changer: Request volumes" >>$logfile
208                 count=`expr 1`
209                 for label in $labels ; do
210                         printf "$count:$label "
211                         count=`expr $count + 1`
212                 done
213                 printf "\n"
214       ;;
215 esac