]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/autochangers/multiple-drive-changer.txt
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / bacula / examples / autochangers / multiple-drive-changer.txt
1 Date: Tue, 15 Feb 2005 17:36:06 +0100
2 From: Mario Wolff <mwolff@unix.schubert-gruppe.de>
3 To: kern@sibbald.com
4 CC: bacula-devel <bacula-devel@lists.sourceforge.net>
5 Subject: Re: Using multiple tapedrives as autochanger!
6
7 Hi Kern!
8
9 Kern Sibbald schrieb:
10  > Hello,
11  >
12  > There is a similar script named ak-mtx-changer.txt in the
13  > <bacula>/examples/autochangers directory of the source tree. If you feel
14  > that your script brings something different, then I'll be happy to
15  > include it in the same directory. If that is the case, please put a
16  > small note in an email message to me with the script and I'll include it
17  > (I know you've already sent the script, but it saves me the time of
18  > searching for it, and I'm sure I've got the right one).
19  >
20  > Best regards, Kern
21
22 As far as i understood the ak-mtx-changer.txt it's simply a 
23 human-resource-changer!?!
24 In the past every single server had it's own DDS-3 Tape, since we switch 
25   to a centralized networkbackup all these drives are unused.
26 Now i took 6 of these drives and placed it in large case on one 
27 scsi-controller. Running bacula with multitape-changer these six drives 
28 are used as one drive with a 6-Slot-Changer!
29
30 Regards,
31 Mario
32
33 PS: I've posted a deploy-script (deploy windows-fd from linux, automated 
34   your hints) a few days ago over gmane to the devellist. This message 
35 was never posted and i got no error message. Maybe problem with the size 
36 (Windows-FD was attached!) ???
37
38 [pasted the hints once again for Kern!]
39
40 Example:
41 bacula-dir.conf:
42
43 # Definition of DDS tape storage device
44 Storage {
45    Name = Multitape
46    #Do not use "localhost" here
47    Address = mystorage    # N.B. Use a fully qualified name here
48    SDPort = 9103
49    Password = "strongsecret"       # password for Storage daemon
50    Device = Multitape
51    Autochanger = yes
52    Media Type = DDS-3
53 }
54
55 bacula-sd.conf:
56 Device {
57    Name = Multitape                        #
58    Media Type = DDS-3
59    Archive Device = /dev/tape
60    AutomaticMount = yes;               # when device opened, read it
61    AlwaysOpen = yes;
62    RemovableMedia = yes;
63    RandomAccess = no;
64    # That's the magic!!!
65    Changer Command = "/etc/bacula/scripts/multitape-changer %c %o %S %a %d"
66    Changer Device = /dev/null
67    AutoChanger = yes
68 }
69
70 Hints:
71 - Important to use a virtual name! multidrive-changer will create links! 
72   (Archive Device = /dev/tape)
73 - It's a bash script not a sh script!
74 - SD must run as root or the multitape-changer must be called with sudo 
75 to have write permission to the /dev dir!
76 - the default-config does an umount on tape-change! Don't switch this! 
77 SD has to release the device-file!
78 - don't use your tapedrives directly anymore! SD does not know that 
79 /dev/tape is /dev/nst0!
80 - don't remove the sleep 1 after getslot...! Without the sleep you will 
81 get a "Operation not permitted" error!
82 - only tested with Debian/GNU-Linux-SID
83
84 [end of paste]
85
86
87 --------------050209030507060501040304
88 Content-Type: text/plain;
89  name="multitape-changer"
90 Content-Transfer-Encoding: 7bit
91 Content-Disposition: inline;
92  filename="multitape-changer"
93
94 #!/bin/bash
95 #
96 # Bacula interface to use multiple drives as one tape-changer
97 # Arguments are copied from the mtx-script! Simply exchange 
98 # the scriptname from demo-config
99 #
100 #  If you set in your Device resource
101 #
102 #  Changer Command = "path-to-this-script/multitape-changer %c %o %S %a %d"
103 #    you will have the following input to this script:
104 #
105 #  multitape-changer "changer-device" "command" "slot" "archive-device" "drive-index"
106 #                  $1              $2       $3        $4               $5
107 #
108 #  for example:
109 #
110 #  multitape-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
111 #
112 # Setup arguments
113 cmd="$2"
114 slot=$3
115 DEVICE=${4:-/dev/tape}
116
117 LABELDIR=/etc/bacula/tapelabel # where to find labelfiles
118 NULLDEVICE=/dev/null           # if unmount link to this
119 SLOT01=/dev/nst0               # first slot
120 SLOT02=/dev/nst1               # second slot
121                                # simply append more
122
123 #get device for a given slotnumber
124 getdevice(){
125   myslot=${1:-1}
126   if [ ${#myslot} -gt 2 ];then exit 1;fi
127   if [ ${#myslot} -eq 2 ];then 
128     eval echo \$SLOT$myslot
129     return
130   else
131     eval echo \$SLOT0$myslot
132     return
133   fi
134 }
135
136 #get name of labelfile for a given slot
137 getname(){
138   myslot=${1:-1}
139   if [ ${#myslot} -gt 2 ];then exit 2;fi
140   if [ ${#myslot} -eq 2 ];then 
141     echo SLOT$myslot
142     return
143   else
144     echo SLOT0$myslot
145     return
146   fi
147 }
148
149 #how many tapes/slots to manage
150 getslots(){
151   count=1
152   while [ "$( getdevice $count )" ];do
153     count=$[ $count + 1 ]
154   done
155   echo $[ $count - 1 ]
156   return
157 }
158
159 #get slot for a given device-file
160 getslot(){
161   device=${1:-$NULLDEVICE}
162   if [ "$device" = "$NULLDEVICE" ];then
163     echo -en "0\n"
164     return
165   else
166     count=1
167     slotdev=$( getdevice $count )
168     while [ "$slotdev" ]; do 
169       if [ "$slotdev" = "$device" ];then
170         echo -en "$count\n"
171         return
172       fi
173       count=$[ $count + 1 ]
174       slotdev=$( getdevice $count )
175     done
176     exit 3
177   fi
178 }
179             
180 if test $# -lt 2 ; then
181   echo "usage: multitape-changer ctl-device command slot archive-device drive"
182   echo "  Insufficient number of arguments arguments given."
183   echo "  Mimimum usage is first two arguments ..."
184   exit 4
185 fi
186
187 #
188 # Check for special cases where only 2 arguments are needed, 
189 #  all others are a minimum of 3
190 case $cmd in
191    loaded)
192      ;;
193    unload)
194      ;;
195    list)
196      ;;
197    slots)
198      ;;
199    *)
200      if test $# -lt 3; then
201         echo "usage: multitape-changer ctl-device command slot archive-device drive"
202         echo "  Insufficient number of arguments arguments given."
203         echo "  Mimimum usage is first three arguments ..."
204         exit 5
205      fi
206      ;;
207 esac
208
209
210 case $cmd in 
211    unload)
212       if [ -e $DEVICE ];then
213         rm $DEVICE && ln -s $NULLDEVICE $DEVICE || exit 6
214       else
215         ln -s $NULLDEVICE $DEVICE || exit 7
216       fi
217       ;;
218
219    load)
220       CURDEV=$( getdevice $slot )
221       if [ -e $DEVICE ];then
222         rm $DEVICE && ln -s $CURDEV $DEVICE || exit 8
223       else
224         ln -s $CURDEV $DEVICE || exit 9
225       fi
226       ;;
227
228    list) 
229       slots=$( getslots )
230       for slot in $( seq 1 $slots );do
231         labelfile=$LABELDIR/$( getname $slot )
232         if [ -f "$labelfile" ];then
233           echo "$slot:$( head -n 1 $labelfile)"
234         else
235           echo "$slot:"
236         fi
237       done
238       exit 0
239       ;;
240
241    loaded)
242       if [ -e $DEVICE ];then
243         line=$( ls -la $DEVICE )
244       fi
245       line=${line:-$NULLDEVICE}
246       getslot ${line##* }
247       sleep 1
248       exit 0
249       ;;
250
251    slots)
252       getslots
253       exit 0
254       ;;
255 esac
256
257 --------------050209030507060501040304--