]> git.sur5r.net Git - bacula/docs/blob - docs/manual/tapetesting.tex
Doc updates
[bacula/docs] / docs / manual / tapetesting.tex
1 %%
2 %%
3
4 \section*{Testing Your Tape Drive With Bacula}
5 \label{_ChapterStart27}
6 \index[general]{Testing Your Tape Drive With Bacula }
7 \addcontentsline{toc}{section}{Testing Your Tape Drive With Bacula}
8
9 This chapter is concerned with testing and configuring your tape drive to make
10 sure that it will work properly with Bacula using the {\bf btape} program. 
11 \label{summary}
12
13 \subsection*{Summary of Steps to Take to Get Your Tape Drive Working}
14 \index[general]{Working!Summary of Steps to Take to Get Your Tape Drive }
15 \index[general]{Summary of Steps to Take to Get Your Tape Drive Working }
16 \addcontentsline{toc}{subsection}{Summary of Steps to Take to Get Your Tape
17 Drive Working}
18
19 In general, you should follow the following steps to get your tape drive to
20 work with Bacula. Start with a tape mounted in your drive. If you have an
21 autochanger, load a tape into the drive. We use {\bf /dev/nst0} as the tape
22 drive name, you will need to adapt it according to your system. 
23
24 Do not proceed to the next item until you have succeeded with the previous
25 one. 
26
27 \begin{enumerate}
28 \item Use tar to write to, then read from your drive:  
29
30    \footnotesize
31 \begin{verbatim}
32    mt -f /dev/nst0 rewind
33    tar cvf /dev/nst0 .
34    mt -f /dev/nst0 rewind
35    tar tvf /dev/nst0
36    
37 \end{verbatim}
38 \normalsize
39
40 \item Make sure you have a valid and correct Device resource  corresponding to
41    your drive. For Linux users, generally,  the default one works. For FreeBSD
42    users, there are two  possible Device configurations (see below). 
43 \item Run the btape {\bf test} command:  
44
45    \footnotesize
46 \begin{verbatim}
47    ./btape -c bacula-sd.conf /dev/nst0
48    test
49    
50 \end{verbatim}
51 \normalsize
52
53 It isn't necessary to run the autochanger part of the  test at this time,  but
54 do not go past this point until the basic test succeeds. If you do have 
55 an autochanger, please be sure to read the
56 \ilink{Autochanger chapter}{_ChapterStart18} of this manual.
57
58 \item Run the btape {\bf fill} command, preferably with two volumes.  This
59    can take a long time. If you have an autochanger and it  is configured, Bacula
60    will automatically use it. If you do  not have it configured, you can manually
61    issue the appopriate  {\bf mtx} command, or press the autochanger buttons to
62    change  the tape when requested to do so. 
63 \item FreeBSD users, run the {\bf tapetest} program, and make  sure your
64    system is patched if necessary. See below for more  details. 
65 \item Run Bacula, and backup a reasonably small directory,  say 60 Megabytes.
66    Do three successive backups of this  directory. 
67 \item Stop Bacula, then restart it. Do another full backup  of the same
68    directory. Then stop and restart Bacula. 
69 \item Do a restore of the directory backed up, by entering the  following
70    restore command, being careful to restore it to  an alternate location:  
71
72 \footnotesize
73 \begin{verbatim}
74    restore select all done
75    yes
76    
77 \end{verbatim}
78 \normalsize
79
80 Do a {\bf diff} on the restored directory to ensure it is identical  to the
81 original directory.  
82 \item If you have an autochanger, you should now go back to the  btape program
83    and run the autochanger test:  
84
85 \footnotesize
86 \begin{verbatim}
87      ./btape -c bacula-sd.conf /dev/nst0
88      auto
89      
90 \end{verbatim}
91 \normalsize
92
93 Adjust your autochanger as necessary to ensure that it works  correctly. See
94 the Autochanger chapter of this manual  for a complete discussion of testing
95 your autochanger.  
96 \end{enumerate}
97
98 If you have reached this point, you stand a good chance of having everything
99 work. If you get into trouble at any point, {\bf carefully} read the
100 documentation given below. If you cannot get past some point, ask the {\bf
101 bacula-users} email list, but specify which of the steps you have successfully
102 completed. In particular, you may want to look at the 
103 \ilink{ Tips for Resolving Problems}{problems1} section below. 
104
105 \subsubsection*{Specifying the Configuration File}
106 \index[general]{File!Specifying the Configuration }
107 \index[general]{Specifying the Configuration File }
108 \addcontentsline{toc}{subsubsection}{Specifying the Configuration File}
109
110 Starting with version 1.27, each of the tape utility programs including the
111 {\bf btape} program requires a valid Storage daemon configuration file
112 (actually, the only part of the configuration file that {\bf btape} needs is
113 the {\bf Device} resource definitions). This permits {\bf btape} to find the
114 configuration parameters for your archive device (generally a tape drive).
115 Without those parameters, the testing and utility programs do not know how to
116 properly read and write your drive. By default, they use {\bf bacula-sd.conf}
117 in the current directory, but you may specify a different configuration file
118 using the {\bf -c} option. 
119
120 \subsubsection*{Specifying a Device Name For a Tape}
121 \index[general]{Tape!Specifying a Device Name For a }
122 \index[general]{Specifying a Device Name For a Tape }
123 \addcontentsline{toc}{subsubsection}{Specifying a Device Name For a Tape}
124
125 {\bf btape} {\bf device-name} where the Volume can be found. In the case of a
126 tape, this is the physical device name such as {\bf /dev/nst0} or {\bf
127 /dev/rmt/0ubn} depending on your system that you specify on the Archive Device
128 directive. For the program to work, it must find the identical name in the
129 Device resource of the configuration file. If the name is not found in the
130 list of phsical names, the utility program will compare the name you entered
131 to the Device names (rather than the Archive device names). See below for
132 specifying Volume names. 
133
134 \subsubsection*{Specifying a Device Name For a File}
135 \index[general]{File!Specifying a Device Name For a }
136 \index[general]{Specifying a Device Name For a File }
137 \addcontentsline{toc}{subsubsection}{Specifying a Device Name For a File}
138
139 If you are attempting to read or write an archive file rather than a tape, the
140 {\bf device-name} should be the full path to the archive location including
141 the filename. The filename (last part of the specification) will be stripped
142 and used as the Volume name, and the path (first part before the filename)
143 must have the same entry in the configuration file. So, the path is equivalent
144 to the archive device name, and the filename is equivalent to the volume name.
145
146
147 \subsection*{btape}
148 \label{btape1}
149 \index[general]{Btape }
150 \addcontentsline{toc}{subsection}{btape}
151
152 This program permits a number of elementary tape operations via a tty command
153 interface. The {\bf test} command, described below, can be very useful for
154 testing tape drive compatibility problems. Aside from initial testing of tape
155 drive compatibility with {\bf Bacula}, {\bf btape} will be mostly used by
156 developers writing new tape drivers. 
157
158 {\bf btape} can be dangerous to use with existing {\bf Bacula} tapes because
159 it will relabel a tape or write on the tape if so requested regardless of
160 whether or not the tape contains valuable data, so please be careful and use
161 it only on blank tapes. 
162
163 To work properly, {\bf btape} needs to read the Storage daemon's configuration
164 file. As a default, it will look for {\bf bacula-sd.conf} in the current
165 directory. If your configuration file is elsewhere, please use the {\bf -c}
166 option to specify where. 
167
168 The physical device name or the Device resource name must be specified on the
169 command line, and this same device name must be present in the Storage
170 daemon's configuration file read by {\bf btape} 
171
172 \footnotesize
173 \begin{verbatim}
174 Usage: btape [options] device_name
175        -b <file>   specify bootstrap file
176        -c <file>   set configuration file to file
177        -d <nn>     set debug level to nn
178        -p          proceed inspite of I/O errors
179        -s          turn off signals
180        -v          be verbose
181        -?          print this message.
182 \end{verbatim}
183 \normalsize
184
185 \subsubsection*{Using btape to Verify your Tape Drive}
186 \index[general]{Using btape to Verify your Tape Drive }
187 \index[general]{Drive!Using btape to Verify your Tape }
188 \addcontentsline{toc}{subsubsection}{Using btape to Verify your Tape Drive}
189
190 An important reason for this program is to ensure that a Storage daemon
191 configuration file is defined so that Bacula will correctly read and write
192 tapes. 
193
194 It is highly recommended that you run the {\bf test} command before running
195 your first Bacula job to ensure that the parameters you have defined for your
196 storage device (tape drive) will permit {\bf Bacula} to function properly. You
197 only need to mount a blank tape, enter the command, and the output should be
198 reasonably self explanatory. For example: 
199
200 \footnotesize
201 \begin{verbatim}
202 (ensure that Bacula is not running)
203 ./btape -c /usr/bin/bacula/bacula-sd.conf /dev/nst0
204 \end{verbatim}
205 \normalsize
206
207 The output will be: 
208
209 \footnotesize
210 \begin{verbatim}
211 Tape block granularity is 1024 bytes.
212 btape: btape.c:376 Using device: /dev/nst0
213 *
214 \end{verbatim}
215 \normalsize
216
217 Enter the test command: 
218
219 \footnotesize
220 \begin{verbatim}
221 test
222 \end{verbatim}
223 \normalsize
224
225 The output produced should be something similar to the following: I've cut the
226 listing short because it is frequently updated to have new tests. 
227
228 \footnotesize
229 \begin{verbatim}
230 === Append files test ===
231 This test is essential to Bacula.
232 I'm going to write one record  in file 0,
233                    two records in file 1,
234              and three records in file 2
235 btape: btape.c:387 Rewound /dev/nst0
236 btape: btape.c:855 Wrote one record of 64412 bytes.
237 btape: btape.c:857 Wrote block to device.
238 btape: btape.c:410 Wrote EOF to /dev/nst0
239 btape: btape.c:855 Wrote one record of 64412 bytes.
240 btape: btape.c:857 Wrote block to device.
241 btape: btape.c:855 Wrote one record of 64412 bytes.
242 btape: btape.c:857 Wrote block to device.
243 btape: btape.c:410 Wrote EOF to /dev/nst0
244 btape: btape.c:855 Wrote one record of 64412 bytes.
245 btape: btape.c:857 Wrote block to device.
246 btape: btape.c:855 Wrote one record of 64412 bytes.
247 btape: btape.c:857 Wrote block to device.
248 btape: btape.c:855 Wrote one record of 64412 bytes.
249 btape: btape.c:857 Wrote block to device.
250 btape: btape.c:410 Wrote EOF to /dev/nst0
251 btape: btape.c:387 Rewound /dev/nst0
252 btape: btape.c:693 Now moving to end of media.
253 btape: btape.c:427 Moved to end of media
254 We should be in file 3. I am at file 3. This is correct!
255 Now the important part, I am going to attempt to append to the tape.
256 ...
257 === End Append files test ===
258 \end{verbatim}
259 \normalsize
260
261 If you do not successfully complete the above test, please resolve the
262 problem(s) before attempting to use {\bf Bacula}. Depending on your tape
263 drive, the test may recommend that you add certain records to your
264 configuration. We strongly recommend that you do so and then re-run the above
265 test to insure it works the first time. 
266
267 Some of the suggestions it provides for resolving the problems may or may not
268 be useful. If at all possible avoid using fixed blocking. If the test suddenly
269 starts to print a long series of: 
270
271 \footnotesize
272 \begin{verbatim}
273 Got EOF on tape.
274 Got EOF on tape.
275 ...
276 \end{verbatim}
277 \normalsize
278
279 then almost certainly, you are running your drive in fixed block mode rather
280 than variable block mode. Please see below for help on resolving that. 
281
282 For FreeBSD users, please see the notes below for doing further testing of
283 your tape drive. 
284
285 \subsubsection*{Linux SCSI Tricks}
286 \index[general]{Tricks!Linux SCSI }
287 \index[general]{Linux SCSI Tricks }
288 \addcontentsline{toc}{subsubsection}{Linux SCSI Tricks}
289
290 You can find out what SCSI devices you have by doing: 
291
292 \footnotesize
293 \begin{verbatim}
294 cat /proc/scsi/scsi
295 \end{verbatim}
296 \normalsize
297
298 For example, I get the following: 
299
300 \footnotesize
301 \begin{verbatim}
302 Attached devices:
303 Host: scsi2 Channel: 00 Id: 01 Lun: 00
304   Vendor: HP       Model: C5713A           Rev: H107
305   Type:   Sequential-Access                ANSI SCSI revision: 02
306 Host: scsi2 Channel: 00 Id: 04 Lun: 00
307   Vendor: SONY     Model: SDT-10000        Rev: 0110
308   Type:   Sequential-Access                ANSI SCSI revision: 02
309 \end{verbatim}
310 \normalsize
311
312 The above represents first an autochanger and second a simple
313 tape drive. The HP changer (the first entry) uses the same SCSI channel
314 for data and for control, so in Bacula, you would use: 
315 \footnotesize
316 \begin{verbatim}
317 Archive Device = /dev/nst0
318 Changer Device = /dev/sg0
319 \end{verbatim}
320 \normalsize
321
322 If you want to remove the SDT-10000 device, you can do so as root with: 
323
324 \footnotesize
325 \begin{verbatim}
326 echo "scsi remove-single-device 2 0 4 0">/proc/scsi/scsi
327 \end{verbatim}
328 \normalsize
329
330 and you can put add it back with: 
331
332 \footnotesize
333 \begin{verbatim}
334 echo "scsi add-single-device 2 0 4 0">/proc/scsi/scsi
335 \end{verbatim}
336 \normalsize
337
338 where the 2 0 4 0 are the Host, Channel, Id, and Lun as seen on the output
339 from {\bf cat /proc/scsi/scsi}. Note, the Channel must be specified as
340 numeric. 
341
342 Below is a slightly more complicated output, which is a single autochanger
343 with two drives, and which operates the changer on a different channel
344 from from the drives:
345
346 \footnotesize
347 \begin{verbatim}
348 Attached devices:
349 Host: scsi0 Channel: 00 Id: 00 Lun: 00
350   Vendor: ATA      Model: WDC WD1600JD-75H Rev: 08.0
351   Type:   Direct-Access                    ANSI SCSI revision: 05
352 Host: scsi2 Channel: 00 Id: 04 Lun: 00
353   Vendor: HP       Model: Ultrium 2-SCSI   Rev: F6CH
354   Type:   Sequential-Access                ANSI SCSI revision: 03
355 Host: scsi2 Channel: 00 Id: 05 Lun: 00
356   Vendor: HP       Model: Ultrium 2-SCSI   Rev: F6CH
357   Type:   Sequential-Access                ANSI SCSI revision: 03
358 Host: scsi2 Channel: 00 Id: 06 Lun: 00
359   Vendor: OVERLAND Model: LXB              Rev: 0106
360   Type:   Medium Changer                   ANSI SCSI revision: 02
361 \end{verbatim}
362 \normalsize
363
364 The above tape drives are accessed on /dev/nst0 and /dev/nst1, while
365 the control channel for those two drives is /dev/sg3.
366
367
368
369 \label{problems1}
370 \subsection*{Tips for Resolving Problems}
371 \index[general]{Problems!Tips for Resolving }
372 \index[general]{Tips for Resolving Problems }
373 \addcontentsline{toc}{subsection}{Tips for Resolving Problems}
374
375 \label{CannotRestore}
376 \subsubsection*{Bacula Saves But Cannot Restore Files}
377 \index[general]{Files!Bacula Saves But Cannot Restore }
378 \index[general]{Bacula Saves But Cannot Restore Files }
379 \addcontentsline{toc}{subsubsection}{Bacula Saves But Cannot Restore Files}
380
381 If you are getting error messages such as: 
382
383 \footnotesize
384 \begin{verbatim}
385 Volume data error at 0:1! Wanted block-id: "BB02", got "". Buffer discarded
386 \end{verbatim}
387 \normalsize
388
389 It is very likely that Bacula has tried to do block positioning and ended up
390 at an invalid block. This can happen if your tape drive is in fixed block mode
391 while Bacula's default is variable blocks. Note that in such cases, Bacula is
392 perfectly able to write to your Volumes (tapes), but cannot position to read
393 them. 
394
395 There are two possible solutions. 
396
397 \begin{enumerate}
398 \item The first and  best is to always ensure that your drive is in  variable
399    block mode. Note, it can switch back to  fixed block mode on a reboot or if
400    another program  uses the drive. So on such systems you  need to modify the
401 Bacula startup files  to explicitly set: 
402
403 \footnotesize
404 \begin{verbatim}
405 mt -f /dev/nst0 defblksize 0
406 \end{verbatim}
407 \normalsize
408
409 or whatever is appropriate on your system.  
410 \item The second possibility, especially, if Bacula wrote  while the drive was
411    in fixed block mode, is to turn  off block positioning in Bacula. This is done
412    by  adding: 
413
414 \footnotesize
415 \begin{verbatim}
416 Block Positioning = no
417 \end{verbatim}
418 \normalsize
419
420 to the Device resource. This is not the recommended  procedure because it can
421 enormously slow down  recovery of files, but it may help where all else 
422 fails. This directive is available in version 1.35.5  or later (and not yet
423 tested).  
424 \end{enumerate}
425
426 If you are getting error messages such as:
427 \footnotesize
428 \begin{verbatim}
429 Volume data error at 0:0!
430 Block checksum mismatch in block=0 len=32625 calc=345678 blk=123456
431 \end{verbatim}
432 \normalsize
433
434 You are getting tape read errors, and this is most likely due to 
435 one of the following things:
436 \begin{enumerate}
437 \item An old or bad tape.
438 \item A dirty drive that needs cleaning (particularly for DDS drives).
439 \item A loose SCSI cable.
440 \item Old firmware in your drive. Make sure you have the latest firmware
441       loaded.
442 \item Computer memory errors.
443 \item Over-clocking your CPU.
444 \item A bad SCSI card.
445 \end{enumerate}
446
447
448 \label{opendevice}
449 \subsubsection*{Bacula Cannot Open the Device}
450 \index[general]{Device!Bacula Cannot Open the }
451 \index[general]{Bacula Cannot Open the Device }
452 \addcontentsline{toc}{subsubsection}{Bacula Cannot Open the Device}
453
454 If you get an error message such as: 
455
456 \footnotesize
457 \begin{verbatim}
458 dev open failed: dev.c:265 stored: unable to open
459 device /dev/nst0:> ERR=No such device or address
460 \end{verbatim}
461 \normalsize
462
463 the first time you run a job, it is most likely due to the fact that you
464 specified the incorrect device name on your {\bf Archive Device}. 
465
466 If Bacula works fine with your drive, then all off a sudden you get error
467 messages similar to the one shown above, it is quite possible that your driver
468 module is being removed because the kernel deems it idle. This is done via
469 {\bf crontab} with the use of {\bf rmmod -a}. To fix the problem, you can
470 remove this entry from {\bf crontab}, or you can manually {\bf modprob} your
471 driver module (or add it to the local startup script). Thanks to Alan Brown
472 for this tip. 
473 \label{IncorrectFiles}
474
475 \subsubsection*{Incorrect File Number}
476 \index[general]{Number!Incorrect File }
477 \index[general]{Incorrect File Number }
478 \addcontentsline{toc}{subsubsection}{Incorrect File Number}
479
480 When Bacula moves to the end of the medium, it normally uses the {\bf
481 ioctl(MTEOM)} function. Then Bacula uses the {\bf ioctl(MTIOCGET)} function to
482 retrieve the current file position from the {\bf mt\_fileno} field. Some SCSI
483 tape drivers will use a fast means of seeking to the end of the medium and in
484 doing so, they will not know the current file position and hence return a {\bf
485 -1}. As a consequence, if you get {\bf ``This is NOT correct!''} in the
486 positioning tests, this may be the cause. You must correct this condition in
487 order for Bacula to work. 
488
489 There are two possible solutions to the above problem of incorrect file
490 number: 
491
492 \begin{itemize}
493 \item Figure out how to configure your SCSI driver to  keep track of the file
494    position during the MTEOM  request. This is the preferred solution.  
495 \item Modify the {\bf Device} resource of your {\bf bacula-sd.conf} file  to
496    include:  
497
498 \footnotesize
499 \begin{verbatim}
500 Hardware End of File = no
501 \end{verbatim}
502 \normalsize
503
504 This will cause Bacula to use the MTFSF request to  seek to the end of the
505 medium, and Bacula will keep  track of the file number itself. 
506 \end{itemize}
507
508 \label{IncorrectBlocks}
509
510 \subsubsection*{Incorrect Number of Blocks or Positioning Errors during btape
511 Testing}
512 \index[general]{Testing!Incorrect Number of Blocks or Positioning Errors
513 during btape }
514 \index[general]{Incorrect Number of Blocks or Positioning Errors during btape
515 Testing }
516 \addcontentsline{toc}{subsubsection}{Incorrect Number of Blocks or Positioning
517 Errors during btape Testing}
518
519 {\bf Bacula's} preferred method of working with tape drives (sequential
520 devices) is to run in variable block mode, and this is what is set by default.
521 You should first ensure that your tape drive is set for variable block mode
522 (see below). 
523
524 If your tape drive is in fixed block mode and you have told Bacula to use
525 different fixed block sizes or variable block sizes (default), you will get
526 errors when Bacula attempts to forward space to the correct block (the kernel
527 driver's idea of tape blocks will not correspond to Bacula's). 
528
529 All modern tape drives support variable tape blocks, but some older drives (in
530 particular the QIC drives) as well as the ATAPI ide-scsi driver run only in
531 fixed block mode. The Travan tape drives also apparently must run in fixed
532 block mode (to be confirmed). 
533
534 Even in variable block mode, with the exception of the first record on the
535 second or subsequent volume of a multi-volume backup, Bacula will write blocks
536 of a fixed size. However, in reading a tape, Bacula will assume that for each
537 read request, exactly one block from the tape will be transferred. This the
538 most common way that tape drives work and is well supported by {\bf Bacula}. 
539
540 Drives that run in fixed block mode can cause serious problems for Bacula if
541 the drive's block size does not correspond exactly to {\bf Bacula's} block
542 size. In fixed block size mode, drivers may transmit a partial block or
543 multiple blocks for a single read request. From {\bf Bacula's} point of view,
544 this destroys the concept of tape blocks. It is much better to run in variable
545 block mode, and almost all modern drives (the OnStream is an exception) run in
546 variable block mode. In order for Bacula to run in fixed block mode, you must
547 include the following records in the Storage daemon's Device resource
548 definition: 
549
550 \footnotesize
551 \begin{verbatim}
552 Minimum Block Size = nnn
553 Maximum Block Size = nnn
554 \end{verbatim}
555 \normalsize
556
557 where {\bf nnn} must be the same for both records and must be identical to the
558 driver's fixed block size. 
559
560 We recommend that you avoid this configuration if at all possible by using
561 variable block sizes. 
562
563 If you must run with fixed size blocks, make sure they are not 512 bytes. This
564 is too small and the overhead that Bacula has with each record will become
565 excessive. If at all possible set any fixed block size to something like
566 64,512 bytes or possibly 32,768 if 64,512 is too large for your drive. See
567 below for the details on checking and setting the default drive block size. 
568
569 To recover files from tapes written in fixed block mode, see below. 
570 \label{TapeModes}
571
572 \subsubsection*{Ensuring that the Tape Modes Are Properly Set -- {\bf Linux
573 Only}}
574 \index[general]{Ensuring that the Tape Modes Are Properly Set -- Linux Only }
575 \index[general]{Only!Ensuring that the Tape Modes Are Properly Set -- Linux }
576 \addcontentsline{toc}{subsubsection}{Ensuring that the Tape Modes Are Properly
577 Set -- Linux Only}
578
579 If you have a modern SCSI tape drive and you are having problems with the {\bf
580 test} command as noted above, it may be that some program has set one or more
581 of your SCSI driver's options to non-default values. For example, if your
582 driver is set to work in SysV manner, Bacula will not work correctly because
583 it expects BSD behavior. To reset your tape drive to the default values, you
584 can try the following, but {\bf ONLY} if you have a SCSI tape drive on a {\bf
585 Linux} system: 
586
587 \footnotesize
588 \begin{verbatim}
589 become super user
590 mt -f /dev/nst0 rewind
591 mt -f /dev/nst0 stoptions buffer-writes async-writes read-ahead
592 \end{verbatim}
593 \normalsize
594
595 The above commands will clear all options and then set those specified. None
596 of the specified options are required by Bacula, but a number of other options
597 such as SysV behavior must not be set. Bacula does not support SysV tape
598 behavior. On systems other than Linux, you will need to consult your {\bf mt}
599 man pages or documentation to figure out how to do the same thing. This should
600 not really be necessary though -- for example, on both Linux and Solaris
601 systems, the default tape driver options are compatible with Bacula. 
602
603 You may also want to ensure that no prior program has set the default block
604 size, as happened to one user, by explicitly turning it off with: 
605
606 \footnotesize
607 \begin{verbatim}
608 mt -f /dev/nst0 defblksize 0
609 \end{verbatim}
610 \normalsize
611
612 If you would like to know what options you have set before making any of the
613 changes noted above, you can now view them on Linux systems, thanks to a tip
614 provided by Willem Riede. Do the following: 
615
616 \footnotesize
617 \begin{verbatim}
618 become super user
619 mt -f /dev/nst0 stsetoptions 0
620 grep st0 /var/log/messages
621 \end{verbatim}
622 \normalsize
623
624 and you will get output that looks something like the following: 
625
626 \footnotesize
627 \begin{verbatim}
628 kernel: st0: Mode 0 options: buffer writes: 1, async writes: 1, read ahead: 1
629 kernel: st0:    can bsr: 0, two FMs: 0, fast mteom: 0, auto lock: 0,
630 kernel: st0:    defs for wr: 0, no block limits: 0, partitions: 0, s2 log: 0
631 kernel: st0:    sysv: 0 nowait: 0
632 \end{verbatim}
633 \normalsize
634
635 Note, I have chopped off the beginning of the line with the date and machine
636 name for presentation purposes. 
637
638 Some people find that the above settings only last until the next reboot, so
639 please check this otherwise you may have unexpected problems. 
640
641 Beginning with Bacula version 1.35.8, if Bacula detects that you are running
642 in variable block mode, it will attempt to set your drive appropriately. All
643 OSes permit setting variable block mode, but some OSes do not permit setting
644 the other modes that Bacula needs to function properly. 
645 \label{compression}
646
647 \subsubsection*{Checking and Setting Tape Hardware Compression and Blocking
648 Size}
649 \index[general]{Checking and Setting Tape Hardware Compression and Blocking
650 Size }
651 \index[general]{Size!Checking and Setting Tape Hardware Compression and
652 Blocking }
653 \addcontentsline{toc}{subsubsection}{Checking and Setting Tape Hardware
654 Compression and Blocking Size}
655
656 As far as I can tell, there is no way with the {\bf mt} program to check if
657 your tape hardware compression is turned on or off. You can, however, turn it
658 on by using (on Linux): 
659
660 \footnotesize
661 \begin{verbatim}
662 become super user
663 mt -f /dev/nst0 defcompression 1
664 \end{verbatim}
665 \normalsize
666
667 and of course, if you use a zero instead of the one at the end, you will turn
668 it off. 
669
670 If you have built the {\bf mtx} program in the {\bf depkgs} package, you can
671 use tapeinfo to get quite a bit of information about your tape drive even if
672 it is not an autochanger. This program is called using the SCSI control
673 device. On Linux for tape drive /dev/nst0, this is usually /dev/sg0, while on
674 FreeBSD for /dev/nsa0, the control device is often /dev/pass2. For example on
675 my DDS-4 drive (/dev/nst0), I get the following: 
676
677 \footnotesize
678 \begin{verbatim}
679 tapeinfo -f /dev/sg0
680 Product Type: Tape Drive
681 Vendor ID: 'HP      '
682 Product ID: 'C5713A          '
683 Revision: 'H107'
684 Attached Changer: No
685 MinBlock:1
686 MaxBlock:16777215
687 SCSI ID: 5
688 SCSI LUN: 0
689 Ready: yes
690 BufferedMode: yes
691 Medium Type: Not Loaded
692 Density Code: 0x26
693 BlockSize: 0             
694 \end{verbatim}
695 \normalsize
696
697 where the {\bf DataCompEnabled: yes} means that tape hardware compression is
698 turned on. You can turn it on and off (yes|no) by using the {\bf mt}
699 commands given above. Also, this output will tell you if the {\bf BlockSize}
700 is non-zero and hence set for a particular block size. Bacula is not likely to
701 work in such a situation because it will normally attempt to write blocks of
702 64,512 bytes, except the last block of the job which will generally be
703 shorter. The first thing to try is setting the default block size to zero
704 using the {\bf mt \ -f \ /dev/nst0 \ defblksize \ 0} command as shown above.
705 On FreeBSD, this would be something like: {\bf mt \ -f \ /dev/nsa0 \ blocksize
706 \ 0}. 
707
708 If your tape drive requires fixed block sizes (very unusual), you can use the
709 following records: 
710
711 \footnotesize
712 \begin{verbatim}
713 Minimum Block Size = nnn
714 Maximum Block Size = nnn
715 \end{verbatim}
716 \normalsize
717
718 in your Storage daemon's Device resource to force Bacula to write fixed size
719 blocks (where you sent nnn to be the same for both of the above records). This
720 should be done only if your drive does not support variable block sizes, or
721 you have some other strong reasons for using fixed block sizes. As mentioned
722 above, a small fixed block size of 512 or 1024 bytes will be very inefficient.
723 Try to set any fixed block size to something like 64,512 bytes or larger if
724 your drive will support it. 
725
726 Also, note that the {\bf Medium Type} field of the output of {\bf tapeinfo}
727 reports {\bf Not Loaded}, which is not correct. As a consequence, you should
728 ignore that field as well as the {\bf Attached Changer} field. 
729
730 To recover files from tapes written in fixed block mode, see below. 
731 \label{FreeBSDTapes}
732
733 \subsubsection*{Tape Modes on FreeBSD}
734 \index[general]{FreeBSD!Tape Modes on }
735 \index[general]{Tape Modes on FreeBSD }
736 \addcontentsline{toc}{subsubsection}{Tape Modes on FreeBSD}
737
738 On most FreeBSD systems such as 4.9 and most tape drives, Bacula should run
739 with: 
740
741 \footnotesize
742 \begin{verbatim}
743 mt \  -f \  /dev/nsa0 \  seteotmodel \  2
744 mt \  -f \  /dev/nsa0 \  blocksize \  0
745 mt \  -f \ /dev/nsa0 \  comp \  enable
746 \end{verbatim}
747 \normalsize
748
749 You might want to put those commands in a startup script to make sure your
750 tape driver is properly initialized before running Bacula. 
751
752 Then according to what the {\bf btape test} command returns, you will probably
753 need to set the following (see below for an alternative): 
754
755 \footnotesize
756 \begin{verbatim}
757   Hardware End of Medium = no
758   BSF at EOM = yes
759   Backward Space Record = no
760   Backward Space File = no
761   Fast Forward Space File = no
762   TWO EOF = yes
763 \end{verbatim}
764 \normalsize
765
766 Then be sure to run some append tests with Bacula where you start and stop
767 Bacula between appending to the tape, or use {\bf btape} version 1.35.1 or
768 greater, which includes simulation of stopping/restarting Bacula. 
769
770 Please see the file {\bf platforms/freebsd/pthreads-fix.txt} in the main
771 Bacula directory concerning {\bf important} information concerning
772 compatibility of Bacula and your system. A much more optimal Device
773 configuration is shown below, but does not work with all tape drives. Please
774 test carefully before putting either into production. 
775
776 Note, for FreeBSD 4.10-RELEASE, using a Sony TSL11000 L100 DDS4 with an
777 autochanger set to variable block size and DCLZ compression, Brian McDonald
778 reports that to get Bacula to append correctly between Bacula executions,
779 the correct values to use are:
780
781 \footnotesize
782 \begin{verbatim}
783 mt \  -f \  /dev/nsa0 \  seteotmodel \  1
784 mt \  -f \  /dev/nsa0 \  blocksize \  0
785 mt \  -f \ /dev/nsa0 \  comp \  enable
786 \end{verbatim}
787 \normalsize
788
789 and 
790
791 \footnotesize
792 \begin{verbatim}
793   Hardware End of Medium = no
794   BSF at EOM = no
795   Backward Space Record = no
796   Backward Space File = no
797   Fast Forward Space File = yes
798   TWO EOF = no
799 \end{verbatim}
800 \normalsize
801
802 This has been confirmed by several other people using different hardware. This
803 configuration is the preferred one because it uses one EOF and no backspacing
804 at the end of the tape, which works much more efficiently and reliably with
805 modern tape drives. 
806
807 Finally, here is a Device configuration that Danny Butroyd reports to work
808 correctly with the Overland Powerloader tape library using LT0-2 and
809 FreeBSD 5.4-Stable:
810
811 \footnotesize
812 \begin{verbatim}
813 # Overland Powerloader LT02 - 17 slots single drive
814 Device {
815   Name = Powerloader
816   Media Type = LT0-2
817   Archive Device = /dev/nsa0
818   AutomaticMount = yes;              
819   AlwaysOpen = yes;
820   RemovableMedia = yes;
821   RandomAccess = no;
822   Changer Command = "/usr/local/sbin/mtx-changer %c %o %S %a %d"
823   Changer Device = /dev/pass2
824   AutoChanger = yes
825   Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"
826
827   # FreeBSD Specific Settings
828   Offline On Unmount = no
829   Hardware End of Medium = no
830   BSF at EOM = yes
831   Backward Space Record = no
832   Fast Forward Space File = no
833   TWO EOF = yes
834 }
835 \end{verbatim}
836 \normalsize
837
838
839 \subsubsection*{Determining What Tape Drives and Autochangers You Have on
840 FreeBSD}
841 \index[general]{FreeBSD!Determining What Tape Drives and Autochangers You Have
842 }
843 \index[general]{Determining What Tape Drives and Autochangers You Have on
844 FreeBSD }
845 \addcontentsline{toc}{subsubsection}{Determining What Tape Drives and
846 Autochangers You Have on FreeBSD}
847
848 On FreeBSD, you can do a {\bf camcontrol devlist} as root to determine what
849 drives and autochangers you have. For example, 
850
851 \footnotesize
852 \begin{verbatim}
853 undef# camcontrol devlist
854     at scbus0 target 2 lun 0 (pass0,sa0)
855     at scbus0 target 4 lun 0 (pass1,sa1)
856     at scbus0 target 4 lun 1 (pass2)
857 \end{verbatim}
858 \normalsize
859
860 from the above, you can determine that there is a tape drive on {\bf /dev/sa0}
861 and another on {\bf /dev/sa1} in addition since there is a second line for the
862 drive on {\bf /dev/sa1}, you know can assume that it is the control device for
863 the autochanger (i.e. {\bf /dev/pass2}). It is also the control device name to
864 use when invoking the tapeinfo program. E.g. 
865
866 \footnotesize
867 \begin{verbatim}
868 tapeinfo -f /dev/pass2
869 \end{verbatim}
870 \normalsize
871
872 \label{onstream}
873
874 \subsubsection*{Using the OnStream driver on Linux Systems}
875 \index[general]{Using the OnStream driver on Linux Systems }
876 \index[general]{Systems!Using the OnStream driver on Linux }
877 \addcontentsline{toc}{subsubsection}{Using the OnStream driver on Linux
878 Systems}
879
880 Bacula version 1.33 (not 1.32x) is now working and ready for testing with the
881 OnStream kernel osst driver version 0.9.14 or above. Osst is available from: 
882 \elink{http://sourceforge.net/projects/osst/}{http://sourceforge.net/projects/%
883 osst/}. 
884
885 To make Bacula work you must first load the new driver then, as root, do: 
886
887 \footnotesize
888 \begin{verbatim}
889   mt -f /dev/nosst0 defblksize 32768
890 \end{verbatim}
891 \normalsize
892
893 Also you must add the following to your Device resource in your Storage
894 daemon's conf file: 
895
896 \footnotesize
897 \begin{verbatim}
898  Minimum Block Size = 32768
899  Maximum Block Size = 32768
900 \end{verbatim}
901 \normalsize
902
903 Here is a Device specification provided by Michel Meyers that is known to
904 work: 
905
906 \footnotesize
907 \begin{verbatim}
908 Device {
909   Name = "Onstream DI-30"
910   Media Type = "ADR-30"
911   Archive Device = /dev/nosst0
912   Minimum Block Size = 32768
913   Maximum Block Size = 32768
914   Hardware End of Medium = yes
915   BSF at EOM = no
916   Backward Space File = yes
917   Fast Forward Space File = yes
918   Two EOF = no
919   AutomaticMount = yes
920   AlwaysOpen = yes
921   Removable Media = yes
922 }
923 \end{verbatim}
924 \normalsize
925
926 \label{fill}
927 \subsubsection*{Using btape to Simulate Filling a Tape}
928 \index[general]{Using btape to Simulate Filling a Tape }
929 \index[general]{Tape!Using btape to Simulate Filling a }
930 \addcontentsline{toc}{subsubsection}{Using btape to Simulate Filling a
931 Tape}
932
933 Because there are often problems with certain tape drives or systems when end
934 of tape conditions occur, {\bf btape} has a special command {\bf fill} that
935 causes it to write random data to a tape until the tape fills. It then writes
936 at least one more Bacula block to a second tape. Finally, it reads back both
937 tapes to ensure that the data has been written in a way that Bacula can
938 recover it. Note, there is also a single tape option as noted below, which you
939 should use rather than the two tape test. See below for more details. 
940
941 This can be an extremely time consuming process (here it is about 6 hours) to
942 fill a full tape. Note, that btape writes random data to the tape when it is
943 filling it. This has two consequences: 1. it takes a bit longer to generate
944 the data, especially on slow CPUs. 2. the total amount of data is
945 approximately the real physical capacity of your tape, regardless of whether
946 or not the tape drive compression is on or off. This is because random data
947 does not compress very much. 
948
949 To begin this test, you enter the {\bf fill} command and follow the
950 instructions. There are two options: the simple single tape option and the
951 multiple tape option. Please use only the simple single tape option because
952 the multiple tape option still doesn't work totally correctly. If the single
953 tape option does not succeed, you should correct the problem before using
954 Bacula. 
955 \label{RecoveringFiles}
956
957 \subsection*{Recovering Files Written to Tape With Fixed Block Sizes}
958 \index[general]{Recovering Files Written to Tape With Fixed Block Sizes }
959 \index[general]{Sizes!Recovering Files Written to Tape With Fixed Block }
960 \addcontentsline{toc}{subsection}{Recovering Files Written to Tape With Fixed
961 Block Sizes}
962
963 If you have been previously running your tape drive in fixed block mode
964 (default 512) and Bacula with variable blocks (default), then in version
965 1.32f-x and 1.34 and above, Bacula will fail to recover files because it does
966 block spacing, and because the block sizes don't agree between your tape drive
967 and Bacula it will not work. 
968
969 The long term solution is to run your drive in variable block mode as
970 described above. However, if you have written tapes using fixed block sizes,
971 this can be a bit of a pain. The solution to the problem is: while you are
972 doing a restore command using a tape written in fixed block size, ensure that
973 your drive is set to the fixed block size used while the tape was written.
974 Then when doing the {\bf restore} command in the Console program, do not
975 answer the prompt {\bf yes/mod/no}. Instead, edit the bootstrap file (the
976 location is listed in the prompt) using any ASCII editor. Remove all {\bf
977 VolBlock} lines in the file. When the file is re-written, answer the question,
978 and Bacula will run without using block positioning, and it should recover
979 your files. 
980
981 \label{BlockModes}
982 \subsection*{Tape Blocking Modes}
983 \index[general]{Modes!Tape Blocking }
984 \index[general]{Tape Blocking Modes }
985 \addcontentsline{toc}{subsection}{Tape Blocking Modes}
986
987 SCSI tapes may either be written in {\bf variable} or {\bf fixed} block sizes.
988 Newer drives support both modes, but some drives such as the QIC devices
989 always use fixed block sizes. Bacula attempts to fill and write complete
990 blocks (default 65K), so that in normal mode (variable block size), Bacula
991 will always write blocks of the same size except the last block of a Job. If
992 Bacula is configured to write fixed block sizes, it will pad the last block of
993 the Job to the correct size. Bacula expects variable tape block size drives to
994 behave as follows: Each write to the drive results in a single record being
995 written to the tape. Each read returns a single record. If you request less
996 bytes than are in the record, only those number of bytes will be returned, but
997 the entire logical record will have been read (the next read will retrieve the
998 next record). Thus data from a single write is always returned in a single
999 read, and sequentially written records are returned by sequential reads. 
1000
1001 Bacula expects fixed block size tape drives to behave as follows: If a write
1002 length is greater than the physical block size of the drive, the write will be
1003 written as two blocks each of the fixed physical size. This single write may
1004 become multiple physical records on the tape. (This is not a good situation).
1005 According to the documentation, one may never write an amount of data that is
1006 not the exact multiple of the blocksize (it is not specified if an error
1007 occurs or if the the last record is padded). When reading, it is my
1008 understanding that each read request reads one physical record from the tape.
1009 Due to the complications of fixed block size tape drives, you should avoid
1010 them if possible with Bacula, or you must be ABSOLUTELY certain that you use
1011 fixed block sizes within Bacula that correspond to the physical block size of
1012 the tape drive. This will ensure that Bacula has a one to one correspondence
1013 between what it writes and the physical record on the tape. 
1014
1015 Please note that Bacula will not function correctly if it writes a block and
1016 that block is split into two or more physical records on the tape. Bacula
1017 assumes that each write causes a single record to be written, and that it can
1018 sequentially recover each of the blocks it has written by using the same
1019 number of sequential reads as it had written. 
1020
1021 \subsection*{Autochanger Errors}
1022 \index[general]{Errors!Autochanger }
1023 \index[general]{Autochanger Errors }
1024 \addcontentsline{toc}{subsection}{Autochanger Errors}
1025
1026 If you are getting errors such as:
1027
1028 \footnotesize
1029 \begin{verbatim}
1030 3992 Bad autochanger "load slot 1, drive 1": ERR=Child exited with code 1.
1031 \end{verbatim}
1032 \normalsize
1033
1034 and you are running your Storage daemon as non-root, then most likely
1035 you are having permissions problems with the control channel. Running
1036 as root, set permissions on /dev/sgX so that the userid and group of
1037 your Storage daemon can access the device. You need to ensure that you
1038 all access to the proper control device, and if you don't have any
1039 SCSI disk drives (including SATA drives), you might want to change
1040 the permissions on /dev/sg*.