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