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