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