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