]> git.sur5r.net Git - bacula/docs/blob - docs/manual/progs.tex
- Litle fix
[bacula/docs] / docs / manual / progs.tex
1 %%
2 %%
3
4 \section*{Volume Utility Tools}
5 \label{_ChapterStart9}
6 \index[general]{Volume Utility Tools }
7 \index[general]{Tools!Volume Utility }
8 \addcontentsline{toc}{section}{Volume Utility Tools}
9
10 This document describes the utility programs written to aid Bacula users and
11 developers in dealing with Volumes external to Bacula. 
12
13 \subsection*{Specifying the Configuration File}
14 \index[general]{Specifying the Configuration File }
15 \addcontentsline{toc}{subsection}{Specifying the Configuration File}
16
17 Starting with version 1.27, each of the following programs requires a valid
18 Storage daemon configuration file (actually, the only part of the
19 configuration file that these programs need is the {\bf Device} resource
20 definitions). This permits the programs to find the configuration parameters
21 for your archive device (generally a tape drive). By default, they read {\bf
22 bacula-sd.conf} in the current directory, but you may specify a different
23 configuration file using the {\bf -c} option. 
24
25 \subsection*{Specifying a Device Name For a Tape}
26 \index[general]{Tape!Specifying a Device Name For a }
27 \index[general]{Specifying a Device Name For a Tape }
28 \addcontentsline{toc}{subsection}{Specifying a Device Name For a Tape}
29
30 Each of these programs require a {\bf device-name} where the Volume can be
31 found. In the case of a tape, this is the physical device name such as {\bf
32 /dev/nst0} or {\bf /dev/rmt/0ubn} depending on your system. For the program to
33 work, it must find the identical name in the Device resource of the
34 configuration file. See below for specifying Volume names. 
35
36 \subsection*{Specifying a Device Name For a File}
37 \index[general]{File!Specifying a Device Name For a }
38 \index[general]{Specifying a Device Name For a File }
39 \addcontentsline{toc}{subsection}{Specifying a Device Name For a File}
40
41 If you are attempting to read or write an archive file rather than a tape, the
42 {\bf device-name} should be the full path to the archive location including
43 the filename. The filename (last part of the specification) will be stripped
44 and used as the Volume name, and the path (first part before the filename)
45 must have the same entry in the configuration file. So, the path is equivalent
46 to the archive device name, and the filename is equivalent to the volume name.
47
48
49 \subsection*{Specifying Volumes}
50 \index[general]{Volumes!Specifying }
51 \index[general]{Specifying Volumes }
52 \addcontentsline{toc}{subsection}{Specifying Volumes}
53
54 In general, you must specify the Volume name to each of the programs below
55 (with the exception of {\bf btape}). The best method to do so is to specify a
56 {\bf bootstrap} file on the command line with the {\bf -b} option. As part of
57 the bootstrap file, you will then specify the Volume name or Volume names if
58 more than one volume is needed. For example, suppose you want to read tapes
59 {\bf tape1} and {\bf tape2}. First construct a {\bf bootstrap} file named say,
60 {\bf list.bsr} which contains: 
61
62 \footnotesize
63 \begin{verbatim}
64 Volume=test1|test2
65 \end{verbatim}
66 \normalsize
67
68 where each Volume is separated by a vertical bar. Then simply use: 
69
70 \footnotesize
71 \begin{verbatim}
72 ./bls -b list.bsr /dev/nst0
73 \end{verbatim}
74 \normalsize
75
76 In the case of Bacula Volumes that are on files, you may simply append volumes
77 as follows: 
78
79 \footnotesize
80 \begin{verbatim}
81 ./bls /tmp/test1\|test2
82 \end{verbatim}
83 \normalsize
84
85 where the backslash (\textbackslash{}) was necessary as a shell escape to
86 permit entering the vertical bar (|). 
87
88 And finally, if you feel that specifying a Volume name is a bit complicated
89 with a bootstrap file, you can use the {\bf -V} option (on all programs except
90 {\bf bcopy}) to specify one or more Volume names separated by the vertical bar
91 (|). For example, 
92
93 \footnotesize
94 \begin{verbatim}
95 ./bls -V Vol001 /dev/nst0
96 \end{verbatim}
97 \normalsize
98
99 You may also specify an asterisk (*) to indicate that the program should
100 accept any volume. For example: 
101
102 \footnotesize
103 \begin{verbatim}
104 ./bls -V* /dev/nst0
105 \end{verbatim}
106 \normalsize
107
108 \subsection*{bls}
109 \label{bls}
110 \index[general]{bls }
111 \addcontentsline{toc}{subsection}{bls}
112
113 {\bf bls} can be used to do an {\bf ls} type listing of a {\bf Bacula} tape or
114 file. It is called: 
115
116 \footnotesize
117 \begin{verbatim}
118 Usage: bls [options] <device-name>
119        -b <file>       specify a bootstrap file
120        -c <file>       specify a config file
121        -d <level>      specify debug level
122        -e <file>       exclude list
123        -i <file>       include list
124        -j              list jobs
125        -k              list blocks
126     (no j or k option) list saved files
127        -L              dump label
128        -p              proceed inspite of errors
129        -v              be verbose
130        -V              specify Volume names (separated by |)
131        -?              print this message
132 \end{verbatim}
133 \normalsize
134
135 For example, to list the contents of a tape: 
136
137 \footnotesize
138 \begin{verbatim}
139 ./bls -V Volume-name /dev/nst0
140 \end{verbatim}
141 \normalsize
142
143 Or to list the contents of a file: 
144
145 \footnotesize
146 \begin{verbatim}
147 ./bls /tmp/Volume-name
148 or
149 ./bls -V Volume-name /tmp
150 \end{verbatim}
151 \normalsize
152
153 Note that, in the case of a file, the Volume name becomes the filename, so in
154 the above example, you will replace the {\bf xxx} with the name of the volume
155 (file) you wrote. 
156
157 Normally if no options are specified, {\bf bls} will produce the equivalent
158 output to the {\bf ls -l} command for each file on the tape. Using other
159 options listed above, it is possible to display only the Job records, only the
160 tape blocks, etc. For example: 
161
162 \footnotesize
163 \begin{verbatim}
164  
165 ./bls /tmp/File002
166 bls: butil.c:148 Using device: /tmp
167 drwxrwxr-x   3 k  k  4096 02-10-19 21:08  /home/kern/bacula/k/src/dird/
168 drwxrwxr-x   2 k  k  4096 02-10-10 18:59  /home/kern/bacula/k/src/dird/CVS/
169 -rw-rw-r--   1 k  k    54 02-07-06 18:02  /home/kern/bacula/k/src/dird/CVS/Root
170 -rw-rw-r--   1 k  k    16 02-07-06 18:02  /home/kern/bacula/k/src/dird/CVS/Repository
171 -rw-rw-r--   1 k  k  1783 02-10-10 18:59  /home/kern/bacula/k/src/dird/CVS/Entries
172 -rw-rw-r--   1 k  k 97506 02-10-18 21:07  /home/kern/bacula/k/src/dird/Makefile
173 -rw-r--r--   1 k  k  3513 02-10-18 21:02  /home/kern/bacula/k/src/dird/Makefile.in
174 -rw-rw-r--   1 k  k  4669 02-07-06 18:02  /home/kern/bacula/k/src/dird/README-config
175 -rw-r--r--   1 k  k  4391 02-09-14 16:51  /home/kern/bacula/k/src/dird/authenticate.c
176 -rw-r--r--   1 k  k  3609 02-07-07 16:41  /home/kern/bacula/k/src/dird/autoprune.c
177 -rw-rw-r--   1 k  k  4418 02-10-18 21:03  /home/kern/bacula/k/src/dird/bacula-dir.conf
178 ...
179 -rw-rw-r--   1 k  k    83 02-08-31 19:19  /home/kern/bacula/k/src/dird/.cvsignore
180 bls: Got EOF on device /tmp
181 84 files found.
182 \end{verbatim}
183 \normalsize
184
185 \subsubsection*{Listing Jobs}
186 \index[general]{Listing Jobs with bls }
187 \index[general]{bls!Listing Jobs }
188 \addcontentsline{toc}{subsubsection}{bls Listing Jobs}
189
190 If you are listing a Volume to determine what Jobs to restore, normally the
191 {\bf -j} option provides you with most of what you will need as long as you
192 don't have multiple clients. For example, 
193
194 \footnotesize
195 \begin{verbatim}
196 ./bls -j -V Test1 -c stored.conf DDS-4
197 bls: butil.c:258 Using device: "DDS-4" for reading.
198 11-Jul 11:54 bls: Ready to read from volume "Test1" on device "DDS-4" (/dev/nst0).
199 Volume Record: File:blk=0:1 SessId=4 SessTime=1121074625 JobId=0 DataLen=165
200 Begin Job Session Record: File:blk=0:2 SessId=4 SessTime=1121074625 JobId=1 Level=F Type=B
201 Begin Job Session Record: File:blk=0:3 SessId=5 SessTime=1121074625 JobId=5 Level=F Type=B
202 Begin Job Session Record: File:blk=0:6 SessId=3 SessTime=1121074625 JobId=2 Level=F Type=B
203 Begin Job Session Record: File:blk=0:13 SessId=2 SessTime=1121074625 JobId=4 Level=F Type=B
204 End Job Session Record: File:blk=0:99 SessId=3 SessTime=1121074625 JobId=2 Level=F Type=B
205    Files=168 Bytes=1,732,978 Errors=0 Status=T
206 End Job Session Record: File:blk=0:101 SessId=2 SessTime=1121074625 JobId=4 Level=F Type=B
207    Files=168 Bytes=1,732,978 Errors=0 Status=T
208 End Job Session Record: File:blk=0:108 SessId=5 SessTime=1121074625 JobId=5 Level=F Type=B
209    Files=168 Bytes=1,732,978 Errors=0 Status=T
210 End Job Session Record: File:blk=0:109 SessId=4 SessTime=1121074625 JobId=1 Level=F Type=B
211    Files=168 Bytes=1,732,978 Errors=0 Status=T
212 11-Jul 11:54 bls: End of Volume at file 1 on device "DDS-4" (/dev/nst0), Volume "Test1"
213 11-Jul 11:54 bls: End of all volumes.
214 \end{verbatim}
215 \normalsize
216
217 shows a full save followed by two incremental saves. 
218
219 Adding the {\bf -v} option will display virtually all information that is
220 available for each record: 
221
222 \subsubsection*{Listing Blocks}
223 \index[general]{Listing Blocks with bls }
224 \index[general]{bls!Listing Blocks }
225 \addcontentsline{toc}{subsubsection}{bls Listing Blocks}
226
227 Normally, except for debugging purposes, you will not need to list Bacula
228 blocks (the ``primitive'' unit of Bacula data on the Volume). However, you can
229 do so with: 
230
231 \footnotesize
232 \begin{verbatim}
233 ./bls -k /tmp/File002
234 bls: butil.c:148 Using device: /tmp
235 Block: 1 size=64512
236 Block: 2 size=64512
237 ...
238 Block: 65 size=64512
239 Block: 66 size=19195
240 bls: Got EOF on device /tmp
241 End of File on device
242 \end{verbatim}
243 \normalsize
244
245 By adding the {\bf -v} option, you can get more information, which can be
246 useful in knowing what sessions were written to the volume: 
247
248 \footnotesize
249 \begin{verbatim}
250 ./bls -k -v /tmp/File002
251 Volume Label:
252 Id                : Bacula 0.9 mortal
253 VerNo             : 10
254 VolName           : File002
255 PrevVolName       :
256 VolFile           : 0
257 LabelType         : VOL_LABEL
258 LabelSize         : 147
259 PoolName          : Default
260 MediaType         : File
261 PoolType          : Backup
262 HostName          :
263 Date label written: 2002-10-19 at 21:16
264 Block: 1 blen=64512 First rec FI=VOL_LABEL SessId=1 SessTim=1035062102 Strm=0 rlen=147
265 Block: 2 blen=64512 First rec FI=6 SessId=1 SessTim=1035062102 Strm=DATA rlen=4087
266 Block: 3 blen=64512 First rec FI=12 SessId=1 SessTim=1035062102 Strm=DATA rlen=5902
267 Block: 4 blen=64512 First rec FI=19 SessId=1 SessTim=1035062102 Strm=DATA rlen=28382
268 ...
269 Block: 65 blen=64512 First rec FI=83 SessId=1 SessTim=1035062102 Strm=DATA rlen=1873
270 Block: 66 blen=19195 First rec FI=83 SessId=1 SessTim=1035062102 Strm=DATA rlen=2973
271 bls: Got EOF on device /tmp
272 End of File on device
273 \end{verbatim}
274 \normalsize
275
276 Armed with the SessionId and the SessionTime, you can extract just about
277 anything. 
278
279 If you want to know even more, add a second {\bf -v} to the command line to
280 get a dump of every record in every block. 
281
282 \footnotesize
283 \begin{verbatim}
284 ./bls -k -v -v /tmp/File002
285 bls: block.c:79 Dump block  80f8ad0: size=64512 BlkNum=1
286                Hdrcksum=b1bdfd6d cksum=b1bdfd6d
287 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=VOL_LABEL Strm=0 len=147 p=80f8b40
288 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=SOS_LABEL Strm=-7 len=122 p=80f8be7
289 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=1 Strm=UATTR len=86 p=80f8c75
290 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=2 Strm=UATTR len=90 p=80f8cdf
291 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=3 Strm=UATTR len=92 p=80f8d4d
292 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=3 Strm=DATA len=54 p=80f8dbd
293 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=3 Strm=MD5 len=16 p=80f8e07
294 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=4 Strm=UATTR len=98 p=80f8e2b
295 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=4 Strm=DATA len=16 p=80f8ea1
296 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=4 Strm=MD5 len=16 p=80f8ec5
297 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=5 Strm=UATTR len=96 p=80f8ee9
298 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=5 Strm=DATA len=1783 p=80f8f5d
299 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=5 Strm=MD5 len=16 p=80f9668
300 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=UATTR len=95 p=80f968c
301 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=DATA len=32768 p=80f96ff
302 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=DATA len=32768 p=8101713
303 bls: block.c:79 Dump block  80f8ad0: size=64512 BlkNum=2
304                Hdrcksum=9acc1e7f cksum=9acc1e7f
305 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=contDATA len=4087 p=80f8b40
306 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=DATA len=31970 p=80f9b4b
307 bls: block.c:92    Rec: VId=1 VT=1035062102 FI=6 Strm=MD5 len=16 p=8101841
308 ...
309 \end{verbatim}
310 \normalsize
311
312 \subsection*{bextract}
313 \label{bextract}
314 \index[general]{Bextract }
315 \addcontentsline{toc}{subsection}{bextract}
316
317 Normally, you will restore files by running a {\bf Restore} Job from the {\bf
318 Console} program. However, {\bf bextract} can be used to extract a single file
319 or a list of files from a Bacula tape or file. In fact, {\bf bextract} can be
320 a useful tool to restore files to an empty system assuming you are able to
321 boot, you have statically linked {\bf bextract} and you have an appropriate
322 {\bf bootstrap} file. 
323
324 It is called: 
325
326 \footnotesize
327 \begin{verbatim}
328  
329 Usage: bextract [-d debug_level] <device-name> <directory-to-store-files>
330        -b <file>       specify a bootstrap file
331        -dnn            set debug level to nn
332        -e <file>       exclude list
333        -i <file>       include list
334        -p              proceed inspite of I/O errors
335        -V              specify Volume names (separated by |)
336        -?              print this message
337 \end{verbatim}
338 \normalsize
339
340 where {\bf device-name} is the Archive Device (raw device name or full
341 filename) of the device to be read, and {\bf directory-to-store-files} is a
342 path prefix to prepend to all the files restored. 
343
344 NOTE: On Windows systems, if you specify a prefix of say d:/tmp, any file that
345 would have been restored to {\bf c:/My Documents} will be restored to {\bf
346 d:/tmp/My Documents}. That is, the original drive specification will be
347 stripped. If no prefix is specified, the file will be restored to the original
348 drive. 
349
350 \subsubsection*{Extracting with Include or Exclude Lists}
351 \index[general]{Lists!Extracting with Include or Exclude }
352 \index[general]{Extracting with Include or Exclude Lists }
353 \addcontentsline{toc}{subsubsection}{Extracting with Include or Exclude Lists}
354
355 Using the {\bf -e} option, you can specify a file containing a list of files
356 to be excluded. Wildcards can be used in the exclusion list. This option will
357 normally be used in conjunction with the {\bf -i} option (see below). Both the
358 {\bf -e} and the {\bf -i} options may be specified at the same time as the
359 {\bf -b} option. The bootstrap filters will be applied first, then the include
360 list, then the exclude list. 
361
362 Likewise, and probably more importantly, with the {\bf -i} option, you can
363 specify a file that contains a list (one file per line) of files and
364 directories to include to be restored. The list must contain the full filename
365 with the path. If you specify a path name only, all files and subdirectories
366 of that path will be restored. If you specify a line containing only the
367 filename (e.g. {\bf my-file.txt}) it probably will not be extracted because
368 you have not specified the full path. 
369
370 For example, if the file {\bf include-list} contains: 
371
372 \footnotesize
373 \begin{verbatim}
374 /home/kern/bacula
375 /usr/local/bin
376 \end{verbatim}
377 \normalsize
378
379 Then the command: 
380
381 \footnotesize
382 \begin{verbatim}
383 ./bextract -i include-list -V Volume /dev/nst0 /tmp
384 \end{verbatim}
385 \normalsize
386
387 will restore from the Bacula archive {\bf /dev/nst0} all files and directories
388 in the backup from {\bf /home/kern/bacula} and from {\bf /usr/local/bin}. The
389 restored files will be placed in a file of the original name under the
390 directory {\bf /tmp} (i.e. /tmp/home/kern/bacula/... and
391 /tmp/usr/local/bin/...). 
392
393 \subsubsection*{Extracting With a Bootstrap File}
394 \index[general]{File!Extracting With a Bootstrap }
395 \index[general]{Extracting With a Bootstrap File }
396 \addcontentsline{toc}{subsubsection}{Extracting With a Bootstrap File}
397
398 The {\bf -b} option is used to specify a {\bf bootstrap} file containing the
399 information needed to restore precisely the files you want. Specifying a {\bf
400 bootstrap} file is optional but recommended because it gives you the most
401 control over which files will be restored. For more details on the {\bf
402 bootstrap} file, please see 
403 \ilink{Restoring Files with the Bootstrap File}{_ChapterStart43}
404 chapter of this document. Note, you may also use a bootstrap file produced by
405 the {\bf restore} command. For example: 
406
407 \footnotesize
408 \begin{verbatim}
409 ./bextract -b bootstrap-file /dev/nst0 /tmp
410 \end{verbatim}
411 \normalsize
412
413 The bootstrap file allows detailed specification of what files you want
414 restored (extracted). You may specify a bootstrap file and include and/or
415 exclude files at the same time. The bootstrap conditions will first be
416 applied, and then each file record seen will be compared to the include and
417 exclude lists. 
418
419 \subsubsection*{Extracting From Multiple Volumes}
420 \index[general]{Volumes!Extracting From Multiple }
421 \index[general]{Extracting From Multiple Volumes }
422 \addcontentsline{toc}{subsubsection}{Extracting From Multiple Volumes}
423
424 If you wish to extract files that span several Volumes, you can specify the
425 Volume names in the bootstrap file or you may specify the Volume names on the
426 command line by separating them with a vertical bar. See the section above
427 under the {\bf bls} program entitled {\bf Listing Multiple Volumes} for more
428 information. The same techniques apply equally well to the {\bf bextract}
429 program. 
430
431 \subsection*{bscan}
432 \label{bscan}
433 \index[general]{bscan }
434 \addcontentsline{toc}{subsection}{bscan}
435
436 The {\bf bscan} program can be used to re-create a database (catalog) from the
437 backup information written to one or more Volumes. This is normally needed
438 only if one or more Volumes have been pruned or purged from your catalog so
439 that the records on the Volume are no longer in the catalog. 
440
441 With some care, it can also be used to synchronize your existing catalog with
442 a Volume. Although we have never seen a case of bscan damaging a
443 catalog, since bscan modifies your catalog, we recommend that
444 you do a simple ASCII backup of your database before running {\bf bscan} just
445 to be sure. See 
446 \ilink{Compacting Your Database}{CompactingMySQL}. 
447
448 {\bf bscan} can also be useful in a disaster recovery situation, after the
449 loss of a hard disk, if you do not have a valid {\bf bootstrap} file for
450 reloading your system, or if a Volume has been recycled but not overwritten,
451 you can use {\bf bscan} to re-create your database, which can then be used to
452 {\bf restore} your system or a file to its previous state. 
453
454 It is called: 
455
456 \footnotesize
457 \begin{verbatim}
458  
459 Usage: bscan [options] <bacula-archive>
460        -b bootstrap   specify a bootstrap file
461        -c <file>      specify configuration file
462        -d <nn>        set debug level to nn
463        -m             update media info in database
464        -n <name>      specify the database name (default bacula)
465        -u <user>      specify database user name (default bacula)
466        -P <password>  specify database password (default none)
467        -h <host>      specify database host (default NULL)
468        -p             proceed inspite of I/O errors
469        -r             list records
470        -s             synchronize or store in database
471        -v             verbose
472        -V <Volumes>   specify Volume names (separated by |)
473        -w <dir>       specify working directory (default from conf file)
474        -?             print this message
475 \end{verbatim}
476 \normalsize
477
478 If you are using MySQL or PostgreSQL, there is no need to supply a working
479 directory since in that case, bscan knows where the databases are. However, if
480 you have provided security on your database, you may need to supply either the
481 database name ({\bf -b} option), the user name ({\bf -u} option), and/or the
482 password ({\bf -p}) options. 
483
484 As an example, let's suppose that you did a backup to Volumes ``Vol001'' 
485 and ``Vol002'', then sometime later all records of one or both those
486 Volumes
487 were pruned or purged from the
488 database. By using {\bf bscan} you can recreate the catalog entries for
489 those Volumes and then use the {\bf restore} command in the Console to restore
490 whatever you want. A command something like: 
491
492 \footnotesize
493 \begin{verbatim}
494 bscan -c bacula-sd.conf -v -V Vol001\|Vol002 /dev/nst0
495 \end{verbatim}
496 \normalsize
497
498 will give you an idea of what is going to happen without changing
499 your catalog. Of course, you may need to change the path to the Storage
500 daemon's conf file, the Volume name, and your tape (or disk) device name. This
501 command must read the entire tape, so if it has a lot of data, it may take a
502 long time, and thus you might want to immediately use the command listed
503 below. Note, if you are writing to a disk file, replace the device name with
504 the path to the directory that contains the Volumes. This must correspond to
505 the Archive Device in the conf file. 
506
507 Then to actually write or store the records in the catalog, add the {\bf -s}
508 option as follows: 
509
510 \footnotesize
511 \begin{verbatim}
512  bscan -s -m -c bacula-sd.conf -v -V Vol001\|Vol002 /dev/nst0
513 \end{verbatim}
514 \normalsize
515
516 When writing to the database, if bscan finds existing records, it will
517 generally either update them if something is wrong or leave them alone. Thus
518 if the Volumes you are scanning are all or partially in the catalog already, no
519 harm will be done to that existing data. Any missing data will simply be
520 added. 
521
522 If you have multiple tapes, you should scan them with: 
523
524 \footnotesize
525 \begin{verbatim}
526  bscan -s -m -c bacula-sd.conf -v -V Vol001\|Vol002\|Vol003 /dev/nst0
527 \end{verbatim}
528 \normalsize
529
530 You should, always try to specify the tapes in the order they are written.
531 However, bscan can handle scanning tapes that are not sequential.  Any
532 incomplete records at the end of the tape will simply be ignored in that
533 case.  If you are simply reparing an existing catalog, this may be OK, but
534 if you are creating a new catalog from scratch, it will leave your database
535 in an incorrect state.  If you do not specify all necessary Volumes on a
536 single bscan command, bscan will not be able to correctly restore the
537 records that span two volumes.  In other words, it is much better to
538 specify two or three volumes on a single bscan command rather than run
539 bscan two or three times, each with a single volume.
540
541
542 Note, the restoration process using bscan is not identical to the original
543 creation of the catalog data. This is because certain non-essential data such
544 as volume reads, volume mounts, etc is not stored on the Volume, and thus is
545 not restored by bscan. The results of bscanning are, however, perfectly valid,
546 and will permit restoration of any or all the files in the catalog using the
547 normal Bacula console commands. 
548
549 \subsubsection*{Using bscan to Compare a Volume to an existing Catalog}
550 \index[general]{Catalog!Using bscan to Compare a Volume to an existing }
551 \index[general]{Using bscan to Compare a Volume to an existing Catalog }
552 \addcontentsline{toc}{subsubsection}{Using bscan to Compare a Volume to an
553 existing Catalog}
554
555 If you wish to compare the contents of a Volume to an existing catalog without
556 changing the catalog, you can safely do so if and only if you do {\bf not}
557 specify either the {\bf -m} or the {\bf -s} options. However, at this time
558 (Bacula version 1.26), the comparison routines are not as good or as thorough
559 as they should be, so we don't particularly recommend this mode other than for
560 testing. 
561
562 \subsubsection*{Using bscan to Recreate a Catalog from a Volume}
563 \index[general]{Volume!Using bscan to Recreate a Catalog from a }
564 \index[general]{Using bscan to Recreate a Catalog from a Volume }
565 \addcontentsline{toc}{subsubsection}{Using bscan to Recreate a Catalog from a
566 Volume}
567
568 This is the mode for which {\bf bscan} is most useful. You can either {\bf
569 bscan} into a freshly created catalog, or directly into your existing catalog
570 (after having made an ASCII copy as described above). Normally, you should
571 start with a freshly created catalog that contains no data. 
572
573 Starting with a single Volume named {\bf TestVolume1}, you run a command such
574 as: 
575
576 \footnotesize
577 \begin{verbatim}
578 ./bscan -V TestVolume1 -v -s -m -c bacula-sd.conf /dev/nst0
579 \end{verbatim}
580 \normalsize
581
582 If there is more than one volume, simply append it to the first one separating
583 it with a vertical bar. You may need to precede the vertical bar with a
584 forward slash escape the shell -- e.g. {\bf
585 TestVolume1\textbackslash{}|TestVolume2 }. The {\bf -v} option was added for
586 verbose output (this can be omitted if desired). The {\bf -s} option that
587 tells {\bf bscan} to store information in the database. The physical device
588 name {\bf /dev/nst0} is specified after all the options. 
589
590 {\bf } For example, after having done a full backup of a directory, then two
591 incrementals, I reinitialized the SQLite database as described above, and
592 using the bootstrap.bsr file noted above, I entered the following command: 
593
594 \footnotesize
595 \begin{verbatim}
596 ./bscan -b bootstrap.bsr -v -s -c bacula-sd.conf /dev/nst0
597 \end{verbatim}
598 \normalsize
599
600 which produced the following output: 
601
602 \footnotesize
603 \begin{verbatim}
604 bscan: bscan.c:182 Using Database: bacula, User: bacula
605 bscan: bscan.c:673 Created Pool record for Pool: Default
606 bscan: bscan.c:271 Pool type "Backup" is OK.
607 bscan: bscan.c:632 Created Media record for Volume: TestVolume1
608 bscan: bscan.c:298 Media type "DDS-4" is OK.
609 bscan: bscan.c:307 VOL_LABEL: OK for Volume: TestVolume1
610 bscan: bscan.c:693 Created Client record for Client: Rufus
611 bscan: bscan.c:769 Created new JobId=1 record for original JobId=2
612 bscan: bscan.c:717 Created FileSet record "Kerns Files"
613 bscan: bscan.c:819 Updated Job termination record for new JobId=1
614 bscan: bscan.c:905 Created JobMedia record JobId 1, MediaId 1
615 bscan: Got EOF on device /dev/nst0
616 bscan: bscan.c:693 Created Client record for Client: Rufus
617 bscan: bscan.c:769 Created new JobId=2 record for original JobId=3
618 bscan: bscan.c:708 Fileset "Kerns Files" already exists.
619 bscan: bscan.c:819 Updated Job termination record for new JobId=2
620 bscan: bscan.c:905 Created JobMedia record JobId 2, MediaId 1
621 bscan: Got EOF on device /dev/nst0
622 bscan: bscan.c:693 Created Client record for Client: Rufus
623 bscan: bscan.c:769 Created new JobId=3 record for original JobId=4
624 bscan: bscan.c:708 Fileset "Kerns Files" already exists.
625 bscan: bscan.c:819 Updated Job termination record for new JobId=3
626 bscan: bscan.c:905 Created JobMedia record JobId 3, MediaId 1
627 bscan: Got EOF on device /dev/nst0
628 bscan: bscan.c:652 Updated Media record at end of Volume: TestVolume1
629 bscan: bscan.c:428 End of Volume. VolFiles=3 VolBlocks=57 VolBytes=10,027,437
630 \end{verbatim}
631 \normalsize
632
633 The key points to note are that {\bf bscan} prints a line when each major
634 record is created. Due to the volume of output, it does not print a line for
635 each file record unless you supply the {\bf -v} option twice or more on the
636 command line. 
637
638 In the case of a Job record, the new JobId will not normally be the same as
639 the original Jobid. For example, for the first JobId above, the new JobId is
640 1, but the original JobId is 2. This is nothing to be concerned about as it is
641 the normal nature of databases. {\bf bscan} will keep everything straight. 
642
643 Although {\bf bscan} claims that it created a Client record for Client: Rufus
644 three times, it was actually only created the first time. This is normal. 
645
646 You will also notice that it read an end of file after each Job (Got EOF on
647 device ...). Finally the last line gives the total statistics for the bscan. 
648
649 If you had added a second {\bf -v} option to the command line, Bacula would
650 have been even more verbose, dumping virtually all the details of each Job
651 record it encountered. 
652
653 Now if you start Bacula and enter a {\bf list jobs} command to the console
654 program, you will get: 
655
656 \footnotesize
657 \begin{verbatim}
658 +-------+----------+------------------+------+-----+----------+----------+---------+
659 | JobId | Name     | StartTime        | Type | Lvl | JobFiles | JobBytes | JobStat |
660 +-------+----------+------------------+------+-----+----------+----------+---------+
661 | 1     | kernsave | 2002-10-07 14:59 | B    | F   | 84       | 4180207  | T       |
662 | 2     | kernsave | 2002-10-07 15:00 | B    | I   | 15       | 2170314  | T       |
663 | 3     | kernsave | 2002-10-07 15:01 | B    | I   | 33       | 3662184  | T       |
664 +-------+----------+------------------+------+-----+----------+----------+---------+
665 \end{verbatim}
666 \normalsize
667
668 which corresponds virtually identically with what the database contained
669 before it was re-initialized and restored with bscan. All the Jobs and Files
670 found on the tape are restored including most of the Media record. The Volume
671 (Media) records restored will be marked as {\bf Full} so that they cannot be
672 rewritten without operator intervention. 
673
674 It should be noted that {\bf bscan} cannot restore a database to the exact
675 condition it was in previously because a lot of the less important information
676 contained in the database is not saved to the tape. Nevertheless, the
677 reconstruction is sufficiently complete, that you can run {\bf restore}
678 against it and get valid results. 
679
680 \subsubsection*{Using bscan to Correct the Volume File Count}
681 \index[general]{Using bscan to Correct the Volume File Count }
682 \index[general]{Count!Using bscan to Correct the Volume File }
683 \addcontentsline{toc}{subsubsection}{Using bscan to Correct the Volume File
684 Count}
685
686 If the Storage daemon crashes during a backup Job, the catalog will not be
687 properly updated for the Volume being used at the time of the crash. This
688 means that the Storage daemon will have written say 20 files on the tape, but
689 the catalog record for the Volume indicates only 19 files. 
690
691 Bacula refuses to write on a tape that contains a different number of files
692 from what is in the catalog. To correct this situation, you may run a {\bf
693 bscan} with the {\bf -m} option (but {\bf without} the {\bf -s} option) to
694 update only the final Media record for the Volumes read. 
695
696 \subsubsection*{After bscan}
697 \index[general]{After bscan }
698 \index[general]{Bscan!After }
699 \addcontentsline{toc}{subsubsection}{After bscan}
700
701 If you use {\bf bscan} to enter the contents of the Volume into an existing
702 catalog, you should be aware that the records you entered may be immediately
703 pruned during the next job, particularly if the Volume is very old or had been
704 previously purged. To avoid this, after running {\bf bscan}, you can manually
705 set the volume status (VolStatus) to {\bf Read-Only} by using the {\bf update}
706 command in the catalog. This will allow you to restore from the volume without
707 having it immediately purged. When you have restored and backed up the data,
708 you can reset the VolStatus to {\bf Used} and the Volume will be purged from
709 the catalog. 
710
711 \subsection*{bcopy}
712 \label{bcopy}
713 \index[general]{Bcopy }
714 \addcontentsline{toc}{subsection}{bcopy}
715
716 The {\bf bcopy} program can be used to copy one {\bf Bacula} archive file to
717 another. For example, you may copy a tape to a file, a file to a tape, a file
718 to a file, or a tape to a tape. For tape to tape, you will need two tape
719 drives. (a later version is planned that will buffer it to disk). In the
720 process of making the copy, no record of the information written to the new
721 Volume is stored in the catalog. This means that the new Volume, though it
722 contains valid backup data, cannot be accessed directly from existing catalog
723 entries. If you wish to be able to use the Volume with the Console restore
724 command, for example, you must first bscan the new Volume into the catalog. 
725
726 \subsubsection*{bcopy Command Options}
727 \index[general]{Options!bcopy Command }
728 \index[general]{Bcopy Command Options }
729 \addcontentsline{toc}{subsubsection}{bcopy Command Options}
730
731 \footnotesize
732 \begin{verbatim}
733 Usage: bcopy [-d debug_level] <input-archive> <output-archive>
734        -b bootstrap      specify a bootstrap file
735        -c <file>         specify configuration file
736        -dnn              set debug level to nn
737        -i                specify input Volume names (separated by |)
738        -o                specify output Volume names (separated by |)
739        -p                proceed inspite of I/O errors
740        -v                verbose
741        -w dir            specify working directory (default /tmp)
742        -?                print this message
743 \end{verbatim}
744 \normalsize
745
746 By using a {\bf bootstrap} file, you can copy parts of a Bacula archive file
747 to another archive. 
748
749 One of the objectives of this program is to be able to recover as much data as
750 possible from a damaged tape. However, the current version does not yet have
751 this feature. 
752
753 As this is a new program, any feedback on its use would be appreciated. In
754 addition, I only have a single tape drive, so I have never been able to test
755 this program with two tape drives. 
756
757 \subsection*{btape}
758 \label{btape}
759 \index[general]{Btape }
760 \addcontentsline{toc}{subsection}{btape}
761
762 This program permits a number of elementary tape operations via a tty command
763 interface. The {\bf test} command, described below, can be very useful for
764 testing older tape drive compatibility problems. Aside from initial testing of
765 tape drive compatibility with {\bf Bacula}, {\bf btape} will be mostly used by
766 developers writing new tape drivers. 
767
768 {\bf btape} can be dangerous to use with existing {\bf Bacula} tapes because
769 it will relabel a tape or write on the tape if so requested regardless that
770 the tape may contain valuable data, so please be careful and use it only on
771 blank tapes. 
772
773 To work properly, {\bf btape} needs to read the Storage daemon's configuration
774 file. As a default, it will look for {\bf bacula-sd.conf} in the current
775 directory. If your configuration file is elsewhere, please use the {\bf -c}
776 option to specify where. 
777
778 The physical device name must be specified on the command line, and this
779 same device name must be present in the Storage daemon's configuration file
780 read by {\bf btape} 
781
782 \footnotesize
783 \begin{verbatim}
784 Usage: btape [-c config_file] [-d debug_level] [device_name]
785        -c <file>   set configuration file to file
786        -dnn        set debug level to nn
787        -s          turn off signals
788        -t          open the default tape device
789        -?          print this message.
790 \end{verbatim}
791 \normalsize
792
793 \subsubsection*{Using btape to Verify your Tape Drive}
794 \index[general]{Using btape to Verify your Tape Drive }
795 \index[general]{Drive!Using btape to Verify your Tape }
796 \addcontentsline{toc}{subsubsection}{Using btape to Verify your Tape Drive}
797
798 An important reason for this program is to ensure that a Storage daemon
799 configuration file is defined so that Bacula will correctly read and write
800 tapes. 
801
802 It is highly recommended that you run the {\bf test} command before running
803 your first Bacula job to ensure that the parameters you have defined for your
804 storage device (tape drive) will permit {\bf Bacula} to function properly. You
805 only need to mount a blank tape, enter the command, and the output should be
806 reasonably self explanatory. Please see the 
807 \ilink{Tape Testing}{_ChapterStart27} Chapter of this manual for
808 the details. 
809
810 \subsubsection*{btape Commands}
811 \index[general]{Btape Commands }
812 \index[general]{Commands!btape }
813 \addcontentsline{toc}{subsubsection}{btape Commands}
814
815 The full list of commands are: 
816
817 \footnotesize
818 \begin{verbatim}
819   Command    Description
820   =======    ===========
821   bsf        backspace file
822   bsr        backspace record
823   cap        list device capabilities
824   clear      clear tape errors
825   eod        go to end of Bacula data for append
826   test       General test Bacula tape functions
827   eom        go to the physical end of medium
828   fill       fill tape, write onto second volume
829   unfill     read filled tape
830   fsf        forward space a file
831   fsr        forward space a record
832   help       print this command
833   label      write a Bacula label to the tape
834   load       load a tape
835   quit       quit btape
836   rd         read tape
837   readlabel  read and print the Bacula tape label
838   rectest    test record handling functions
839   rewind     rewind the tape
840   scan       read tape block by block to EOT and report
841   status     print tape status
842   test       test a tape for compatibility with Bacula
843   weof       write an EOF on the tape
844   wr         write a single record of 2048 bytes
845 \end{verbatim}
846 \normalsize
847
848 The most useful commands are: 
849
850 \begin{itemize}
851 \item test -- test writing records and EOF marks and  reading them back.  
852 \item fill -- completely fill a volume with records, then  write a few records
853    on a second volume, and finally,  both volumes will be read back. 
854    This command writes blocks containing random data, so your drive will
855    not be able to compress the data, and thus it is a good test of 
856    the real physical capacity of your tapes.              
857 \item readlabel -- read and dump the label on a Bacula tape.  
858 \item cap -- list the device capabilities as defined in the  configuration
859    file and as perceived by the Storage daemon. 
860    \end{itemize}
861
862 The {\bf readlabel} command can be used to display the details of a Bacula
863 tape label. This can be useful if the physical tape label was lost or damaged.
864
865
866 In the event that you want to relabel a {\bf Bacula}, you can simply use the
867 {\bf label} command which will write over any existing label. However, please
868 note for labeling tapes, we recommend that you use the {\bf label} command in
869 the {\bf Console} program since it will never overwrite a valid Bacula tape. 
870
871 \subsection*{Other Programs}
872 \index[general]{Programs!Other }
873 \index[general]{Other Programs }
874 \addcontentsline{toc}{subsection}{Other Programs}
875
876 The following programs are general utility programs and in general do not need
877 a configuration file nor a device name. 
878
879 \subsection*{bsmtp}
880 \label{bsmtp}
881 \index[general]{Bsmtp }
882 \addcontentsline{toc}{subsection}{bsmtp}
883
884 {\bf bsmtp} is a simple mail transport program that permits more flexibility
885 than the standard mail programs typically found on Unix systems. It can even
886 be used on Windows machines. 
887
888 It is called: 
889
890 \footnotesize
891 \begin{verbatim}
892 Usage: bsmtp [-f from] [-h mailhost] [-s subject] [-c copy] [recipient ...]
893        -c          set the Cc: field
894        -dnn        set debug level to nn
895        -f          set the From: field
896        -h          use mailhost:port as the bsmtp server
897        -s          set the Subject: field
898        -?          print this message.
899 \end{verbatim}
900 \normalsize
901
902 If the {\bf -f} option is not specified, {\bf bsmtp} will use your userid. If
903 the option is not specified {\bf bsmtp} will use the value in the environment
904 variable {\bf bsmtpSERVER} or if there is none {\bf localhost}. By default
905 port 25 is used. 
906
907 {\bf recipients} is a space separated list of email recipients. 
908
909 The body of the email message is read from standard input. 
910
911 An example of the use of {\bf bsmtp} would be to put the following statement
912 in the {\bf Messages} resource of your {\bf bacula-dir.conf} file. Note, these
913 commands should appear on a single line each. 
914
915 \footnotesize
916 \begin{verbatim}
917   mailcommand = "/home/bacula/bin/bsmtp -h mail.domain.com -f \"\(Bacula\) %r\"
918                  -s \"Bacula: %t %e of %c %l\" %r"
919   operatorcommand = "/home/bacula/bin/bsmtp -h mail.domain.com -f \"\(Bacula\) %r\"
920                     -s \"Bacula: Intervention needed for %j\" %r"
921 \end{verbatim}
922 \normalsize
923
924 Where you replace {\bf /home/bacula/bin} with the path to your {\bf Bacula}
925 binary directory, and you replace {\bf mail.domain.com} with the fully
926 qualified name of your bsmtp (email) server, which normally listens on port
927 25. For more details on the substitution characters (e.g. \%r) used in the
928 above line, please see the documentation of the 
929 \ilink{ MailCommand in the Messages Resource}{mailcommand}
930 chapter of this manual. 
931
932 It is HIGHLY recommended that you test one or two cases by hand to make sure
933 that the {\bf mailhost} that you specified is correct and that it will accept
934 your email requests. Since {\bf bsmtp} always uses a TCP connection rather
935 than writing in the spool file, you may find that your {\bf from} address is
936 being rejected because it does not contain a valid domain, or because your
937 message is caught in your spam filtering rules. Generally, you should specify
938 a fully qualified domain name in the {\bf from} field, and depending on
939 whether your bsmtp gateway is Exim or Sendmail, you may need to modify the
940 syntax of the from part of the message. Please test. 
941
942 When running {\bf bsmtp} by hand, you will need to terminate the message by
943 entering a ctl-d in column 1 of the last line. 
944
945 \subsection*{dbcheck}
946 \label{dbcheck}
947 \index[general]{Dbcheck }
948 \addcontentsline{toc}{subsection}{dbcheck}
949
950 {\bf dbcheck} is a simple program that will search for inconsistencies in your
951 database, and optionally fix them. The {\bf dbcheck} program can be found in
952 the {\bf \lt{}bacula-source\gt{}/src/tools} directory of the source
953 distribution. Though it is built with the make process, it is not normally
954 ``installed''. 
955
956 It is called: 
957
958 \footnotesize
959 \begin{verbatim}
960 Usage: dbcheck [-c config] [-C catalog name] [-d debug_level]     []
961        -b              batch mode
962        -C              catalog name in the director conf file
963        -c              director conf filename
964        -dnn            set debug level to nn
965        -f              fix inconsistencies
966        -v              verbose
967        -?              print this message
968 \end{verbatim}
969 \normalsize
970
971 If the {\bf -c} option is given with the Director's conf file, there is no
972 need to enter any of the command line arguments, in particular the working
973 directory as dbcheck will read them from the file. 
974
975 If the {\bf -f} option is specified, {\bf dbcheck} will repair ({\bf fix}) the
976 inconsistencies it finds. Otherwise, it will report only. 
977
978 If the {\bf -b} option is specified, {\bf dbcheck} will run in batch mode, and
979 it will proceed to examine and fix (if -f is set) all programmed inconsistency
980 checks. If the {\bf -b} option is not specified, {\bf dbcheck} will enter
981 interactive mode and prompt with the following: 
982
983 \footnotesize
984 \begin{verbatim}
985 Hello, this is the database check/correct program.
986 Please select the function you want to perform.
987      1) Toggle modify database flag
988      2) Toggle verbose flag
989      3) Repair bad Filename records
990      4) Repair bad Path records
991      5) Eliminate duplicate Filename records
992      6) Eliminate duplicate Path records
993      7) Eliminate orphaned Jobmedia records
994      8) Eliminate orphaned File records
995      9) Eliminate orphaned Path records
996     10) Eliminate orphaned Filename records
997     11) Eliminate orphaned FileSet records
998     12) Eliminate orphaned Client records
999     13) Eliminate orphaned Job records
1000     14) Eliminate all Admin records
1001     15) Eliminate all Restore records
1002     16) All (3-15)
1003     17) Quit
1004 Select function number:
1005 \end{verbatim}
1006 \normalsize
1007
1008 By entering 1 or 2, you can toggle the modify database flag (-f option) and
1009 the verbose flag (-v). It can be helpful and reassuring to turn off the modify
1010 database flag, then select one or more of the consistency checks (items 3
1011 through 9) to see what will be done, then toggle the modify flag on and re-run
1012 the check. 
1013
1014 The inconsistencies examined are the following: 
1015
1016 \begin{itemize}
1017 \item Duplicate filename records. This can happen if you accidentally run  two
1018    copies of Bacula at the same time, and they are both adding  filenames
1019    simultaneously. It is a rare occurrence, but will create  an inconsistent
1020 database. If this is the case, you will receive  error messages during Jobs
1021 warning of duplicate database records.  If you are not getting these error
1022 messages, there is no reason  to run this check. 
1023 \item Repair bad Filename records. This checks and corrects filenames  that
1024    have a trailing slash. They should not.  
1025 \item Repair bad Path records. This checks and corrects path names  that do
1026    not have a trailing slash. They should.  
1027 \item Duplicate path records. This can happen if you accidentally run  two
1028    copies of Bacula at the same time, and they are both adding  filenames
1029    simultaneously. It is a rare occurrence, but will create  an inconsistent
1030 database. See the item above for why this occurs and  how you know it is
1031 happening. 
1032 \item Orphaned JobMedia records. This happens when a Job record is deleted 
1033    (perhaps by a user issued SQL statement), but the corresponding  JobMedia
1034    record (one for each Volume used in the Job) was not deleted.  Normally, this
1035 should not happen, and even if it does, these records  generally do not take
1036 much space in your database. However, by running  this check, you can
1037 eliminate any such orphans.  
1038 \item Orphaned File records. This happens when a Job record is deleted 
1039    (perhaps by a user issued SQL statement), but the corresponding  File record
1040    (one for each Volume used in the Job) was not deleted.  Note, searching for
1041 these records can be {\bf very} time consuming (i.e.  it may take hours) for a
1042 large database. Normally this should not  happen as Bacula takes care to
1043 prevent it. Just the same, this  check can remove any orphaned File records.
1044 It is recommended that  you run this once a year since orphaned File records
1045 can take a  large amount of space in your database. 
1046 \item Orphaned Path records. This condition happens any time a directory is 
1047    deleted from your system and all associated Job records have been purged. 
1048    During standard purging (or pruning) of Job records, Bacula does  not check
1049 for orphaned Path records. As a consequence, over a period  of time, old
1050 unused Path records will tend to accumulate and use  space in your database.
1051 This check will eliminate them. It is strongly  recommended that you run this
1052 check at least once a year. 
1053 \item Orphaned Filename records. This condition happens any time a file is 
1054    deleted from your system and all associated Job records have been purged. 
1055    This can happen quite frequently as there are quite a large number  of files
1056 that are created and then deleted. In addition, if you  do a system update or
1057 delete an entire directory, there can be  a very large number of Filename
1058 records that remain in the catalog  but are no longer used.  
1059
1060 During standard purging (or pruning) of Job records, Bacula does  not check
1061 for orphaned Filename records. As a consequence, over a period  of time, old
1062 unused Filename records will accumulate and use  space in your database. This
1063 check will eliminate them. It is strongly  recommended that you run this check
1064 at least once a year, and for  large database (more than 200 Megabytes), it is
1065 probably better to  run this once every 6 months.  
1066 \item Orphaned Client records. These records can remain in the database  long
1067    after you have removed a client. 
1068 \item Orphaned Job records. If no client is defined for a job or you  do not
1069    run a job for a long time, you can accumulate old job  records. This option
1070    allow you to remove jobs that are not  attached to any client (and thus
1071 useless).  
1072 \item All Admin records. This command will remove all Admin records, 
1073    regardless of their age.  
1074 \item All Restore records. This command will remove all Restore records, 
1075    regardless of their age. 
1076    \end{itemize}
1077
1078 \subsection*{testfind}
1079 \label{testfind}
1080 \index[general]{Testfind }
1081 \addcontentsline{toc}{subsection}{testfind}
1082
1083 {\bf testfind} permits listing of files using the same search engine that is
1084 used for the {\bf Include} resource in Job resources. Note, much of the
1085 functionality of this program (listing of files to be included) is present in
1086 the 
1087 \ilink{estimate command}{estimate} in the Console program. 
1088
1089 The original use of testfind was to ensure that Bacula's file search engine
1090 was correct and to print some statistics on file name and path length.
1091 However, you may find it useful to see what bacula would do with a given {\bf
1092 Include} resource. The {\bf testfind} program can be found in the {\bf
1093 \lt{}bacula-source\gt{}/src/tools} directory of the source distribution.
1094 Though it is built with the make process, it is not normally ``installed''. 
1095
1096 It is called: 
1097
1098 \footnotesize
1099 \begin{verbatim}
1100 Usage: testfind [-d debug_level] [-] [pattern1 ...]
1101        -a          print extended attributes (Win32 debug)
1102        -dnn        set debug level to nn
1103        -           read pattern(s) from stdin
1104        -?          print this message.
1105 Patterns are used for file inclusion -- normally directories.
1106 Debug level>= 1 prints each file found.
1107 Debug level>= 10 prints path/file for catalog.
1108 Errors are always printed.
1109 Files/paths truncated is a number with len> 255.
1110 Truncation is only in the catalog.
1111 \end{verbatim}
1112 \normalsize
1113
1114 Where a pattern is any filename specification that is valid within an {\bf
1115 Include} resource definition. If none is specified, {\bf /} (the root
1116 directory) is assumed. For example: 
1117
1118 \footnotesize
1119 \begin{verbatim}
1120 ./testfind /bin
1121 \end{verbatim}
1122 \normalsize
1123
1124 Would print the following: 
1125
1126 \footnotesize
1127 \begin{verbatim}
1128 Dir: /bin
1129 Reg: /bin/bash
1130 Lnk: /bin/bash2 -> bash
1131 Lnk: /bin/sh -> bash
1132 Reg: /bin/cpio
1133 Reg: /bin/ed
1134 Lnk: /bin/red -> ed
1135 Reg: /bin/chgrp
1136 ...
1137 Reg: /bin/ipcalc
1138 Reg: /bin/usleep
1139 Reg: /bin/aumix-minimal
1140 Reg: /bin/mt
1141 Lnka: /bin/gawk-3.1.0 -> /bin/gawk
1142 Reg: /bin/pgawk
1143 Total files    : 85
1144 Max file length: 13
1145 Max path length: 5
1146 Files truncated: 0
1147 Paths truncated: 0
1148 \end{verbatim}
1149 \normalsize
1150
1151 Even though {\bf testfind} uses the same search engine as {\bf Bacula}, each
1152 directory to be listed, must be entered as a separate command line entry or
1153 entered one line at a time to standard input if the {\bf -} option was
1154 specified. 
1155
1156 Specifying a debug level of one (i.e. {\bf -d1}) on the command line will
1157 cause {\bf testfind} to print the raw filenames without showing the Bacula
1158 internal file type, or the link (if any). Debug levels of 10 or greater cause
1159 the filename and the path to be separated using the same algorithm that is
1160 used when putting filenames into the Catalog database. 
1161