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