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