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