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