]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/de/concepts/restore.tex
Tweak downloads report
[bacula/docs] / docs / manuals / de / concepts / restore.tex
1 %%
2 %%
3 \chapter{The Restore Command}
4 \label{RestoreChapter}
5 \index[general]{Command!Console Restore}
6 \index[general]{Console Restore Command}
7
8 \section{General}
9 \index[general]{General }
10
11 Below, we will discuss restoring files with the Console {\bf restore} command,
12 which is the recommended way of doing restoring files. It is not possible
13 to restore files by automatically starting a job as you do with Backup,
14 Verify, ... jobs.  However, in addition to the console restore command,
15 there is a standalone program named {\bf bextract}, which also permits
16 restoring files.  For more information on this program, please see the
17 \ilink{Bacula Utility Programs}{bextract} chapter of this manual. We 
18 don't particularly recommend the {\bf bextract} program because it
19 lacks many of the features of the normal Bacula restore, such as the 
20 ability to restore Win32 files to Unix systems, and the ability to
21 restore access control lists (ACL).  As a consequence, we recommend,
22 wherever possible to use Bacula itself for restores as described below.
23
24 You may also want to look at the {\bf bls} program in the same chapter,
25 which allows you to list the contents of your Volumes.  Finally, if you
26 have an old Volume that is no longer in the catalog, you can restore the
27 catalog entries using the program named {\bf bscan}, documented in the same
28 \ilink{Bacula Utility Programs}{bscan} chapter.
29
30 In general, to restore a file or a set of files, you must run a {\bf restore}
31 job. That is a job with {\bf Type = Restore}. As a consequence, you will need
32 a predefined {\bf restore} job in your {\bf bacula-dir.conf} (Director's
33 config) file. The exact parameters (Client, FileSet, ...) that you define are
34 not important as you can either modify them manually before running the job or
35 if you use the {\bf restore} command, explained below, Bacula will  
36 automatically set them for you. In fact, you can no longer simply run a restore
37 job.  You must use the restore command.                                  
38
39 Since Bacula is a network backup program, you must be aware that when you
40 restore files, it is up to you to ensure that you or Bacula have selected the
41 correct Client and the correct hard disk location for restoring those files.
42 {\bf Bacula} will quite willingly backup client A, and restore it by sending
43 the files to a different directory on client B. Normally, you will want to
44 avoid this, but assuming the operating systems are not too different in their
45 file structures, this should work perfectly well, if so desired. 
46 By default, Bacula will restore data to the same Client that was backed
47 up, and those data will be restored not to the original places but to
48 {\bf /tmp/bacula-restores}.  You may modify any of these defaults when the
49 restore command prompts you to run the job by selecting the {\bf mod}
50 option.
51
52 \label{Example1}
53 \section{The Restore Command}
54 \index[general]{Command!Restore}
55 \index[general]{Restore Command}
56
57 Since Bacula maintains a catalog of your files and on which Volumes (disk or
58 tape), they are stored, it can do most of the bookkeeping work, allowing you
59 simply to specify what kind of restore you want (current, before a particular
60 date), and what files to restore. Bacula will then do the rest. 
61
62 This is accomplished using the {\bf restore} command in the Console. First you
63 select the kind of restore you want, then the JobIds are selected,
64 the File records for those Jobs are placed in an internal Bacula directory
65 tree, and the restore enters a file selection mode that allows you to
66 interactively walk up and down the file tree selecting individual files to be
67 restored. This mode is somewhat similar to the standard Unix {\bf restore}
68 program's interactive file selection mode. 
69
70 If a Job's file records have been pruned from the catalog, the {\bf
71 restore} command will be unable to find any files to restore.  See below
72 for more details on this.
73
74 Within the Console program, after entering the {\bf restore} command, you are
75 presented with the following selection prompt:  
76
77 \footnotesize
78 \begin{verbatim}
79 First you select one or more JobIds that contain files
80 to be restored. You will be presented several methods
81 of specifying the JobIds. Then you will be allowed to
82 select which files from those JobIds are to be restored.
83 To select the JobIds, you have the following choices:
84      1: List last 20 Jobs run
85      2: List Jobs where a given File is saved
86      3: Enter list of comma separated JobIds to select
87      4: Enter SQL list command
88      5: Select the most recent backup for a client
89      6: Select backup for a client before a specified time
90      7: Enter a list of files to restore
91      8: Enter a list of files to restore before a specified time
92      9: Find the JobIds of the most recent backup for a client
93     10: Find the JobIds for a backup for a client before a specified time
94     11: Enter a list of directories to restore for found JobIds
95     12: Cancel
96 Select item:  (1-12):
97 \end{verbatim}
98 \normalsize
99
100 There are a lot of options, and as a point of reference, most people will
101 want to slect item 5 (the most recent backup for a client). The details
102 of the above options are:
103
104 \begin{itemize}
105 \item Item 1 will list the last 20 jobs run. If you find the Job you want,
106    you can then select item 3 and enter its JobId(s).
107
108 \item Item 2 will list all the Jobs where a specified file is saved.  If you
109    find the Job you want, you can then select item 3 and enter the JobId.
110
111 \item Item 3 allows you the enter a list of comma separated JobIds whose 
112    files will be put into the directory tree. You may then select which
113    files from those JobIds to restore. Normally, you would use this option
114    if you have a particular version of a file that you want to restore and
115    you know its JobId. The most common options (5 and 6) will not select
116    a job that did not terminate normally, so if you know a file is 
117    backed up by a Job that failed (possibly because of a system crash), you
118    can access it through this option by specifying the JobId. 
119
120 \item Item 4 allows you to enter any arbitrary SQL command.  This is
121    probably the most primitive way of finding the desired JobIds, but at
122    the same time, the most flexible.  Once you have found the JobId(s), you
123    can select item 3 and enter them.
124
125 \item Item 5 will automatically select the most recent Full backup and all
126    subsequent incremental and differential backups for a specified Client.
127    These are the Jobs and Files which, if reloaded, will restore your
128    system to the most current saved state.  It automatically enters the
129    JobIds found into the directory tree in an optimal way such that only
130    the most recent copy of any particular file found in the set of Jobs
131    will be restored.  This is probably the most convenient of all the above
132    options to use if you wish to restore a selected Client to its most
133    recent state.
134
135    There are two important things to note. First, this automatic selection
136    will never select a job that failed (terminated with an error status).
137    If you have such a job and want to recover one or more files from it,
138    you will need to explicitly enter the JobId in item 3, then choose the
139    files to restore.
140
141    If some of the Jobs that are needed to do the restore have had their 
142    File records pruned, the restore will be incomplete. Bacula currently
143    does not correctly detect this condition.  You can however, check for
144    this by looking carefully at the list of Jobs that Bacula selects and
145    prints. If you find Jobs with the JobFiles column set to zero, when
146    files should have been backed up, then you should expect problems.
147
148    If all the File records have been pruned, Bacula will realize that there
149    are no file records in any of the JobIds chosen and will inform you. It
150    will then propose doing a full restore (non-selective) of those JobIds.
151    This is possible because Bacula still knows where the beginning of the
152    Job data is on the Volumes, even if it does not know where particular
153    files are located or what their names are.
154
155 \item Item 6 allows you to specify a date and time, after which Bacula  will
156    automatically select the most recent Full backup and all  subsequent
157    incremental and differential backups that started  before the specified date
158    and time.  
159
160 \item Item 7 allows you to specify one or more filenames  (complete path
161    required) to be restored. Each filename  is entered one at a time or if you
162    prefix a filename  with the less-than symbol (\lt{}) Bacula will read that 
163    file and assume it is a list of filenames to be restored.  If you
164    prefix the filename with a question mark (?), then the filename will
165    be interpreted as an SQL table name, and Bacula will include the rows
166    of that table in the list to be restored. The table must contain the
167    JobId in the first column and the FileIndex in the second column. 
168    This table feature is intended for external programs that want to build
169    their own list of files to be restored.
170    The filename entry mode is terminated by entering a  blank line.
171
172 \item Item 8 allows you to specify a date and time before  entering the
173    filenames. See Item 7 above for more  details.
174
175 \item Item 9 allows you find the JobIds of the most recent backup for
176    a client. This is much like option 5 (it uses the same code), but
177    those JobIds are retained internally as if you had entered them
178    manually.  You may then select item 11 (see below) to restore one
179    or more directories.
180
181 \item Item 10 is the same as item 9, except that it allows you to enter
182    a before date (as with item 6). These JobIds will then be retained
183    internally.
184
185 \index[general]{Restore Directories}
186 \item Item 11 allows you to enter a list of JobIds from which you can
187    select directories to be restored. The list of JobIds can have been
188    previously created by using either item 9 or 10 on the menu.  You
189    may then enter a full path to a directory name or a filename preceded
190    by a less than sign (\lt{}). The filename should contain a list
191    of directories to be restored.  All files in those directories will
192    be restored, but if the directory contains subdirectories, nothing
193    will be restored in the subdirectory unless you explicitly enter its
194    name.
195
196 \item Item 12 allows you to cancel the restore command.  
197 \end{itemize}
198
199 As an example, suppose that we select item 5 (restore to most recent state).
200 If you have not specified a client=xxx on the command line, it
201 it will then ask for the desired Client, which on my system, will print all
202 the Clients found in the database as follows:  
203
204 \footnotesize
205 \begin{verbatim}
206 Defined clients:
207      1: Rufus
208      2: Matou
209      3: Polymatou
210      4: Minimatou
211      5: Minou
212      6: MatouVerify
213      7: PmatouVerify
214      8: RufusVerify
215      9: Watchdog
216 Select Client (File daemon) resource (1-9):
217 \end{verbatim}
218 \normalsize
219
220 You will probably have far fewer Clients than this example, and if you have
221 only one Client, it will be automatically selected.  In this case, I enter
222 {\bf Rufus} to select the Client. Then  Bacula needs to know what FileSet is
223 to be restored, so it prompts with:  
224
225 \footnotesize
226 \begin{verbatim}
227 The defined FileSet resources are:
228      1: Full Set
229      2: Other Files
230 Select FileSet resource (1-2):
231 \end{verbatim}
232 \normalsize
233
234 If you have only one FileSet defined for the Client, it will be selected
235 automatically.  I choose item 1, which is my full backup.  Normally, you
236 will only have a single FileSet for each Job, and if your machines are
237 similar (all Linux) you may only have one FileSet for all your Clients.
238
239 At this point, {\bf Bacula} has all the information it needs to find the most
240 recent set of backups. It will then query the database, which may take a bit
241 of time, and it will come up with something like the following. Note, some of
242 the columns are truncated here for presentation: 
243
244 \footnotesize
245 \begin{verbatim}
246 +-------+------+----------+-------------+-------------+------+-------+----------
247 --+
248 | JobId | Levl | JobFiles | StartTime   | VolumeName  | File | SesId |
249 VolSesTime |
250 +-------+------+----------+-------------+-------------+------+-------+----------
251 --+
252 | 1,792 | F    |  128,374 | 08-03 01:58 | DLT-19Jul02 |   67 |    18 |
253 1028042998 |
254 | 1,792 | F    |  128,374 | 08-03 01:58 | DLT-04Aug02 |    0 |    18 |
255 1028042998 |
256 | 1,797 | I    |      254 | 08-04 13:53 | DLT-04Aug02 |    5 |    23 |
257 1028042998 |
258 | 1,798 | I    |       15 | 08-05 01:05 | DLT-04Aug02 |    6 |    24 |
259 1028042998 |
260 +-------+------+----------+-------------+-------------+------+-------+----------
261 --+
262 You have selected the following JobId: 1792,1792,1797
263 Building directory tree for JobId 1792 ...
264 Building directory tree for JobId 1797 ...
265 Building directory tree for JobId 1798 ...
266 cwd is: /
267 $
268 \end{verbatim}
269 \normalsize
270
271 Depending on the number of {\bf JobFiles} for each JobId, the {\bf Building
272 directory tree ...} can take a bit of time. If you notice ath all the
273 JobFiles are zero, your Files have probably been pruned and you will not be
274 able to select any individual files -- it will be restore everything or
275 nothing.
276
277 In our example, Bacula found four Jobs that comprise the most recent backup of
278 the specified Client and FileSet. Two of the Jobs have the same JobId because
279 that Job wrote on two different Volumes. The third Job was an incremental
280 backup to the previous Full backup, and it only saved 254 Files compared to
281 128,374 for the Full backup. The fourth Job was also an incremental backup
282 that saved 15 files. 
283
284 Next Bacula entered those Jobs into the directory tree, with no files marked
285 to be restored as a default, tells you how many files are in the tree, and
286 tells you that the current working directory ({\bf cwd}) is /. Finally, Bacula
287 prompts with the dollar sign (\$) to indicate that you may enter commands to
288 move around the directory tree and to select files. 
289              
290 If you want all the files to automatically be marked when the directory
291 tree is built, you could have entered the command {\bf restore all}, or
292 at the \$ prompt, you can simply enter {\bf mark *}.
293
294 Instead of choosing item 5 on the first menu (Select the most recent backup
295 for a client), if we had chosen item 3 (Enter list of JobIds to select) and we
296 had entered the JobIds {\bf 1792,1797,1798} we would have arrived at the same
297 point.                 
298
299 One point to note, if you are manually entering JobIds, is that you must enter
300 them in the order they were run (generally in increasing JobId order). If you
301 enter them out of order and the same file was saved in two or more of the
302 Jobs, you may end up with an old version of that file (i.e. not the most
303 recent). 
304
305 Directly entering the JobIds can also permit you to recover data from
306 a Job that wrote files to tape but that terminated with an error status.
307
308 While in file selection mode, you can enter {\bf help} or a question mark (?)
309 to produce a summary of the available commands:  
310
311 \footnotesize
312 \begin{verbatim}
313  Command    Description
314   =======    ===========
315   cd         change current directory
316   count      count marked files in and below the cd
317   dir        long list current directory, wildcards allowed
318   done       leave file selection mode
319   estimate   estimate restore size
320   exit       same as done command
321   find       find files, wildcards allowed
322   help       print help
323   ls         list current directory, wildcards allowed
324   lsmark     list the marked files in and below the cd
325   mark       mark dir/file to be restored recursively in dirs
326   markdir    mark directory name to be restored (no files)
327   pwd        print current working directory
328   unmark     unmark dir/file to be restored recursively in dir
329   unmarkdir  unmark directory name only no recursion
330   quit       quit and do not do restore
331   ?          print help
332 \end{verbatim}
333 \normalsize
334
335 As a default no files have been selected for restore (unless you
336 added {\bf all} to the command line. If you want to restore
337 everything, at this point, you should enter {\bf mark *}, and then {\bf done}
338 and {\bf Bacula} will write the bootstrap records to a file and request your
339 approval to start a restore job. 
340
341 If you do not enter the above mentioned {\bf mark *} command, you will start
342 with an empty slate. Now you can simply start looking at the tree and {\bf
343 mark} particular files or directories you want restored. It is easy to make
344 a mistake in specifying a file to mark or unmark, and Bacula's error handling
345 is not perfect, so please check your work by using the {\bf ls} or {\bf dir}
346 commands to see what files are actually selected. Any selected file has its
347 name preceded by an asterisk. 
348
349 To check what is marked or not marked, enter the {\bf count} command, which
350 displays:  
351
352 \footnotesize
353 \begin{verbatim}
354 128401 total files. 128401 marked to be restored.
355      
356 \end{verbatim}
357 \normalsize
358
359 Each of the above commands will be described in more detail in the next
360 section. We continue with the above example, having accepted to restore all
361 files as Bacula set by default. On entering the {\bf done} command, Bacula
362 prints:  
363
364 \footnotesize
365 \begin{verbatim}
366 Bootstrap records written to /home/kern/bacula/working/restore.bsr
367 The job will require the following   
368    Volume(s)                 Storage(s)                SD Device(s)
369 ===========================================================================
370
371    DLT-19Jul02               Tape                      DLT8000
372    DLT-04Aug02               Tape                      DLT8000
373
374 128401 files selected to restore.
375 Run Restore job
376 JobName:    kernsrestore
377 Bootstrap:  /home/kern/bacula/working/restore.bsr
378 Where:      /tmp/bacula-restores
379 Replace:    always
380 FileSet:    Other Files
381 Client:     Rufus
382 Storage:    Tape
383 When:       2006-12-11 18:20:33
384 Catalog:    MyCatalog
385 Priority:   10
386 OK to run? (yes/mod/no):
387     
388 \end{verbatim}
389 \normalsize
390
391 Please examine each of the items very carefully to make sure that they are
392 correct.  In particular, look at {\bf Where}, which tells you where in the
393 directory structure the files will be restored, and {\bf Client}, which
394 tells you which client will receive the files.  Note that by default the
395 Client which will receive the files is the Client that was backed up.
396 These items will not always be completed with the correct values depending
397 on which of the restore options you chose.  You can change any of these
398 default items by entering {\bf mod} and responding to the prompts.
399
400 The above assumes that you have defined a {\bf Restore} Job resource in your
401 Director's configuration file. Normally, you will only need one Restore Job
402 resource definition because by its nature, restoring is a manual operation,
403 and using the Console interface, you will be able to modify the Restore Job to
404 do what you want. 
405
406 An example Restore Job resource definition is given below. 
407
408 Returning to the above example, you should verify that the Client name is
409 correct before running the Job. However, you may want to modify some of the
410 parameters of the restore job. For example, in addition to checking the Client
411 it is wise to check that the Storage device chosen by Bacula is indeed
412 correct. Although the {\bf FileSet} is shown, it will be ignored in restore.
413 The restore will choose the files to be restored either by reading the {\bf
414 Bootstrap} file, or if not specified, it will restore all files associated
415 with the specified backup {\bf JobId} (i.e. the JobId of the Job that
416 originally backed up the files). 
417
418 Finally before running the job, please note that the default location for
419 restoring files is {\bf not} their original locations, but rather the directory
420 {\bf /tmp/bacula-restores}. You can change this default by modifying your {\bf
421 bacula-dir.conf} file, or you can modify it using the {\bf mod} option. If you
422 want to restore the files to their original location, you must have {\bf
423 Where} set to nothing or to the root, i.e. {\bf /}. 
424
425 If you now enter {\bf yes}, Bacula will run the restore Job. The Storage
426 daemon will first request Volume {\bf DLT-19Jul02} and after the appropriate
427 files have been restored from that volume, it will request Volume {\bf
428 DLT-04Aug02}. 
429
430 \section{Selecting Files by Filename}
431 \index[general]{Selecting Files by Filename }
432 \index[general]{Filename!Selecting Files by }
433
434 If you have a small number of files to restore, and you know the filenames,
435 you can either put the list of filenames in a file to be read by Bacula, or
436 you can enter the names one at a time. The filenames must include the full
437 path and filename. No wild cards are used. 
438
439 To enter the files, after the {\bf restore}, you select item number 7 from the
440 prompt list: 
441
442 \footnotesize
443 \begin{verbatim}
444 To select the JobIds, you have the following choices:
445      1: List last 20 Jobs run
446      2: List Jobs where a given File is saved
447      3: Enter list of comma separated JobIds to select
448      4: Enter SQL list command
449      5: Select the most recent backup for a client
450      6: Select backup for a client before a specified time
451      7: Enter a list of files to restore
452      8: Enter a list of files to restore before a specified time
453      9: Find the JobIds of the most recent backup for a client
454     10: Find the JobIds for a backup for a client before a specified time
455     11: Enter a list of directories to restore for found JobIds
456     12: Cancel
457 Select item:  (1-12):
458 \end{verbatim}
459 \normalsize
460
461 which then prompts you for the client name: 
462
463 \footnotesize
464 \begin{verbatim}
465 Defined Clients:
466      1: Timmy
467      2: Tibs
468      3: Rufus
469 Select the Client (1-3): 3
470 \end{verbatim}
471 \normalsize
472
473 Of course, your client list will be different, and if you have only one
474 client, it will be automatically selected. And finally, Bacula requests you to
475 enter a filename: 
476
477 \footnotesize
478 \begin{verbatim}
479 Enter filename:
480 \end{verbatim}
481 \normalsize
482
483 At this point, you can enter the full path and filename 
484
485 \footnotesize
486 \begin{verbatim}
487 Enter filename: /home/kern/bacula/k/Makefile.in
488 Enter filename:
489 \end{verbatim}
490 \normalsize
491
492 as you can see, it took the filename. If Bacula cannot find a copy of the
493 file, it prints the following: 
494
495 \footnotesize
496 \begin{verbatim}
497 Enter filename: junk filename
498 No database record found for: junk filename
499 Enter filename:
500 \end{verbatim}
501 \normalsize
502
503 If you want Bacula to read the filenames from a file, you simply precede the
504 filename with a less-than symbol (\lt{}). When you have entered all the
505 filenames, you enter a blank line, and Bacula will write the bootstrap file,
506 tells you what tapes will be used, and proposes a Restore job to be run: 
507
508 \footnotesize
509 \begin{verbatim}
510 Enter filename:
511 Automatically selected Storage: DDS-4
512 Bootstrap records written to /home/kern/bacula/working/restore.bsr
513 The restore job will require the following Volumes:
514    
515    test1
516 1 file selected to restore.
517 Run Restore job
518 JobName:    kernsrestore
519 Bootstrap:  /home/kern/bacula/working/restore.bsr
520 Where:      /tmp/bacula-restores
521 Replace:    always
522 FileSet:    Other Files
523 Client:     Rufus
524 Storage:    DDS-4
525 When:       2003-09-11 10:20:53
526 Priority:   10
527 OK to run? (yes/mod/no):
528 \end{verbatim}
529 \normalsize
530
531 It is possible to automate the selection by file by putting your list of files
532 in say {\bf /tmp/file-list}, then using the following command: 
533
534 \footnotesize
535 \begin{verbatim}
536 restore client=Rufus file=</tmp/file-list
537 \end{verbatim}
538 \normalsize
539
540 If in modifying the parameters for the Run Restore job, you find that Bacula
541 asks you to enter a Job number, this is because you have not yet specified
542 either a Job number or a Bootstrap file. Simply entering zero will allow you
543 to continue and to select another option to be modified. 
544 \label{CommandArguments}
545
546 \section{Command Line Arguments}
547 \index[general]{Arguments!Command Line }
548 \index[general]{Command Line Arguments }
549
550 If all the above sounds complicated, you will probably agree that it really
551 isn't after trying it a few times. It is possible to do everything that was
552 shown above, with the exception of selecting the FileSet, by using command
553 line arguments with a single command by entering: 
554
555 \footnotesize
556 \begin{verbatim}
557 restore client=Rufus select current all done yes
558 \end{verbatim}
559 \normalsize
560
561 The {\bf client=Rufus} specification will automatically select Rufus as the
562 client, the {\bf current} tells Bacula that you want to restore the system to
563 the most current state possible, and the {\bf yes} suppresses the final {\bf
564 yes/mod/no} prompt and simply runs the restore. 
565
566 The full list of possible command line arguments are: 
567
568 \begin{itemize}
569 \item {\bf all} -- select all Files to be restored.  
570 \item {\bf select} -- use the tree selection method.  
571 \item {\bf done} -- do not prompt the user in tree mode.  
572 \item {\bf current} -- automatically select the most current set of  backups
573    for the specified client.  
574 \item {\bf client=xxxx} -- select the specified client.  
575 \item {\bf jobid=nnn} -- specify a JobId or comma separated list of  JobIds to
576    be restored.  
577 \item {\bf before=YYYY-MM-DD HH:MM:SS} -- specify a date and time to  which
578    the system should be restored. Only Jobs started before  the specified
579    date/time will be selected, and as is the case  for {\bf current} Bacula will
580    automatically find the most  recent prior Full save and all Differential and
581    Incremental  saves run before the date you specify. Note, this command is  not
582    too user friendly in that you must specify the date/time  exactly as shown. 
583 \item {\bf file=filename} -- specify a filename to be restored. You  must
584    specify the full path and filename. Prefixing the entry  with a less-than
585    sign
586    (\lt{}) will cause Bacula to assume that the  filename is on your system and
587    contains a list of files to be  restored. Bacula will thus read the list from
588    that file. Multiple  file=xxx specifications may be specified on the command
589    line. 
590 \item {\bf jobid=nnn} -- specify a JobId to be restored. 
591 \item {\bf pool=pool-name} -- specify a Pool name to be used for selection  of
592    Volumes when specifying options 5 and 6 (restore current system,  and restore
593    current system before given date). This permits you to  have several Pools,
594    possibly one offsite, and to select the Pool to  be used for restoring.  
595 \item {\bf where=/tmp/bacula-restore} -- restore files in {\bf where} directory.
596 \item {\bf yes} -- automatically run the restore without prompting  for
597    modifications (most useful in batch scripts). 
598 \item {\bf strip\_prefix=/prod} -- remove a part of the filename when restoring.
599 \item {\bf add\_prefix=/test} -- add a prefix to all files when restoring (like
600   where) (can't be used with {\bf where=}).
601 \item {\bf add\_suffix=.old} -- add a suffix to all your files.
602 \item {\bf regexwhere=!a.pdf!a.bkp.pdf!} -- do complex filename manipulation
603   like with sed unix command. Will overwrite other filename manipulation.
604 \end{itemize}
605
606 \label{restorefilerelocation}
607 \section{Using File Relocation}
608 \index[general]{Using File Relocation}
609 \label{filerelocation}
610
611 \subsection{Introduction}
612
613 The \textbf{where=} option is simple, but not very powerful. With file
614 relocation, Bacula can restore a file to the same directory, but with a
615 different name, or in an other directory without recreating the full path.
616
617 You can also do filename and path manipulations, implemented in Bacula
618 2.1.8 or later, such as adding a suffix to all your files, renaming files
619 or directories, etc.  Theses options will overwrite {\bf where=} option.
620
621
622 For example, many users use OS snapshot features so that file
623 \texttt{/home/eric/mbox} will be backed up from the directory
624 \texttt{/.snap/home/eric/mbox}, which can complicate restores.  If you use
625 \textbf{where=/tmp}, the file will be restored to
626 \texttt{/tmp/.snap/home/eric/mbox} and you will have to move the file to
627 \texttt{/home/eric/mbox.bkp} by hand.  In this case, you could use
628 \textbf{strip\_prefix=/.snap} and \textbf{add\_suffix=.bkp} options and
629 Bacula will restore the file to its original location -- that is
630 \texttt{/home/eric/mbox}.
631
632 To use this feature, there are command line options as described in 
633 the \ilink{restore section}{restorefilerelocation} of this manual;
634 you can modify your restore job before running it; or you can
635 add options to your restore job in as described in 
636 \ilink{bacula-dir.conf}{confaddprefix}.
637
638 \begin{verbatim}
639 Parameters to modify:
640      1: Level
641      2: Storage
642 ..
643     10: File Relocation
644 ..
645 Select parameter to modify (1-12):
646
647
648 This will replace your current Where value
649      1: Strip prefix
650      2: Add prefix
651      3: Add file suffix
652      4: Enter a regexp
653      5: Test filename manipulation
654      6: Use this ?
655 Select parameter to modify (1-6):   
656 \end{verbatim}
657
658
659 \subsection{RegexWhere format}
660
661 The format is very close to that used by sed or Perl (\texttt{s/replace this/by
662   that/}) operator. A valid regexwhere expression has three fields :
663 \begin{itemize}
664 \item a search expression (with optionnal submatch)
665 \item a replacement expression (with optionnal back references \$1 to \$9)
666 \item a set of search options (only case-insensitive ``i'' at this time)
667 \end{itemize}
668
669 Each field is delimited by a separator specified by the user as the first
670 character of the expression. The separator can be one of the following:
671 \begin{verbatim}
672 <separator-keyword> = / !�; % : , ~ # = &
673 \end{verbatim}
674
675 You can use several expressions separated by a commas.
676
677 \subsection*{Examples}
678
679 \begin{tabular}{|c|c|c|l}
680 \hline
681 Orignal filename & Computed filename  & RegexWhere  & Comments \\
682 \hline
683 \hline
684 \texttt{c:/system.ini} & \texttt{c:/system.old.ini} & \texttt{/.ini\$/.old.ini/} & use \$ as end of filename\\
685 \hline
686 \texttt{/prod/u01/pdata/} & \texttt{/rect/u01/rdata}  & \texttt{/prod/rect/,/pdata/rdata/} & using two regexp\\
687 \hline
688 \texttt{/prod/u01/pdata/} & \texttt{/rect/u01/rdata}  & \texttt{!/prod/!/rect/!,/pdata/rdata/} & using \texttt{!} instead of \texttt{/}\\
689 \hline
690 \texttt{C:/WINNT} & \texttt{d:/WINNT}  & \texttt{/c:/d:/i} & using case-insensitive pattern matching \\
691 \hline
692
693 \end{tabular}
694
695 %\subsubsection{Using group}
696 %
697 %Like with Perl or Sed, you can make submatch with \texttt{()}, 
698 %
699 %\subsubsection*{Examples}
700
701
702 %\subsubsection{Options}
703 %
704 %       i   Do case-insensitive pattern matching.
705
706 \section{Restoring Directory Attributes}
707 \index[general]{Attributes!Restoring Directory }
708 \index[general]{Restoring Directory Attributes }
709
710 Depending how you do the restore, you may or may not get the directory entries
711 back to their original state. Here are a few of the problems you can
712 encounter, and for same machine restores, how to avoid them. 
713
714 \begin{itemize}
715 \item You backed up on one machine and are restoring to another that is 
716    either a different OS or doesn't have the same users/groups defined.  Bacula
717    does the best it can in these situations. Note, Bacula has saved the
718    user/groups in numeric form, which means on a different machine, they
719    may map to different user/group names.
720
721 \item You are restoring into a directory that is already created and has
722    file creation restrictions.  Bacula tries to reset everything but
723    without walking up the full chain of directories and modifying them all
724    during the restore, which Bacula does and will not do, getting
725    permissions back correctly in this situation depends to a large extent
726    on your OS.
727
728 \item You are doing a recursive restore of a directory tree.  In this case
729    Bacula will restore a file before restoring the file's parent directory
730    entry.  In the process of restoring the file Bacula will create the
731    parent directory with open permissions and ownership of the file being
732    restored.  Then when Bacula tries to restore the parent directory Bacula
733    sees that it already exists (Similar to the previous situation).  If you
734    had set the Restore job's "Replace" property to "never" then Bacula will
735    not change the directory's permissions and ownerships to match what it
736    backed up, you should also notice that the actual number of files
737    restored is less then the expected number.  If you had set the Restore
738    job's "Replace" property to "always" then Bacula will change the
739    Directory's ownership and permissions to match what it backed up, also
740    the actual number of files restored should be equal to the expected
741    number.
742
743 \item You selected one or more files in a directory, but did not select the
744    directory entry to be restored.  In that case, if the directory is not
745    on disk Bacula simply creates the directory with some default attributes
746    which may not be the same as the original.  If you do not select a
747    directory and all its contents to be restored, you can still select
748    items within the directory to be restored by individually marking those
749    files, but in that case, you should individually use the "markdir"
750    command to select all higher level directory entries (one at a time) to
751    be restored if you want the directory entries properly restored.
752
753 \item The {\bf bextract} program does not restore access control lists
754   (ACLs), nor will it restore non-portable Win32 data (default) to Unix
755   machines.
756 \end{itemize}
757
758 \label{Windows}
759 \section{Restoring on Windows}
760 \index[general]{Restoring on Windows }
761 \index[general]{Windows!Restoring on }
762
763 If you are restoring on WinNT/2K/XP systems, Bacula will restore the files
764 with the original ownerships and permissions as would be expected.  This is
765 also true if you are restoring those files to an alternate directory (using
766 the Where option in restore).  However, if the alternate directory does not
767 already exist, the Bacula File daemon (Client) will try to create it.  In
768 some cases, it may not create the directories, and if it does since the
769 File daemon runs under the SYSTEM account, the directory will be created
770 with SYSTEM ownership and permissions.  In this case, you may have problems
771 accessing the newly restored files.
772
773 To avoid this problem, you should create any alternate directory before
774 doing the restore.  Bacula will not change the ownership and permissions of
775 the directory if it is already created as long as it is not one of the
776 directories being restored (i.e.  written to tape).
777
778 The default restore location is {\bf /tmp/bacula-restores/} and if you are
779 restoring from drive {\bf E:}, the default will be 
780 {\bf /tmp/bacula-restores/e/}, so you should ensure that this directory
781 exists before doing the restore, or use the {\bf mod} option to
782 select a different {\bf where} directory that does exist.
783
784 Some users have experienced problems restoring files that participate in
785 the Active Directory. They also report that changing the userid under which
786 Bacula (bacula-fd.exe) runs, from SYSTEM to a Domain Admin userid, resolves
787 the problem.
788
789
790 \section{Restoring Files Can Be Slow}
791 \index[general]{Slow!Restoring Files Can Be }
792 \index[general]{Restoring Files Can Be Slow }
793
794 Restoring files is generally {\bf much} slower than backing them up for several
795 reasons. The first is that during a backup the tape is normally already
796 positioned and Bacula only needs to write. On the other hand, because restoring
797 files is done so rarely, Bacula keeps only the start file and block on the
798 tape for the whole job rather than on a file by file basis which would use
799 quite a lot of space in the catalog. 
800
801 Bacula will forward space to the correct file mark on the tape for the Job,
802 then forward space to the correct block, and finally sequentially read each
803 record until it gets to the correct one(s) for the file or files you want to
804 restore. Once the desired files are restored, Bacula will stop reading the
805 tape. 
806
807 Finally, instead of just reading a file for backup, during the restore, Bacula
808 must create the file, and the operating system must allocate disk space for
809 the file as Bacula is restoring it. 
810
811 For all the above reasons the restore process is generally much slower than
812 backing up (sometimes it takes three times as long).
813
814 \section{Problems Restoring Files}
815 \index[general]{Files!Problems Restoring }
816 \index[general]{Problems Restoring Files }
817
818 The most frequent problems users have restoring files are error messages such
819 as: 
820
821 \footnotesize
822 \begin{verbatim}
823 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
824 block.c:868 Volume data error at 20:0! Short block of 512 bytes on
825 device /dev/tape discarded.
826 \end{verbatim}
827 \normalsize
828
829 or 
830
831 \footnotesize
832 \begin{verbatim}
833 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
834 block.c:264 Volume data error at 20:0! Wanted ID: "BB02", got ".".
835 Buffer discarded.
836 \end{verbatim}
837 \normalsize
838
839 Both these kinds of messages indicate that you were probably running your tape
840 drive in fixed block mode rather than variable block mode. Fixed block mode
841 will work with any program that reads tapes sequentially such as tar, but
842 Bacula repositions the tape on a block basis when restoring files because this
843 will speed up the restore by orders of magnitude when only a few files are being
844 restored. There are several ways that you can attempt to recover from this
845 unfortunate situation. 
846
847 Try the following things, each separately, and reset your Device resource to
848 what it is now after each individual test: 
849
850 \begin{enumerate}
851 \item Set "Block Positioning = no" in your Device resource  and try the
852    restore. This is a new directive and untested. 
853
854 \item Set "Minimum Block Size = 512" and "Maximum  Block Size = 512" and
855    try the restore.  If you are able to determine the block size your drive
856    was previously using, you should try that size if 512 does not work.
857    This is a really horrible solution, and it is not at all recommended
858    to continue backing up your data without correcting this condition.
859    Please see the Tape Testing chapter for more on this.
860
861 \item Try editing the restore.bsr file at the Run xxx yes/mod/no prompt 
862    before starting the restore job and remove all the VolBlock statements.
863    These are what causes Bacula to reposition the tape, and where problems
864    occur if you have a fixed block size set for your drive.  The VolFile
865    commands also cause repositioning, but this will work regardless of the
866    block size.
867
868 \item Use bextract to extract the files you want -- it reads the  Volume
869    sequentially if you use the include list feature, or if you use a .bsr
870    file, but remove all the VolBlock statements after the .bsr file is
871    created (at the Run yes/mod/no) prompt but before you start the restore.
872 \end{enumerate}
873
874 \section{Restore Errors}
875 \index[general]{Errors!Restore}
876 \index[general]{Restore Errors}
877
878 There are a number of reasons why there may be restore errors or
879 warning messages. Some of the more common ones are:
880
881 \begin{description}
882
883 \item [file count mismatch]
884   This can occur for the following reasons:
885   \begin{itemize}
886   \item You requested Bacula not to overwrite existing or newer
887      files.
888   \item A Bacula miscount of files/directories. This is an
889      on-going problem due to the complications of directories,
890      soft/hard link, and such.  Simply check that all the files you
891      wanted were actually restored.
892   \end{itemize}
893
894 \item [file size error]
895    When Bacula restores files, it checks that the size of the
896    restored file is the same as the file status data it saved 
897    when starting the backup of the file. If the sizes do not
898    agree, Bacula will print an error message. This size mismatch
899    most often occurs because the file was being written as Bacula
900    backed up the file. In this case, the size that Bacula
901    restored will be greater than the status size.  This often
902    happens with log files.
903
904    If the restored size is smaller, then you should be concerned
905    about a possible tape error and check the Bacula output as
906    well as your system logs.
907 \end{description}
908
909
910
911 \section{Example Restore Job Resource}
912 \index[general]{Example Restore Job Resource }
913 \index[general]{Resource!Example Restore Job }
914
915 \footnotesize
916 \begin{verbatim}
917 Job {
918   Name = "RestoreFiles"
919   Type = Restore
920   Client = Any-client
921   FileSet = "Any-FileSet"
922   Storage = Any-storage
923   Where = /tmp/bacula-restores
924   Messages = Standard
925   Pool = Default
926 }
927 \end{verbatim}
928 \normalsize
929
930 If {\bf Where} is not specified, the default location for restoring files will
931 be their original locations. 
932 \label{Selection}
933
934 \section{File Selection Commands}
935 \index[general]{Commands!File Selection }
936 \index[general]{File Selection Commands }
937
938 After you have selected the Jobs to be restored and Bacula has created the
939 in-memory directory tree, you will enter file selection mode as indicated by
940 the dollar sign ({\bf \$}) prompt. While in this mode, you may use the
941 commands listed above. The basic idea is to move up and down the in memory
942 directory structure with the {\bf cd} command much as you normally do on the
943 system. Once you are in a directory, you may select the files that you want
944 restored. As a default no files are marked to be restored. If you wish to
945 start with all files, simply enter: {\bf cd /} and {\bf mark *}. Otherwise
946 proceed to select the files you wish to restore by marking them with the {\bf
947 mark} command. The available commands are: 
948
949 \begin{description}
950
951 \item [cd]
952    The {\bf cd} command changes the current directory to  the argument
953    specified.
954    It operates much like the Unix {\bf cd} command.  Wildcard specifications are
955    not permitted.  
956
957    Note, on Windows systems, the various drives (c:, d:, ...) are treated  like
958    a
959    directory within the file tree while in the file  selection mode. As a
960    consequence, you must do a {\bf cd c:} or  possibly in some cases a {\bf cd
961    C:} (note upper case)  to get down to the first directory.  
962
963 \item [dir]
964    \index[dir]{dir }
965    The {\bf dir} command is similar to the {\bf ls} command,  except that it
966    prints it in long format (all details). This command  can be a bit slower
967    than
968    the {\bf ls} command because it must access  the catalog database for the
969    detailed information for each file.  
970
971 \item [estimate]
972    \index[dir]{estimate }
973    The {\bf estimate} command prints a summary of  the total files in the tree,
974    how many are marked to be restored, and  an estimate of the number of bytes
975    to
976    be restored. This can be useful  if you are short on disk space on the
977    machine
978    where the files will be  restored.  
979
980 \item [find]
981    \index[dir]{find}
982    The {\bf find} command accepts one or more arguments  and displays all files
983    in the tree that match that argument. The argument  may have wildcards. It is
984    somewhat similar to the Unix command  {\bf find / -name arg}.  
985
986 \item [ls]
987    The {\bf ls} command produces a listing of all the files  contained in the
988    current directory much like the Unix {\bf ls} command.  You may specify an
989    argument containing wildcards, in which case only  those files will be
990    listed.
991
992    Any file that is marked to be restored will  have its name preceded by an
993    asterisk ({\bf *}). Directory names  will be terminated with a forward slash
994    ({\bf /}) to distinguish them  from filenames.  
995
996 \item [lsmark]
997    \index[fd]{lsmark}
998    The {\bf lsmark} command is the same as the  {\bf ls} except that it will
999    print only those files marked for  extraction. The other distinction is that
1000    it will recursively  descend into any directory selected. 
1001
1002 \item [mark]
1003    \index[dir]{mark}
1004    The {\bf mark} command allows you to mark files to be restored. It takes a
1005    single argument which is the filename  or directory name in the current
1006    directory to be marked for extraction.  The argument may be a wildcard
1007    specification, in which  case all files that match in the current directory
1008    are marked to be  restored. If the argument matches a directory rather than a
1009    file,  then the directory and all the files contained in that directory
1010    (recursively)  are marked to be restored. Any marked file will have its name 
1011    preceded with an asterisk ({\bf *}) in the output produced by the  {\bf ls}
1012 or
1013    {\bf dir} commands. Note, supplying a full path on  the mark command does not
1014    work as expected to select a file or  directory in the current directory.
1015    Also, the {\bf mark} command works  on the current and lower directories but
1016    does not touch higher level  directories.  
1017
1018    After executing the {\bf mark} command, it will print a brief summary:  
1019
1020 \footnotesize
1021 \begin{verbatim}
1022     No files marked.
1023     
1024 \end{verbatim}
1025 \normalsize
1026
1027    If no files were marked, or:  
1028
1029 \footnotesize
1030 \begin{verbatim}
1031     nn files marked.
1032     
1033 \end{verbatim}
1034 \normalsize
1035
1036    if some files are marked.  
1037
1038 \item [unmark]
1039    \index[dir]{unmark }
1040    The {\bf unmark} is identical to the {\bf mark}  command, except that it
1041    unmarks the specified file or files so that  they will not be restored. Note:
1042    the {\bf unmark} command works from  the current directory, so it does not
1043    unmark any files at a higher  level. First do a {\bf cd /} before the {\bf
1044    unmark *} command if  you want to unmark everything.  
1045
1046 \item [pwd]
1047    \index[dir]{pwd }
1048    The {\bf pwd} command prints the current working  directory. It accepts no
1049    arguments.  
1050
1051 \item [count]
1052    \index[dir]{count }
1053    The {\bf count} command prints the total files in the  directory tree and the
1054    number of files marked to be restored.  
1055
1056 \item [done]
1057    \index[dir]{done }
1058    This command terminates file selection mode.  
1059
1060 \item [exit]
1061    \index[fd]{exit }
1062    This command terminates file selection mode (the same as  done).  
1063
1064 \item [quit]
1065    \index[fd]{quit }
1066    This command terminates the file selection and does  not run the restore
1067 job. 
1068
1069
1070 \item [help]
1071    \index[fd]{help }
1072    This command prints a summary of the commands available.  
1073
1074 \item [?]
1075    This command is the same as the {\bf help} command.  
1076 \end{description}
1077
1078 \label{database_restore}
1079 \section{Restoring When Things Go Wrong}
1080 \index[general]{Restoring When Things Go Wrong }
1081 \index[general]{Restoring Your Database}
1082 \index[general]{Database!Restoring}
1083
1084 This and the following sections will try to present a few of the kinds of
1085 problems that can come up making restoring more difficult. We will try to
1086 provide a few ideas how to get out of these problem situations.
1087 In addition to what is presented here, there is more specific information
1088 on restoring a \ilink{Client}{restore_client} and your
1089 \ilink{Server}{restore_server} in the \ilink{Disaster Recovery Using
1090 Bacula}{RescueChapter} chapter of this manual.
1091
1092 \begin{description}
1093 \item[Problem]
1094    My database is broken.
1095 \item[Solution]
1096    For SQLite, use the vacuum command to try to fix the database. For either
1097    MySQL or PostgreSQL, see the vendor's documentation. They have specific tools
1098    that check and repair databases, see the \ilink{database
1099    repair}{DatabaseRepair} sections of this manual for links to vendor    
1100    information.
1101
1102    Assuming the above does not resolve the problem, you will need to restore
1103    or rebuild your catalog.  Note, if it is a matter of some
1104    inconsistencies in the Bacula tables rather than a broken database, then
1105    running \ilink{dbcheck}{dbcheck} might help, but you will need to ensure
1106    that your database indexes are properly setup.  Please see
1107    the \ilink{Database Performance Issues}{DatabasePerformance} sections
1108    of this manual for more details.
1109
1110 \item[Problem]
1111    How do I restore my catalog?
1112 \item[Solution with a Catalog backup]
1113    If you have backed up your database nightly (as you should) and you
1114    have made a bootstrap file, you can immediately load back your
1115    database (or the ASCII SQL output).  Make a copy of your current
1116    database, then re-initialize it, by running the following scripts:
1117 \begin{verbatim}
1118    ./drop_bacula_tables
1119    ./make_bacula_tables
1120 \end{verbatim}
1121    After re-initializing the database, you should be able to run 
1122    Bacula. If you now try to use the restore command, it will not 
1123    work because the database will be empty. However, you can manually
1124    run a restore job and specify your bootstrap file. You do so
1125    by entering the {bf run} command in the console and selecting the
1126    restore job.  If you are using the default bacula-dir.conf, this
1127    Job will be named {\bf RestoreFiles}. Most likely it will prompt
1128    you with something such as:
1129
1130 \footnotesize
1131 \begin{verbatim}
1132 Run Restore job
1133 JobName:    RestoreFiles
1134 Bootstrap:  /home/kern/bacula/working/restore.bsr
1135 Where:      /tmp/bacula-restores
1136 Replace:    always
1137 FileSet:    Full Set
1138 Client:     rufus-fd
1139 Storage:    File
1140 When:       2005-07-10 17:33:40
1141 Catalog:    MyCatalog
1142 Priority:   10
1143 OK to run? (yes/mod/no): 
1144 \end{verbatim}
1145 \normalsize
1146
1147    A number of the items will be different in your case.  What you want to
1148    do is: to use the mod option to change the Bootstrap to point to your
1149    saved bootstrap file; and to make sure all the other items such as
1150    Client, Storage, Catalog, and Where are correct.  The FileSet is not
1151    used when you specify a bootstrap file.  Once you have set all the
1152    correct values, run the Job and it will restore the backup of your
1153    database, which is most likely an ASCII dump. 
1154
1155    You will then need to follow the instructions for your
1156    database type to recreate the database from the ASCII backup file.
1157    See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of
1158    this manual for examples of the command needed to restore a 
1159    database from an ASCII dump (they are shown in the Compacting Your
1160    XXX Database sections).
1161     
1162    Also, please note that after you restore your database from an ASCII
1163    backup, you do NOT want to do a {\bf make\_bacula\_tables}  command, or
1164    you will probably erase your newly restored database tables.
1165
1166       
1167 \item[Solution with a Job listing]
1168    If you did save your database but did not make a bootstrap file, then
1169    recovering the database is more difficult.  You will probably need to
1170    use bextract to extract the backup copy.  First you should locate the
1171    listing of the job report from the last catalog backup.  It has
1172    important information that will allow you to quickly find your database
1173    file.  For example, in the job report for the CatalogBackup shown below,
1174    the critical items are the Volume name(s), the Volume Session Id and the
1175    Volume Session Time.  If you know those, you can easily restore your
1176    Catalog.
1177
1178 \footnotesize
1179 \begin{verbatim}
1180 22-Apr 10:22 HeadMan: Start Backup JobId 7510,
1181 Job=CatalogBackup.2005-04-22_01.10.0
1182 22-Apr 10:23 HeadMan: Bacula 1.37.14 (21Apr05): 22-Apr-2005 10:23:06
1183   JobId:                  7510
1184   Job:                    CatalogBackup.2005-04-22_01.10.00
1185   Backup Level:           Full
1186   Client:                 Polymatou
1187   FileSet:                "CatalogFile" 2003-04-10 01:24:01
1188   Pool:                   "Default"
1189   Storage:                "DLTDrive"
1190   Start time:             22-Apr-2005 10:21:00
1191   End time:               22-Apr-2005 10:23:06
1192   FD Files Written:       1
1193   SD Files Written:       1
1194   FD Bytes Written:       210,739,395
1195   SD Bytes Written:       210,739,521
1196   Rate:                   1672.5 KB/s
1197   Software Compression:   None
1198   Volume name(s):         DLT-22Apr05
1199   Volume Session Id:      11
1200   Volume Session Time:    1114075126
1201   Last Volume Bytes:      1,428,240,465
1202   Non-fatal FD errors:    0
1203   SD Errors:              0
1204   FD termination status:  OK
1205   SD termination status:  OK
1206   Termination:            Backup OK
1207 \end{verbatim}
1208 \normalsize
1209
1210   From the above information, you can manually create a bootstrap file,
1211   and then follow the instructions given above for restoring your database.
1212   A reconstructed bootstrap file for the above backup Job would look
1213   like the following:
1214
1215 \footnotesize
1216 \begin{verbatim}
1217 Volume="DLT-22Apr05"
1218 VolSessionId=11
1219 VolSessionTime=1114075126
1220 FileIndex=1-1
1221 \end{verbatim}
1222 \normalsize    
1223
1224   Where we have inserted the Volume name, Volume Session Id, and Volume
1225   Session Time that correspond to the values in the job report.  We've also
1226   used a FileIndex of one, which will always be the case providing that
1227   there was only one file backed up in the job.
1228   
1229   The disadvantage of this bootstrap file compared to what is created when
1230   you ask for one to be written, is that there is no File and Block
1231   specified, so the restore code must search all data in the Volume to find
1232   the requested file.  A fully specified bootstrap file would have the File
1233   and Blocks specified as follows:
1234
1235 \footnotesize
1236 \begin{verbatim}
1237 Volume="DLT-22Apr05"
1238 VolSessionId=11
1239 VolSessionTime=1114075126
1240 VolFile=118-118
1241 VolBlock=0-4053
1242 FileIndex=1-1
1243 \end{verbatim}
1244 \normalsize
1245
1246    Once you have restored the ASCII dump of the database,
1247    you will then to follow the instructions for your
1248    database type to recreate the database from the ASCII backup file.
1249    See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of
1250    this manual for examples of the command needed to restore a 
1251    database from an ASCII dump (they are shown in the Compacting Your
1252    XXX Database sections).
1253     
1254    Also, please note that after you restore your database from an ASCII
1255    backup, you do NOT want to do a {\bf make\_bacula\_tables}  command, or
1256    you will probably erase your newly restored database tables.
1257
1258 \item [Solution without a Job Listing]
1259    If you do not have a job listing, then it is a bit more difficult.
1260    Either you use the \ilink{bscan}{bscan} program to scan the contents
1261    of your tape into a database, which can be very time consuming 
1262    depending on the size of the tape, or you can use the \ilink{bls}{bls}
1263    program to list everything on the tape, and reconstruct a bootstrap 
1264    file from the bls listing for the file or files you want following
1265    the instructions given above.
1266
1267    There is a specific example of how to use {\bf bls} below.
1268
1269 \item [Problem]
1270    I try to restore the last known good full backup by specifying
1271    item 3 on the restore menu then the JobId to restore.  Bacula 
1272    then reports:
1273
1274 \footnotesize
1275 \begin{verbatim}
1276    1 Job 0 Files
1277 \end{verbatim}
1278 \normalsize
1279    and restores nothing.
1280
1281 \item[Solution]
1282    Most likely the File records were pruned from the database either due
1283    to the File Retention period expiring or by explicitly purging the
1284    Job. By using the "llist jobid=nn" command, you can obtain all the
1285    important information about the job:
1286
1287 \footnotesize
1288 \begin{verbatim}
1289 llist jobid=120
1290            JobId: 120
1291              Job: save.2005-12-05_18.27.33
1292         Job.Name: save
1293      PurgedFiles: 0
1294             Type: B
1295            Level: F
1296     Job.ClientId: 1
1297      Client.Name: Rufus
1298        JobStatus: T
1299        SchedTime: 2005-12-05 18:27:32
1300        StartTime: 2005-12-05 18:27:35
1301          EndTime: 2005-12-05 18:27:37
1302         JobTDate: 1133803657
1303     VolSessionId: 1
1304   VolSessionTime: 1133803624
1305         JobFiles: 236
1306        JobErrors: 0
1307  JobMissingFiles: 0
1308       Job.PoolId: 4
1309        Pool.Name: Full
1310    Job.FileSetId: 1
1311  FileSet.FileSet: BackupSet
1312 \end{verbatim}
1313 \normalsize
1314
1315    Then you can find the Volume(s) used by doing:
1316
1317 \footnotesize
1318 \begin{verbatim}
1319 sql
1320 select VolumeName from JobMedia,Media where JobId=1 and JobMedia.MediaId=Media.MediaId;
1321 \end{verbatim}
1322 \normalsize
1323
1324    Finally, you can create a bootstrap file as described in the previous
1325    problem above using this information.
1326
1327    If you are using Bacula version 1.38.0 or greater, when you select
1328    item 3 from the menu and enter the JobId, it will ask you if
1329    you would like to restore all the files in the job, and it will
1330    collect the above information and write the bootstrap file for
1331    you.
1332
1333 \item [Problem]
1334   You don't have a bootstrap file, and you don't have the Job report for
1335   the backup of your database, but you did backup the database, and you
1336   know the Volume to which it was backed up.
1337   
1338 \item [Solution]
1339   Either bscan the tape (see below for bscanning), or better use {\bf bls}
1340   to find where it is on the tape, then use {\bf bextract} to 
1341   restore the database.  For example,
1342
1343
1344 \footnotesize
1345 \begin{verbatim}
1346 ./bls -j -V DLT-22Apr05 /dev/nst0
1347 \end{verbatim}
1348 \normalsize
1349   Might produce the following output:
1350 \footnotesize
1351 \begin{verbatim}
1352 bls: butil.c:258 Using device: "/dev/nst0" for reading.
1353 21-Jul 18:34 bls: Ready to read from volume "DLT-22Apr05" on device "DLTDrive"
1354 (/dev/nst0).
1355 Volume Record: File:blk=0:0 SessId=11 SessTime=1114075126 JobId=0 DataLen=164
1356 ...
1357 Begin Job Session Record: File:blk=118:0 SessId=11 SessTime=1114075126
1358 JobId=7510
1359    Job=CatalogBackup.2005-04-22_01.10.0 Date=22-Apr-2005 10:21:00 Level=F Type=B
1360 End Job Session Record: File:blk=118:4053 SessId=11 SessTime=1114075126
1361 JobId=7510
1362    Date=22-Apr-2005 10:23:06 Level=F Type=B Files=1 Bytes=210,739,395 Errors=0
1363 Status=T
1364 ...
1365 21-Jul 18:34 bls: End of Volume at file 201 on device "DLTDrive" (/dev/nst0),
1366 Volume "DLT-22Apr05"
1367 21-Jul 18:34 bls: End of all volumes.
1368 \end{verbatim}
1369 \normalsize
1370   Of course, there will be many more records printed, but we have indicated
1371   the essential lines of output. From the information on the Begin Job and End 
1372   Job Session Records, you can reconstruct a bootstrap file such as the one
1373   shown above.
1374
1375 \item[Problem]
1376   How can I find where a file is stored.
1377 \item[Solution]
1378   Normally, it is not necessary, you just use the {\bf restore} command to
1379   restore the most recently saved version (menu option 5), or a version
1380   saved before a given date (menu option 8).  If you know the JobId of the
1381   job in which it was saved, you can use menu option 3 to enter that JobId.
1382
1383   If you would like to know the JobId where a file was saved, select
1384   restore menu option 2.
1385
1386   You can also use the {\bf query} command to find information such as: 
1387 \footnotesize
1388 \begin{verbatim}
1389 *query
1390 Available queries:
1391      1: List up to 20 places where a File is saved regardless of the
1392 directory
1393      2: List where the most recent copies of a file are saved
1394      3: List last 20 Full Backups for a Client
1395      4: List all backups for a Client after a specified time
1396      5: List all backups for a Client
1397      6: List Volume Attributes for a selected Volume
1398      7: List Volumes used by selected JobId
1399      8: List Volumes to Restore All Files
1400      9: List Pool Attributes for a selected Pool
1401     10: List total files/bytes by Job
1402     11: List total files/bytes by Volume
1403     12: List Files for a selected JobId
1404     13: List Jobs stored on a selected MediaId
1405     14: List Jobs stored for a given Volume name
1406     15: List Volumes Bacula thinks are in changer
1407     16: List Volumes likely to need replacement from age or errors
1408 Choose a query (1-16):
1409 \end{verbatim}
1410 \normalsize
1411
1412 \item[Problem]
1413   I didn't backup my database. What do I do now?
1414 \item[Solution]
1415   This is probably the worst of all cases, and you will probably have
1416   to re-create your database from scratch and then bscan in all your
1417   Volumes, which is a very long, painful, and inexact process.
1418
1419 There are basically three steps to take:
1420
1421 \begin{enumerate}
1422 \item Ensure that your SQL server is running (MySQL or PostgreSQL)
1423    and that the Bacula database (normally bacula) exists.  See the
1424    \ilink{Installation}{CreateDatabase} chapter of the manual.
1425 \item Ensure that the Bacula databases are created. This is also
1426    described at the above link.
1427 \item Start and stop the Bacula Director using the propriate
1428    bacula-dir.conf file so that it can create the Client and
1429    Storage records which are not stored on the Volumes.  Without these
1430    records, scanning is unable to connect the Job records to the proper
1431   client.
1432 \end{enumerate}
1433
1434 When the above is complete, you can begin bscanning your Volumes. Please
1435 see the \ilink{bscan}{bscan} section of the Volume Utility Tools of this
1436 chapter for more details.
1437
1438 \end{description}