]> git.sur5r.net Git - bacula/docs/blob - docs/manual/autochangers.tex
Update
[bacula/docs] / docs / manual / autochangers.tex
1 %%
2 %%
3
4 \chapter{Autochanger Support}
5 \label{AutochangersChapter}
6 \index[general]{Support!Autochanger }
7 \index[general]{Autochanger Support }
8
9 Bacula provides autochanger support for reading and writing tapes.  In
10 order to work with an autochanger, Bacula requires a number of things, each of
11 which is explained in more detail after this list:
12
13 \begin{itemize}
14 \item A script that actually controls the autochanger according  to commands
15    sent by Bacula. We furnish such a script  that works with {\bf mtx} found in
16    the {\bf depkgs} distribution.  This script works only with single drive
17    autochangers.  
18
19 \item That each Volume (tape) to be used must be defined in the  Catalog and
20    have a Slot number assigned  to it so that Bacula knows where the Volume is in
21    the  autochanger. This is generally done with the {\bf label}  command. See
22    below for more details. You must pre-label the tapes manually before
23    using them. 
24
25 \item Modifications to your Storage daemon's Device configuration  resource to
26    identify that the device is a changer, as well  as a few other parameters.  
27
28 \item You should also modify your Storage resource definition  in the
29    Director's configuration file so that you are automatically prompted for the
30    Slot when labeling a Volume. 
31
32 \item You need to ensure that your Storage daemon (if not running as root)
33    has access permissions to both the tape drive and the control device.
34
35 \item You need to have {\bf Autochanger = yes} in your Storage resource
36    in your bacula-dir.conf file so that you will be prompted for the
37    slot number when you label Volumes.
38 \end{itemize}
39
40 In version 1.37 and later, there is a new \ilink{Autochanger
41 resource}{AutochangerRes} that permits you to group Device resources thus
42 creating a multi-drive autochanger. If you have an autochanger,
43 you must use this new resource. 
44
45 Bacula uses its own {\bf mtx-changer} script to interface with a program
46 that actually does the tape changing.  Thus in principle, {\bf mtx-changer}
47 can be adapted to function with any autochanger program, or you can
48 call any other script or program. The current
49 version of {\bf mtx-changer} works with the {\bf mtx} program.  However,
50 FreeBSD users have provided a script in the {\bf examples/autochangers}
51 directory that allows Bacula to use the {\bf chio} program.
52
53 Bacula also supports autochangers with barcode
54 readers. This support includes two Console commands: {\bf label barcodes}
55 and {\bf update slots}. For more details on these commands, see the "Barcode
56 Support" section below. 
57
58 Current Bacula autochanger support does not include cleaning, stackers, or
59 silos.  However, under certain conditions, you may be able to make Bacula
60 work with stackers (gravity feed and such).  Support for multi-drive
61 autochangers requires the \ilink{Autochanger resource}{AutochangerRes}
62 introduced in version 1.37.  This resource is also recommended for single
63 drive autochangers.
64
65 In principle, if {\bf mtx} will operate your changer correctly, then it is
66 just a question of adapting the {\bf mtx-changer} script (or selecting one
67 already adapted) for proper interfacing. You can find a list of autochangers
68 supported by {\bf mtx} at the following link: 
69 \elink{http://mtx.opensource-sw.net/compatibility.php}
70 {http://mtx.opensource-sw.net/compatibility.php}.
71 The home page for the {\bf mtx} project can be found at: 
72 \elink{http://mtx.opensource-sw.net/}{http://mtx.opensource-sw.net/}. 
73
74 If you are having troubles, please use the {\bf auto} command in the {\bf
75 btape} program to test the functioning of your autochanger with Bacula. When
76 Bacula is running, please remember that for many distributions (e.g. FreeBSD,
77 Debian, ...) the Storage daemon runs as {\bf bacula.tape} rather than {\bf
78 root.root}, so you will need to ensure that the Storage daemon has sufficient
79 permissions to access the autochanger. 
80
81 \label{SCSI devices}
82 \section{Knowing What SCSI Devices You Have}
83 \index[general]{Have!Knowing What SCSI Devices You }
84 \index[general]{Knowing What SCSI Devices You Have }
85 \index[general]{SCSI devices}
86 \index[general]{devices!SCSI}
87
88 Under Linux, you can 
89
90 \footnotesize
91 \begin{verbatim}
92 cat /proc/scsi/scsi
93 \end{verbatim}
94 \normalsize
95
96 to see what SCSI devices you have available. You can also: 
97
98 \footnotesize
99 \begin{verbatim}
100 cat /proc/scsi/sg/device_hdr /proc/scsi/sg/devices
101 \end{verbatim}
102 \normalsize
103
104 to find out how to specify their control address ({\bf /dev/sg0} for the
105 first, {\bf /dev/sg1} for the second, ...) on the {\bf Changer Device = }
106 Bacula directive. 
107
108 For more detailed information on what SCSI devices you have please see
109 the \ilink{Linux SCSI Tricks}{SCSITricks}  section of the Tape Testing
110 chapter of this manual.
111
112 Under FreeBSD, you can use: 
113
114 \footnotesize
115 \begin{verbatim}
116 camcontrol devlist
117 \end{verbatim}
118 \normalsize
119
120 To list the SCSI devices as well as the {\bf /dev/passn} that you will use on
121 the Bacula {\bf Changer Device = } directive. 
122
123 Please check that your Storage daemon has permission to access this
124 device.
125
126 The following tip for FreeBSD users comes from Danny Butroyd:
127 on reboot Bacula will NOT have permission to 
128 control the device /dev/pass0 (assuming this is your changer device).  
129 To get around this just edit the /etc/devfs.conf file and add the 
130 following to the bottom:                   
131 \footnotesize
132 \begin{verbatim}
133 own     pass0   root:bacula
134 perm    pass0   0666
135 own     nsa0.0  root:bacula
136 perm    nsa0.0    0666
137 \end{verbatim}
138 \normalsize
139
140 This gives the bacula group permission to write to the nsa0.0 device 
141 too just to be on the safe side.   To bring these changes into effect 
142 just run:-
143
144 /etc/rc.d/devfs restart
145
146 Basically this will stop you having to manually change permissions on these 
147 devices to make Bacula work when operating the AutoChanger after a reboot.
148
149 \label{scripts}
150 \section{Example Scripts}
151 \index[general]{Scripts!Example }
152 \index[general]{Example Scripts }
153
154 Please read the sections below so that you understand how autochangers work
155 with Bacula. Although we supply a default {\bf mtx-changer} script, your
156 autochanger may require some additional changes. If you want to see examples
157 of configuration files and scripts, please look in the {\bf
158 \lt{}bacula-src\gt{}/examples/devices} directory where you will find an
159 example {\bf HP-autoloader.conf} Bacula Device resource, and several {\bf
160 mtx-changer} scripts that have been modified to work with different
161 autochangers. 
162
163 \label{Slots}
164
165 \section{Slots}
166 \index[general]{Slots }
167
168 To properly address autochangers, Bacula must know which Volume is in each
169 {\bf slot} of the autochanger. Slots are where the changer cartridges reside
170 when not loaded into the drive. Bacula numbers these slots from one to the
171 number of cartridges contained in the autochanger. 
172
173 Bacula will not automatically use a Volume in your autochanger unless it is
174 labeled and the slot number is stored in the catalog and the Volume is marked
175 as InChanger. For each Volume in your
176 changer, you will, using the Console program, assign a slot. This information
177 is kept in {\bf Bacula's} catalog database along with the other data for the
178 volume. If no slot is given, or the slot is set to zero, Bacula will not
179 attempt to use the autochanger even if all the necessary configuration records
180 are present. In addition, the console {\bf mount} command does not cause
181 Bacula to operate the autochanger, it only tells Bacula to read any tape that
182 may be in the drive. 
183
184 You can check if the Slot number and InChanger flag are set by doing a:
185 \begin{verbatim}
186 list Volumes
187 \end{verbatim}
188
189 in the Console program.
190
191 \label{mult}
192 \section{Multiple Devices}
193 \index[general]{Devices!Multiple}
194 \index[general]{Multiple Devices}
195
196 Some autochangers have more than one read/write device (drive). The
197 new \ilink{Autochanger resource}{AutochangerRes} introduced in version
198 1.37 permits you to group Device resources, where each device 
199 represents a drive. The Director may still reference the Devices (drives)
200 directly, but doing so, bypasses the proper functioning of the
201 drives together.  Instead, the Director (in the Storage resource)
202 should reference the Autochanger resource name. Doing so permits 
203 the Storage daemon to ensure that only one drive uses the mtx-changer
204 script at a time, and also that two drives don't reference the
205 same Volume.
206
207 Multi-drive requires the use of the {\bf
208 Drive Index} directive in the Device resource of the Storage daemon's
209 configuration file. Drive numbers or the Device Index are numbered beginning
210 at zero, which is the default. To use the second Drive in an autochanger, you
211 need to define a second Device resource and set the Drive Index to 1 for
212 that device. In general, the second device will have the same {\bf Changer
213 Device} (control channel) as the first drive, but a different {\bf Archive
214 Device}. 
215
216 As a default, Bacula jobs will prefer to write to a Volume that is
217 already mounted. If you have a multiple drive autochanger and you want
218 Bacula to write to more than one Volume in the same Pool at the same
219 time, you will need to set \ilink{Prefer Mounted Volumes} {PreferMountedVolumes}
220 in the Directors Job resource to {\bf no}. This will cause
221 the Storage daemon to maximize the use of drives.
222
223
224 \label{ConfigRecords}
225 \section{Device Configuration Records}
226 \index[general]{Records!Device Configuration }
227 \index[general]{Device Configuration Records }
228
229 Configuration of autochangers within Bacula is done in the Device resource of
230 the Storage daemon. Four records: {\bf Autochanger}, {\bf Changer Device},
231 {\bf Changer Command}, and {\bf Maximum Changer Wait} control how Bacula uses
232 the autochanger. 
233
234 These four records, permitted in {\bf Device} resources, are described in
235 detail below. Note, however, that the {\bf Changer Device} and the 
236 {\bf Changer Command} directives are not needed in the Device resource
237 if they are present in the {\bf Autochanger} resource.
238
239 \begin{description}
240
241 \item [Autochanger = {\it Yes|No} ]
242    \index[sd]{Autochanger  }
243    The {\bf Autochanger} record specifies that the current device  is or is not
244 an autochanger. The default is {\bf no}.  
245
246 \item [Changer Device = \lt{}device-name\gt{}]
247    \index[sd]{Changer Device  }
248    In addition to the Archive Device name, you must specify a  {\bf Changer
249 Device} name. This is because most autochangers are  controlled through a
250 different device than is used for reading and  writing the cartridges. For
251 example, on Linux, one normally uses the generic SCSI interface for
252 controlling the autochanger, but the standard SCSI interface for reading and
253 writing the  tapes. On Linux, for the {\bf Archive Device = /dev/nst0},  you
254 would typically have {\bf Changer Device = /dev/sg0}.  Note, some of the more
255 advanced autochangers will locate the changer device on {\bf /dev/sg1}. Such
256 devices typically have  several drives and a large number of tapes.  
257
258 On FreeBSD systems, the changer device will typically be on {\bf /dev/pass0}
259 through {\bf /dev/passn}.  
260
261 On Solaris, the changer device will typically be some file under {\bf
262 /dev/rdsk}.  
263
264 Please ensure that your Storage daemon has permission to access this
265 device.
266
267 \item [Changer Command = \lt{}command\gt{}]
268    \index[sd]{Changer Command  }
269    This record is used to specify the external program to call  and what
270 arguments to pass to it. The command is assumed to be  a standard program or
271 shell script that can be executed by  the operating system. This command is
272 invoked each time that Bacula wishes to manipulate the autochanger.  The
273 following substitutions are made in the {\bf command}  before it is sent to
274 the operating system for execution:  
275
276 \footnotesize
277 \begin{verbatim}
278       %% = %
279       %a = archive device name
280       %c = changer device name
281       %d = changer drive index base 0
282       %f = Client's name
283       %j = Job name
284       %o = command  (loaded, load, or unload)
285       %s = Slot base 0
286       %S = Slot base 1
287       %v = Volume name
288 \end{verbatim}
289 \normalsize
290
291 An actual example for using {\bf mtx} with the  {\bf mtx-changer} script (part
292 of the Bacula distribution) is:  
293
294 \footnotesize
295 \begin{verbatim}
296 Changer Command = "/etc/bacula/mtx-changer %c %o %S %a %d"
297 \end{verbatim}
298 \normalsize
299
300 Where you will need to adapt the {\bf /etc/bacula} to be  the actual path on
301 your system where the mtx-changer script  resides.  Details of the three
302 commands currently used by Bacula  (loaded, load, unload) as well as the
303 output expected by  Bacula are give in the {\bf Bacula Autochanger Interface} 
304 section below.  
305
306 \item [Maximum Changer Wait = \lt{}time\gt{}]
307    \index[sd]{Maximum Changer Wait  }
308    This record is used to define the maximum amount of time that Bacula
309    will wait for an autoloader to respond to a command (e.g.  load).  The
310    default is set to 120 seconds.  If you have a slow autoloader you may
311    want to set it longer.
312
313 If the autoloader program fails to respond in this time, it  will be killed
314 and Bacula will request operator intervention.  
315
316 \item [Drive Index = \lt{}number\gt{}]
317    \index[sd]{Drive Index  }
318    This record allows you to tell Bacula to use the second or subsequent
319    drive in an autochanger with multiple drives.  Since the drives are
320    numbered from zero, the second drive is defined by
321
322 \footnotesize
323 \begin{verbatim}
324 Device Index = 1
325       
326 \end{verbatim}
327 \normalsize
328
329 To use the second drive, you need a second Device resource definition  in the
330 Bacula configuration file. See the Multiple Drive section above  in this
331 chapter for more information. 
332 \end{description}
333
334 In addition, for proper functioning of the Autochanger, you must 
335 define an Autochanger resource.
336 \input{autochangerres}
337
338 \label{example}
339 \section{An Example Configuration File}
340 \index[general]{Example Configuration File }
341 \index[general]{File!Example Configuration }
342
343 The following two resources implement an autochanger: 
344
345 \footnotesize
346 \begin{verbatim}
347 Autochanger {
348   Name = "Autochanger"
349   Device = DDS-4
350   Changer Device = /dev/sg0
351   Changer Command = "/etc/bacula/mtx-changer %c %o %S %a %d"
352 }
353
354 Device {
355   Name = DDS-4
356   Media Type = DDS-4
357   Archive Device = /dev/nst0    # Normal archive device
358   Autochanger = yes
359   LabelMedia = no;
360   AutomaticMount = yes;
361   AlwaysOpen = yes;
362 }
363 \end{verbatim}
364 \normalsize
365
366 where you will adapt the {\bf Archive Device}, the {\bf Changer Device}, and
367 the path to the {\bf Changer Command} to correspond to the values used on your
368 system. 
369
370 \section{A Multi-drive Example Configuration File}
371 \index[general]{Multi-drive Example Configuration File }
372
373 The following resources implement a multi-drive autochanger: 
374
375 \footnotesize
376 \begin{verbatim}
377 Autochanger {
378   Name = "Autochanger"
379   Device = Drive-1, Drive-2
380   Changer Device = /dev/sg0
381   Changer Command = "/etc/bacula/mtx-changer %c %o %S %a %d"
382 }
383
384 Device {
385   Name = Drive-1
386   Drive Index = 0
387   Media Type = DDS-4
388   Archive Device = /dev/nst0    # Normal archive device
389   Autochanger = yes
390   LabelMedia = no;
391   AutomaticMount = yes;
392   AlwaysOpen = yes;
393 }
394
395 Device {
396   Name = Drive-2
397   Drive Index = 1
398   Media Type = DDS-4
399   Archive Device = /dev/nst1    # Normal archive device
400   Autochanger = yes
401   LabelMedia = no;
402   AutomaticMount = yes;
403   AlwaysOpen = yes;
404 }
405
406 \end{verbatim}
407 \normalsize
408
409 where you will adapt the {\bf Archive Device}, the {\bf Changer Device}, and
410 the path to the {\bf Changer Command} to correspond to the values used on your
411 system. 
412
413 \label{SpecifyingSlots}
414 \section{Specifying Slots When Labeling}
415 \index[general]{Specifying Slots When Labeling }
416 \index[general]{Labeling!Specifying Slots When }
417
418 If you add an {\bf Autochanger = yes} record to the Storage resource in your
419 Director's configuration file, the Bacula Console will automatically prompt
420 you for the slot number when the Volume is in the changer when
421 you {\bf add} or {\bf label} tapes for that Storage device. If your
422 {\bf mtx-changer} script is properly installed, Bacula will automatically
423 load the correct tape during the label command.
424   
425 You must also set
426 {\bf Autochanger = yes} in the Storage daemon's Device resource                
427 as we have described above in
428 order for the autochanger to be used. Please see the 
429 \ilink{Storage Resource}{Autochanger1} in the Director's chapter
430 and the 
431 \ilink{Device Resource}{Autochanger} in the Storage daemon
432 chapter for more details on these records. 
433
434 Thus all stages of dealing with tapes can be totally automated. It is also
435 possible to set or change the Slot using the {\bf update} command in the
436 Console and selecting {\bf Volume Parameters} to update. 
437
438 Even though all the above configuration statements are specified and correct,
439 Bacula will attempt to access the autochanger only if a {\bf slot} is non-zero
440 in the catalog Volume record (with the Volume name). 
441
442 If your autochanger has barcode labels, you can label all the Volumes in
443 your autochanger one after another by using the {\bf label barcodes} command.
444 For each tape in the changer containing a barcode, Bacula will mount the tape
445 and then label it with the same name as the barcode. An appropriate Media
446 record will also be created in the catalog. Any barcode that begins with the
447 same characters as specified on the "CleaningPrefix=xxx" command, will be
448 treated as a cleaning tape, and will not be labeled. For example with: 
449
450 Please note that Volumes must be pre-labeled to be automatically used in
451 the autochanger during a backup.  If you do not have a barcode reader, this
452 is done manually (or via a script).
453
454 \footnotesize
455 \begin{verbatim}
456 Pool {
457   Name ...
458   Cleaning Prefix = "CLN"
459 }
460 \end{verbatim}
461 \normalsize
462
463 Any slot containing a barcode of CLNxxxx will be treated as a cleaning tape
464 and will not be mounted.
465
466 \section{Changing Cartridges}
467 \index[general]{Changing Cartridges }
468 If you wish to insert or remove cartridges in your autochanger or
469 you manually run the {\bf mtx} program, you must first tell Bacula
470 to release the autochanger by doing:
471
472 \footnotesize
473 \begin{verbatim}
474 unmount
475 (change cartridges and/or run mtx)
476 mount
477 \end{verbatim}
478 \normalsize
479
480 If you do not do the unmount before making such a change, Bacula
481 will become completely confused about what is in the autochanger
482 and may stop function because it expects to have exclusive use
483 of the autochanger while it has the drive mounted.
484
485
486 \label{Magazines}
487 \section{Dealing with Multiple Magazines}
488 \index[general]{Dealing with Multiple Magazines }
489 \index[general]{Magazines!Dealing with Multiple }
490
491 If you have several magazines or if you insert or remove cartridges from a
492 magazine, you should notify Bacula of this. By doing so, Bacula will as
493 a preference, use Volumes that it knows to be in the autochanger before
494 accessing Volumes that are not in the autochanger. This prevents unneeded
495 operator intervention. 
496
497 If your autochanger has barcodes (machine readable tape labels), the task of
498 informing Bacula is simple. Every time, you change a magazine, or add or
499 remove a cartridge from the magazine, simply do 
500
501 \footnotesize
502 \begin{verbatim}
503 unmount
504 (remove magazine)
505 (insert new magazine)
506 update slots
507 mount
508 \end{verbatim}
509 \normalsize
510
511 in the Console program. This will cause Bacula to request the autochanger to
512 return the current Volume names in the magazine. This will be done without
513 actually accessing or reading the Volumes because the barcode reader does this
514 during inventory when the autochanger is first turned on. Bacula will ensure
515 that any Volumes that are currently marked as being in the magazine are marked
516 as no longer in the magazine, and the new list of Volumes will be marked as
517 being in the magazine. In addition, the Slot numbers of the Volumes will be
518 corrected in Bacula's catalog if they are incorrect (added or moved). 
519
520 If you do not have a barcode reader on your autochanger, you have several
521 alternatives. 
522
523 \begin{enumerate}
524 \item You can manually set the Slot and InChanger flag using  the {\bf update
525    volume} command in the Console (quite  painful). 
526
527 \item You can issue a 
528
529 \footnotesize
530 \begin{verbatim}
531 update slots scan
532 \end{verbatim}
533 \normalsize
534
535    command that will cause Bacula to read the label on each  of the cartridges in
536    the magazine in turn and update the  information (Slot, InChanger flag) in the
537    catalog. This  is quite effective but does take time to load each cartridge 
538    into the drive in turn and read the Volume label.  
539
540 \item You can modify the mtx-changer script so that it simulates  an
541    autochanger with barcodes. See below for more details. 
542 \end{enumerate}
543
544 \label{simulating}
545 \section{Simulating Barcodes in your Autochanger}
546 \index[general]{Autochanger!Simulating Barcodes in your }
547 \index[general]{Simulating Barcodes in your Autochanger }
548
549 You can simulate barcodes in your autochanger by making the {\bf mtx-changer}
550 script return the same information that an autochanger with barcodes would do.
551 This is done by commenting out the one and only line in the {\bf list)} case,
552 which is: 
553
554 \footnotesize
555 \begin{verbatim}
556   ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
557 \end{verbatim}
558 \normalsize
559
560 at approximately line 99 by putting a \# in column one of that line, or by
561 simply deleting it. Then in its place add a new line that prints the contents
562 of a file. For example: 
563
564 \footnotesize
565 \begin{verbatim}
566 cat /etc/bacula/changer.volumes
567 \end{verbatim}
568 \normalsize
569
570 Be sure to include a full path to the file, which can have any name. The
571 contents of the file must be of the following format: 
572
573 \footnotesize
574 \begin{verbatim}
575 1:Volume1
576 2:Volume2
577 3:Volume3
578 ...
579 \end{verbatim}
580 \normalsize
581
582 Where the 1, 2, 3 are the slot numbers and Volume1, Volume2, ... are the
583 Volume names in those slots. You can have multiple files that represent the
584 Volumes in different magazines, and when you change magazines, simply copy the
585 contents of the correct file into your {\bf /etc/bacula/changer.volumes} file.
586 There is no need to stop and start Bacula when you change magazines, simply
587 put the correct data in the file, then run the {\bf update slots} command, and
588 your autochanger will appear to Bacula to be an autochanger with barcodes. 
589 \label{updateslots}
590
591 \section{The Full Form of the Update Slots Command}
592 \index[general]{Full Form of the Update Slots Command }
593 \index[general]{Command!Full Form of the Update Slots }
594
595 If you change only one cartridge in the magazine, you may not want to scan all
596 Volumes, so the {\bf update slots} command (as well as the {\bf update slots
597 scan} command) has the additional form: 
598
599 \footnotesize
600 \begin{verbatim}
601 update slots=n1,n2,n3-n4, ...
602 \end{verbatim}
603 \normalsize
604
605 where the keyword {\bf scan} can be appended or not. The n1,n2, ... represent
606 Slot numbers to be updated and the form n3-n4 represents a range of Slot
607 numbers to be updated (e.g. 4-7 will update Slots 4,5,6, and 7). 
608
609 This form is particularly useful if you want to do a scan (time expensive) and
610 restrict the update to one or two slots. 
611
612 For example, the command: 
613
614 \footnotesize
615 \begin{verbatim}
616 update slots=1,6 scan
617 \end{verbatim}
618 \normalsize
619
620 will cause Bacula to load the Volume in Slot 1, read its Volume label and
621 update the Catalog. It will do the same for the Volume in Slot 6. The command:
622
623
624 \footnotesize
625 \begin{verbatim}
626 update slots=1-3,6
627 \end{verbatim}
628 \normalsize
629
630 will read the barcoded Volume names for slots 1,2,3 and 6 and make the
631 appropriate updates in the Catalog. If you don't have a barcode reader or have
632 not modified the mtx-changer script as described above, the above command will
633 not find any Volume names so will do nothing. 
634 \label{FreeBSD}
635
636 \section{FreeBSD Issues}
637 \index[general]{Issues!FreeBSD }
638 \index[general]{FreeBSD Issues }
639
640 If you are having problems on FreeBSD when Bacula tries to select a tape, and
641 the message is {\bf Device not configured}, this is because FreeBSD has made
642 the tape device {\bf /dev/nsa1} disappear when there is no tape mounted in the
643 autochanger slot. As a consequence, Bacula is unable to open the device. The
644 solution to the problem is to make sure that some tape is loaded into the tape
645 drive before starting Bacula. This problem is corrected in Bacula versions
646 1.32f-5 and later. 
647
648 Please see the 
649 \ilink{ Tape Testing}{FreeBSDTapes} chapter of this manual for
650 {\bf important} information concerning your tape drive before doing the
651 autochanger testing. 
652 \label{AutochangerTesting}
653
654 \section{Testing Autochanger and Adapting mtx-changer script}
655 \index[general]{Testing the Autochanger }
656 \index[general]{Adapting Your mtx-changer script}
657
658
659 Before attempting to use the autochanger with Bacula, it is preferable to
660 "hand-test" that the changer works. To do so, we suggest you do the
661 following commands (assuming that the {\bf mtx-changer} script is installed in
662 {\bf /etc/bacula/mtx-changer}): 
663
664 \begin{description}
665
666 \item [Make sure Bacula is not running.]
667
668 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ list \ 0 \ /dev/nst0 \ 0]
669 \index[sd]{mtx-changer list}
670
671 This command should print:  
672
673 \footnotesize
674 \begin{verbatim}
675    1:
676    2:
677    3:
678    ...
679    
680 \end{verbatim}
681 \normalsize
682
683 or one number per line for each slot that is  occupied in your changer, and
684 the number should be  terminated by a colon ({\bf :}). If your changer has 
685 barcodes, the barcode will follow the colon.  If an error message is printed,
686 you must resolve the  problem (e.g. try a different SCSI control device name
687 if {\bf /dev/sg0}  is incorrect. For example, on FreeBSD systems, the
688 autochanger  SCSI control device is generally {\bf /dev/pass2}.  
689
690 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ slots ]
691 \index[sd]{mtx-changer slots}
692
693 This command should return the number of slots in your autochanger.  
694
695 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ unload \ 1 \ /dev/nst0 \ 0 ]
696 \index[sd]{mtx-changer unload}
697
698    If a tape is loaded from slot 1, this should cause it to be unloaded.  
699
700 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ load \ 3 \ /dev/nst0 \ 0 ]
701 \index[sd]{mtx-changer load}
702
703 Assuming you have a tape in slot 3,  it will be loaded into drive (0).
704  
705
706 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ loaded \ 0 \ /dev/nst0 \ 0]
707 \index[sd]{mtx-changer loaded}
708
709 It should print "3"  
710 Note, we have used an "illegal" slot number 0. In this case, it is simply
711 ignored because the slot number is not used.  However, it must be specified
712 because the drive parameter at the end of the command is needed to select
713 the correct drive.
714
715 \item [/etc/bacula/mtx-changer \ /dev/sg0 \ unload \ 3 /dev/nst0 \ 0]
716
717 will unload the tape into slot 3.
718
719 \end{description}
720
721 Once all the above commands work correctly, assuming that you have the right
722 {\bf Changer Command} in your configuration, Bacula should be able to operate
723 the changer. The only remaining area of problems will be if your autoloader
724 needs some time to get the tape loaded after issuing the command. After the
725 {\bf mtx-changer} script returns, Bacula will immediately rewind and read the
726 tape. If Bacula gets rewind I/O errors after a tape change, you will probably
727 need to insert a {\bf sleep 20} after the {\bf mtx} command, but be careful to
728 exit the script with a zero status by adding {\bf exit 0} after any additional
729 commands you add to the script. This is because Bacula checks the return
730 status of the script, which should be zero if all went well. 
731
732 You can test whether or not you need a {\bf sleep} by putting the following
733 commands into a file and running it as a script: 
734
735 \footnotesize
736 \begin{verbatim}
737 #!/bin/sh
738 /etc/bacula/mtx-changer /dev/sg0 unload 1 /dev/nst0 0
739 /etc/bacula/mtx-changer /dev/sg0 load 3 /dev/nst0 0
740 mt -f /dev/st0 rewind
741 mt -f /dev/st0 weof
742 \end{verbatim}
743 \normalsize
744
745 If the above script runs, you probably have no timing problems. If it does not
746 run, start by putting a {\bf sleep 30} or possibly a {\bf sleep 60} in the 
747 script just after the mtx-changer load command. If that works, then you should
748 move the sleep into the actual {\bf mtx-changer} script so that it will be
749 effective when Bacula runs. 
750
751 A second problem that comes up with a small number of autochangers is that
752 they need to have the cartridge ejected before it can be removed. If this is
753 the case, the {\bf load 3} will never succeed regardless of how long you wait.
754 If this seems to be your problem, you can insert an eject just after the
755 unload so that the script looks like: 
756
757 \footnotesize
758 \begin{verbatim}
759 #!/bin/sh
760 /etc/bacula/mtx-changer /dev/sg0 unload 1 /dev/nst0 0
761 mt -f /dev/st0 offline
762 /etc/bacula/mtx-changer /dev/sg0 load 3 /dev/nst0 0
763 mt -f /dev/st0 rewind
764 mt -f /dev/st0 weof
765 \end{verbatim}
766 \normalsize
767
768 Obviously, if you need the {\bf offline} command, you should move it into the
769 mtx-changer script ensuring that you save the status of the {\bf mtx} command
770 or always force an {\bf exit 0} from the script, because Bacula checks the
771 return status of the script. 
772
773 As noted earlier, there are several scripts in {\bf
774 \lt{}bacula-source\gt{}/examples/devices} that implement the above features,
775 so they may be a help to you in getting your script to work. 
776
777 If Bacula complains "Rewind error on /dev/nst0. ERR=Input/output error." you
778 most likely need more sleep time in your {\bf mtx-changer} before returning to
779 Bacula after a load command has been completed.
780
781 \label{using}
782
783 \section{Using the Autochanger}
784 \index[general]{Using the Autochanger }
785 \index[general]{Autochanger!Using the }
786
787 Let's assume that you have properly defined the necessary Storage daemon
788 Device records, and you have added the {\bf Autochanger = yes} record to the
789 Storage resource in your Director's configuration file. 
790
791 Now you fill your autochanger with say six blank tapes. 
792
793 What do you do to make Bacula access those tapes? 
794
795 One strategy is to prelabel each of the tapes. Do so by starting Bacula, then
796 with the Console program, enter the {\bf label} command: 
797
798 \footnotesize
799 \begin{verbatim}
800 ./console
801 Connecting to Director rufus:8101
802 1000 OK: rufus-dir Version: 1.26 (4 October 2002)
803 *label
804 \end{verbatim}
805 \normalsize
806
807 it will then print something like: 
808
809 \footnotesize
810 \begin{verbatim}
811 Using default Catalog name=BackupDB DB=bacula
812 The defined Storage resources are:
813      1: Autochanger
814      2: File
815 Select Storage resource (1-2): 1
816 \end{verbatim}
817 \normalsize
818
819 I select the autochanger (1), and it prints: 
820
821 \footnotesize
822 \begin{verbatim}
823 Enter new Volume name: TestVolume1
824 Enter slot (0 for none): 1
825 \end{verbatim}
826 \normalsize
827
828 where I entered {\bf TestVolume1} for the tape name, and slot {\bf 1} for the
829 slot. It then asks: 
830
831 \footnotesize
832 \begin{verbatim}
833 Defined Pools:
834      1: Default
835      2: File
836 Select the Pool (1-2): 1
837 \end{verbatim}
838 \normalsize
839
840 I select the Default pool. This will be automatically done if you only have a
841 single pool, then Bacula will proceed to unload any loaded volume, load the
842 volume in slot 1 and label it. In this example, nothing was in the drive, so
843 it printed: 
844
845 \footnotesize
846 \begin{verbatim}
847 Connecting to Storage daemon Autochanger at localhost:9103 ...
848 Sending label command ...
849 3903 Issuing autochanger "load slot 1" command.
850 3000 OK label. Volume=TestVolume1 Device=/dev/nst0
851 Media record for Volume=TestVolume1 successfully created.
852 Requesting mount Autochanger ...
853 3001 Device /dev/nst0 is mounted with Volume TestVolume1
854 You have messages.
855 *
856 \end{verbatim}
857 \normalsize
858
859 You may then proceed to label the other volumes. The messages will change
860 slightly because Bacula will unload the volume (just labeled TestVolume1)
861 before loading the next volume to be labeled. 
862
863 Once all your Volumes are labeled, Bacula will automatically load them as they
864 are needed. 
865
866 To "see" how you have labeled your Volumes, simply enter the {\bf list
867 volumes} command from the Console program, which should print something like
868 the following: 
869
870 \footnotesize
871 \begin{verbatim}
872 *{\bf list volumes}
873 Using default Catalog name=BackupDB DB=bacula
874 Defined Pools:
875      1: Default
876      2: File
877 Select the Pool (1-2): 1
878 +-------+----------+--------+---------+-------+--------+----------+-------+------+
879 | MedId | VolName  | MedTyp | VolStat | Bites | LstWrt | VolReten | Recyc | Slot |
880 +-------+----------+--------+---------+-------+--------+----------+-------+------+
881 | 1     | TestVol1 | DDS-4  | Append  | 0     | 0      | 30672000 | 0     | 1    |
882 | 2     | TestVol2 | DDS-4  | Append  | 0     | 0      | 30672000 | 0     | 2    |
883 | 3     | TestVol3 | DDS-4  | Append  | 0     | 0      | 30672000 | 0     | 3    |
884 | ...                                                                            |
885 +-------+----------+--------+---------+-------+--------+----------+-------+------+
886 \end{verbatim}
887 \normalsize
888
889 \label{Barcodes}
890
891 \section{Barcode Support}
892 \index[general]{Support!Barcode }
893 \index[general]{Barcode Support }
894
895 Bacula provides barcode support with two Console commands, {\bf label
896 barcodes} and {\bf update slots}.
897
898 The {\bf label barcodes} will cause Bacula to read the barcodes of all the
899 cassettes that are currently installed in the magazine (cassette holder) using
900 the {\bf mtx-changer} {\bf list} command. Each cassette is mounted in turn and
901 labeled with the same Volume name as the barcode. 
902
903 The {\bf update slots} command will first obtain the list of cassettes and
904 their barcodes from {\bf mtx-changer}. Then it will find each volume in turn
905 in the catalog database corresponding to the barcodes and set its Slot to
906 correspond to the value just read. If the Volume is not in the catalog, then
907 nothing will be done. This command is useful for synchronizing Bacula with the
908 current magazine in case you have changed magazines or in case you have moved
909 cassettes from one slot to another.
910
911 The {\bf Cleaning Prefix} statement can be used in the Pool resource to define
912 a Volume name prefix, which if it matches that of the Volume (barcode) will
913 cause that Volume to be marked with a VolStatus of {\bf Cleaning}. This will
914 prevent Bacula from attempting to write on the Volume.
915
916 \label{interface}
917
918 \section{Bacula Autochanger Interface}
919 \index[general]{Interface!Bacula Autochanger }
920 \index[general]{Bacula Autochanger Interface }
921
922 Bacula calls the autochanger script that you specify on the {\bf Changer
923 Device} statement. Normally this script will be the {\bf mtx-changer} script
924 that we can provide, but it can in fact be any program. The only requirements
925 are that the "commands" that Bacula uses are {\bf loaded}, {\bf load}, {\bf
926 unload}, {\bf list}, and {\bf slots}. In addition,
927 each of those commands must return the information in the precise format as
928 specified below: 
929
930 \footnotesize
931 \begin{verbatim}
932 - Currently the changer commands used are:
933     loaded -- returns number of the slot that is loaded, base 1,
934               in the drive or 0 if the drive is empty.
935     load   -- loads a specified slot (note, some autochangers
936               require a 30 second pause after this command) into
937               the drive.
938     unload -- unloads the device (returns cassette to its slot).
939     list   -- returns one line for each cassette in the autochanger
940               in the format <slot>:<barcode>. Where
941               the {\bf slot} is the non-zero integer representing
942               the slot number, and {\bf barcode} is the barcode
943               associated with the cassette if it exists and if you
944               autoloader supports barcodes. Otherwise the barcode
945               field is blank.
946     slots  -- returns total number of slots in the autochanger.
947 \end{verbatim}
948 \normalsize
949
950 Bacula checks the exit status of the program called, and if it is zero, the
951 data is accepted. If the exit status is non-zero, Bacula ignores any
952 information returned and treats the drive as if it is not an autochanger.