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