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