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