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