]> git.sur5r.net Git - bacula/docs/blob - docs/manual/restore.tex
01915d59fd1f10232549735fcf074af7694c025f
[bacula/docs] / docs / manual / restore.tex
1 %%
2 %%
3
4 \section*{The Bacula Console Restore Command}
5 \label{_ChapterStart13}
6 \index[general]{Command!Bacula Console Restore }
7 \index[general]{Bacula Console Restore Command }
8 \addcontentsline{toc}{section}{Bacula Console Restore Command}
9
10 \subsection*{General}
11 \index[general]{General }
12 \addcontentsline{toc}{subsection}{General}
13
14 Below, we will discuss restoring files with the Console {\bf restore} command,
15 which is the recommended way of doing it. However, there is a standalone
16 program named {\bf bextract}, which also permits restoring files. For more
17 information on this program, please see the 
18 \ilink{Bacula Utility Programs}{bextract} chapter of this manual.
19 You will also want to look at the {\bf bls} program in the same chapter, which
20 allows you to list the contents of your Volumes. Finally, if you have an old
21 Volume that is no longer in the catalog, you can restore the catalog entries
22 using the program named {\bf bscan}, documented in the same 
23 \ilink{Bacula Utility Programs}{bextract} chapter. 
24
25 In general, to restore a file or a set of files, you must run a {\bf restore}
26 job. That is a job with {\bf Type = Restore}. As a consequence, you will need
27 a predefined {\bf restore} job in your {\bf bacula-dir.conf} (Director's
28 config) file. The exact parameters (Client, FileSet, ...) that you define are
29 not important as you can either modify them manually before running the job or
30 if you use the {\bf restore} command, explained below, Bacula will  
31 automatically set them for you. 
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 \subsection*{The Restore Command}
48 \index[general]{Command!Restore }
49 \index[general]{Restore Command }
50 \addcontentsline{toc}{subsection}{Restore Command}
51
52 Since Bacula maintains a catalog of your files and on which Volumes (disk or
53 tape), they are stored, it can do most of the bookkeeping work, allowing you
54 simply to specify what kind of restore you want (current, before a particular
55 date), and what files to restore. Bacula will then do the rest. 
56
57 This is accomplished using the {\bf restore} command in the Console. First you
58 select the kind of restore you want, then the JobIds are selected,
59 the File records for those Jobs are placed in an internal Bacula directory
60 tree, and the restore enters a file selection mode that allows you to
61 interactively walk up and down the file tree selecting individual files to be
62 restored. This mode is somewhat similar to the standard Unix {\bf restore}
63 program's interactive file selection mode. 
64
65 If your Files have been pruned, the {\bf restore} command will be unable
66 to find any files to restore. See below 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 \begin{itemize}
95 \item Item 1 will list the last 20 jobs run. If you find the Job you want,
96    you can then select item 3 and enter its JobId(s). 
97 \item Item 2 will list all the Jobs where a specified file is saved.  If you
98    find the Job you want, you can then select item 3 and enter the JobId. 
99 \item Item 3 allows you the enter a list of comma separated JobIds whose 
100    files will be put into the directory tree. You may then select which
101    files from those JobIds to restore.
102 \item Item 4 allows you to enter any arbitrary SQL command. This is  probably
103    the most primitive way of finding the desired JobIds,  but at the same time,
104    the most flexible.  Once you have found the JobId(s), you can select item 3
105    and enter  them.  
106 \item Item 5 will automatically select the most recent Full backup and all 
107    subsequent incremental and differential backups for a specified Client.
108    These are the Jobs and Files which, if reloaded, will restore your
109    system to the most current saved state.  It automatically enters the
110    JobIds found into the directory tree.  This is probably the most
111    convenient of all the above options to use if you wish to restore a
112    selected Client to its most recent state.
113
114    There are two important things to note. First, this automatic selection
115    will never select a job that failed (terminated with an error status).
116    If you have such a job and want to recover one or more files from it,
117    you will need to explicitly enter the JobId in item 3, then choose the
118    files to restore.
119
120    If some of the Jobs that are needed to do the restore have had their 
121    File records pruned, the restore will be incomplete. Bacula currently
122    does not correctly detect this condition.  You can however, check for
123    this by looking carefully at the list of Jobs that Bacula selects and
124    prints. If you find Jobs with the JobFiles column set to zero, when
125    files should have been backed up, then you should expect problems.
126
127    If all the File records have been pruned, Bacula will realize that there
128    are no file records in any of the JobIds chosen and will inform you. It
129    will then propose doing a full restore (non-selective) of those JobIds.
130    This is possible because Bacula still knows where the beginning of the
131    Job data is on the Volumes, even if it does not know where particular
132    files are located.
133
134 \item Item 6 allows you to specify a date and time, after which Bacula  will
135    automatically select the most recent Full backup and all  subsequent
136    incremental and differential backups that started  before the specified date
137   and time.  
138 \item Item 7 allows you to specify one or more filenames  (complete path
139    required) to be restored. Each filename  is entered one at a time or if you
140    prefix a filename  with the less-than symbol (\lt{}) Bacula will read that 
141    file and assume it is a list of filenames to be restored.  The filename entry
142    mode is terminated by entering a  blank line.  
143 \item Item 8 allows you to specify a date and time before  entering the
144    filenames. See Item 7 above for more  details.  
145 \item Item 9 allows you find the JobIds of the most recent backup for
146    a client. This is much like option 5 (it uses the same code), but
147    those JobIds are retained internally as if you had entered them
148    manually.  You may then select item 11 (see below) to restore one
149    or more directories.
150 \item Item 10 is the same as item 9, except that it allows you to enter
151    a before date (as with item 6). These JobIds will then be retained
152    internally.
153 \item Item 11 allows you to enter a list of JobIds from which you can
154    select directories to be restored. The list of JobIds can have been
155    previously created by using either item 9 or 10 on the menu.  You
156    may then enter a full path to a directory name or a filename preceded
157    by a less than sign (\lt{}). The filename should contain a list
158    of directories to be restored.  All files in those directories will
159    be restored, but if the directory contains subdirectories, nothing
160    will be restored in the subdirectory unless you explicitly enter its
161    name.
162 \item Item 12 allows you to cancel the restore command.  
163 \end{itemize}
164
165 As an example, suppose that we select item 5 (restore to most recent state).
166 It will then ask for the desired Client, which on my system, will print all
167 the Clients found in the database as follows:  
168
169 \footnotesize
170 \begin{verbatim}
171 Defined clients:
172      1: Rufus
173      2: Matou
174      3: Polymatou
175      4: Minimatou
176      5: Minou
177      6: MatouVerify
178      7: PmatouVerify
179      8: RufusVerify
180      9: Watchdog
181 Select Client (File daemon) resource (1-9):
182      
183 \end{verbatim}
184 \normalsize
185
186 You will probably have far fewer Clients than this example, and  if you have
187 only one Client, it will be automatically selected. In this case, I enter
188 {\bf Rufus} to select the Client. Then  Bacula needs to know what FileSet is
189 to be restored, so it  prompts with:  
190
191 \footnotesize
192 \begin{verbatim}
193 The defined FileSet resources are:
194      1: Full Set
195      2: Kerns Files
196 Select FileSet resource (1-2):
197      
198 \end{verbatim}
199 \normalsize
200
201 I choose item 1, which is my full backup. Normally, you will only have a
202 single FileSet for each Job, and if your machines are similar (all Linux) you
203 may only have one FileSet for all your Clients. 
204
205 At this point, {\bf Bacula} has all the information it needs to find the most
206 recent set of backups. It will then query the database, which may take a bit
207 of time, and it will come up with something like the following. Note, some of
208 the columns are truncated here for presentation: 
209
210 \footnotesize
211 \begin{verbatim}
212 +-------+------+----------+-------------+-------------+------+-------+----------
213 --+
214 | JobId | Levl | JobFiles | StartTime   | VolumeName  | File | SesId |
215 VolSesTime |
216 +-------+------+----------+-------------+-------------+------+-------+----------
217 --+
218 | 1,792 | F    |  128,374 | 08-03 01:58 | DLT-19Jul02 |   67 |    18 |
219 1028042998 |
220 | 1,792 | F    |  128,374 | 08-03 01:58 | DLT-04Aug02 |    0 |    18 |
221 1028042998 |
222 | 1,797 | I    |      254 | 08-04 13:53 | DLT-04Aug02 |    5 |    23 |
223 1028042998 |
224 | 1,798 | I    |       15 | 08-05 01:05 | DLT-04Aug02 |    6 |    24 |
225 1028042998 |
226 +-------+------+----------+-------------+-------------+------+-------+----------
227 --+
228 You have selected the following JobId: 1792,1792,1797
229 Building directory tree for JobId 1792 ...
230 Building directory tree for JobId 1797 ...
231 Building directory tree for JobId 1798 ...
232 cwd is: /
233 $
234 \end{verbatim}
235 \normalsize
236
237 Depending on the number of {\bf JobFiles} for each JobId, the {\bf Building
238 directory tree ...``} can take a bit of time. If you notice ath all the
239 JobFiles are zero, your Files have probably been pruned and you will not be
240 able to select any individual files -- it will be restore everything or
241 nothing.
242
243 In our example, Bacula found four Jobs that comprise the most recent backup of
244 the specified Client and FileSet. Two of the Jobs have the same JobId because
245 that Job wrote on two different Volumes. The third Job was an incremental
246 backup to the previous Full backup, and it only saved 254 Files compared to
247 128,374 for the Full backup. The fourth Job was also an incremental backup
248 that saved 15 files. 
249
250 Next Bacula entered those Jobs into the directory tree, with no files marked
251 to be restored as a default, tells you how many files are in the tree, and
252 tells you that the current working directory ({\bf cwd}) is /. Finally, Bacula
253 prompts with the dollar sign (\$) to indicate that you may enter commands to
254 move around the directory tree and to select files. 
255              
256 If you want all the files to automatically be marked when the directory
257 tree is built, enter the command {\bf restore all}.
258
259 Instead of choosing item 5 on the first menu (Select the most recent backup
260 for a client), if we had chosen item 3 (Enter list of JobIds to select) and we
261 had entered the JobIds {\bf 1792,1797,1798} we would have arrived at the same
262 point.                 
263
264 One point to note, if you are manually entering JobIds, is that you must enter
265 them in the order they were run (generally in increasing JobId order). If you
266 enter them out of order and the same file was saved in two or more of the
267 Jobs, you may end up with an old version of that file (i.e. not the most
268 recent). 
269
270 Directly entering the JobIds can also permit you to recover data from
271 a Job that wrote files to tape but that terminated with an error status.
272
273 While in file selection mode, you can enter {\bf help} or a question mark (?)
274 to produce a summary of the available commands:  
275
276 \footnotesize
277 \begin{verbatim}
278  Command    Description
279   =======    ===========
280   cd         change current directory
281   count      count marked files in and below the cd
282   dir        long list current directory, wildcards allowed
283   done       leave file selection mode
284   estimate   estimate restore size
285   exit       same as done command
286   find       find files, wildcards allowed
287   help       print help
288   ls         list current directory, wildcards allowed
289   lsmark     list the marked files in and below the cd
290   mark       mark dir/file to be restored recursively in dirs
291   markdir    mark directory name to be restored (no files)
292   pwd        print current working directory
293   unmark     unmark dir/file to be restored recursively in dir
294   unmarkdir  unmark directory name only no recursion
295   quit       quit and do not do restore
296   ?          print help
297 \end{verbatim}
298 \normalsize
299
300 As a default no files have been selected for restore (unless you
301 added {\bf all} to the command line. If you want to restore
302 everything, at this point, you should enter {\bf mark *}, and then {\bf done}
303 and {\bf Bacula} will write the bootstrap records to a file and request your
304 approval to start a restore job. 
305
306 If you do not enter the above mentioned {\bf mark *} command, you will start
307 with an empty slate. Now you can simply start looking at the tree and {\bf
308 mark} particular files or directories you want restored. It is easy to make
309 a mistake in specifying a file to mark or unmark, and Bacula's error handling
310 is not perfect, so please check your work by using the {\bf ls} or {\bf dir}
311 commands to see what files are actually selected. Any selected file has its
312 name preceded by an asterisk. 
313
314 To check what is marked or not marked, enter the {\bf count} command, which
315 displays:  
316
317 \footnotesize
318 \begin{verbatim}
319 128401 total files. 128401 marked to be restored.
320      
321 \end{verbatim}
322 \normalsize
323
324 Each of the above commands will be described in more detail in the next
325 section. We continue with the above example, having accepted to restore all
326 files as Bacula set by default. On entering the {\bf done} command, Bacula
327 prints:  
328
329 \footnotesize
330 \begin{verbatim}
331 Bootstrap records written to /home/kern/bacula/working/restore.bsr
332 The restore job will require the following Volumes:
333    
334    DLT-19Jul02
335    DLT-04Aug02
336 128401 files selected to restore.
337 Run Restore job
338 JobName:    kernsrestore
339 Bootstrap:  /home/kern/bacula/working/restore.bsr
340 Where:      /tmp/bacula-restores
341 Replace:    always
342 FileSet:    Kerns Files
343 Client:     Rufus
344 Storage:    SDT-10000
345 JobId:      *None*
346 OK to run? (yes/mod/no):
347     
348 \end{verbatim}
349 \normalsize
350
351 Please examine each of the items very carefully to make sure that they are
352 correct.  In particular, look at {\bf Where}, which tells you where in the
353 directory structure the files will be restored, and {\bf Client}, which
354 tells you which client will receive the files.  Note that by default the
355 Client which will receive the files is the Client that was backed up.
356 These items will not always be completed with the correct values depending
357 on which of the restore options you chose.  You can change any of these
358 default items by entering {\bf mod} and responding to the prompts.
359
360 The above assumes that you have defined a {\bf Restore} Job resource in your
361 Director's configuration file. Normally, you will only need one Restore Job
362 resource definition because by its nature, restoring is a manual operation,
363 and using the Console interface, you will be able to modify the Restore Job to
364 do what you want. 
365
366 An example Restore Job resource definition is given below. 
367
368 Returning to the above example, you should verify that the Client name is
369 correct before running the Job. However, you may want to modify some of the
370 parameters of the restore job. For example, in addition to checking the Client
371 it is wise to check that the Storage device chosen by Bacula is indeed
372 correct. Although the {\bf FileSet} is shown, it will be ignored in restore.
373 The restore will choose the files to be restored either by reading the {\bf
374 Bootstrap} file, or if not specified, it will restore all files associated
375 with the specified backup {\bf JobId} (i.e. the JobId of the Job that
376 originally backed up the files). 
377
378 Finally before running the job, please note that the default location for
379 restoring files is {\bf not} their original locations, but rather the directory
380 {\bf /tmp/bacula-restores}. You can change this default by modifying your {\bf
381 bacula-dir.conf} file, or you can modify it using the {\bf mod} option. If you
382 want to restore the files to their original location, you must have {\bf
383 Where} set to nothing or to the root, i.e. {\bf /}. 
384
385 If you now enter {\bf yes}, Bacula will run the restore Job. The Storage
386 daemon will first request Volume {\bf DLT-19Jul02} and after the appropriate
387 files have been restored from that volume, it will request Volume {\bf
388 DLT-04Aug02}. 
389
390 \subsection*{Selecting Files by Filename}
391 \index[general]{Selecting Files by Filename }
392 \index[general]{Filename!Selecting Files by }
393 \addcontentsline{toc}{subsection}{Selecting Files by Filename}
394
395 If you have a small number of files to restore, and you know the filenames,
396 you can either put the list of filenames in a file to be read by Bacula, or
397 you can enter the names one at a time. The filenames must include the full
398 path and filename. No wild cards are used. 
399
400 To enter the files, after the {\bf restore}, you select item number 7 from the
401 prompt list: 
402
403 \footnotesize
404 \begin{verbatim}
405 To select the JobIds, you have the following choices:
406      1: List last 20 Jobs run
407      2: List Jobs where a given File is saved
408      3: Enter list of comma separated JobIds to select
409      4: Enter SQL list command
410      5: Select the most recent backup for a client
411      6: Select backup for a client before a specified time
412      7: Enter a list of files to restore
413      8: Enter a list of files to restore before a specified time
414      9: Find the JobIds of the most recent backup for a client
415     10: Find the JobIds for a backup for a client before a specified time
416     11: Enter a list of directories to restore for found JobIds
417     12: Cancel
418 Select item:  (1-12):
419 \end{verbatim}
420 \normalsize
421
422 which then prompts you for the client name: 
423
424 \footnotesize
425 \begin{verbatim}
426 Defined Clients:
427      1: Timmy
428      2: Tibs
429      3: Rufus
430 Select the Client (1-3): 3
431 \end{verbatim}
432 \normalsize
433
434 Of course, your client list will be different, and if you have only one
435 client, it will be automatically selected. And finally, Bacula requests you to
436 enter a filename: 
437
438 \footnotesize
439 \begin{verbatim}
440 Enter filename:
441 \end{verbatim}
442 \normalsize
443
444 At this point, you can enter the full path and filename 
445
446 \footnotesize
447 \begin{verbatim}
448 Enter filename: /home/kern/bacula/k/Makefile.in
449 Enter filename:
450 \end{verbatim}
451 \normalsize
452
453 as you can see, it took the filename. If Bacula cannot find a copy of the
454 file, it prints the following: 
455
456 \footnotesize
457 \begin{verbatim}
458 Enter filename: junk filename
459 No database record found for: junk filename
460 Enter filename:
461 \end{verbatim}
462 \normalsize
463
464 If you want Bacula to read the filenames from a file, you simply precede the
465 filename with a less-than symbol (\lt{}). When you have entered all the
466 filenames, you enter a blank line, and Bacula will write the bootstrap file,
467 tells you what tapes will be used, and proposes a Restore job to be run: 
468
469 \footnotesize
470 \begin{verbatim}
471 Enter filename:
472 Automatically selected Storage: DDS-4
473 Bootstrap records written to /home/kern/bacula/working/restore.bsr
474 The restore job will require the following Volumes:
475    
476    test1
477 1 file selected to restore.
478 Run Restore job
479 JobName:    kernsrestore
480 Bootstrap:  /home/kern/bacula/working/restore.bsr
481 Where:      /tmp/bacula-restores
482 Replace:    always
483 FileSet:    Kerns Files
484 Client:     Rufus
485 Storage:    DDS-4
486 When:       2003-09-11 10:20:53
487 Priority:   10
488 OK to run? (yes/mod/no):
489 \end{verbatim}
490 \normalsize
491
492 It is possible to automate the selection by file by putting your list of files
493 in say {\bf /tmp/file-list}, then using the following command: 
494
495 \footnotesize
496 \begin{verbatim}
497 restore client=Rufus file=</tmp/file-list
498 \end{verbatim}
499 \normalsize
500
501 If in modifying the parameters for the Run Restore job, you find that Bacula
502 asks you to enter a Job number, this is because you have not yet specified
503 either a Job number or a Bootstrap file. Simply entering zero will allow you
504 to continue and to select another option to be modified. 
505 \label{CommandArguments}
506
507 \subsection*{Command Line Arguments}
508 \index[general]{Arguments!Command Line }
509 \index[general]{Command Line Arguments }
510 \addcontentsline{toc}{subsection}{Command Line Arguments}
511
512 If all the above sounds complicated, you will probably agree that it really
513 isn't after trying it a few times. It is possible to do everything that was
514 shown above, with the exception of selecting the FileSet, by using command
515 line arguments with a single command by entering: 
516
517 \footnotesize
518 \begin{verbatim}
519 restore client=Rufus select current all done yes
520 \end{verbatim}
521 \normalsize
522
523 The {\bf client=Rufus} specification will automatically select Rufus as the
524 client, the {\bf current} tells Bacula that you want to restore the system to
525 the most current state possible, and the {\bf yes} suppresses the final {\bf
526 yes/mod/no} prompt and simply runs the restore. 
527
528 The full list of possible command line arguments are: 
529
530 \begin{itemize}
531 \item {\bf all} -- select all Files to be restored.  
532 \item {\bf select} -- use the tree selection method.  
533 \item {\bf done} -- do not prompt the user in tree mode.  
534 \item {\bf current} -- automatically select the most current set of  backups
535    for the specified client.  
536 \item {\bf client=xxxx} -- select the specified client.  
537 \item {\bf jobid=nnn} -- specify a JobId or comma separated list of  JobIds to
538    be restored.  
539 \item {\bf before=YYYY-MM-DD HH:MM:SS} -- specify a date and time to  which
540    the system should be restored. Only Jobs started before  the specified
541    date/time will be selected, and as is the case  for {\bf current} Bacula will
542 automatically find the most  recent prior Full save and all Differential and
543 Incremental  saves run before the date you specify. Note, this command is  not
544 too user friendly in that you must specify the date/time  exactly as shown. 
545 \item {\bf file=filename} -- specify a filename to be restored. You  must
546    specify the full path and filename. Prefixing the entry  with a less-than
547 sign
548    (\lt{}) will cause Bacula to assume that the  filename is on your system and
549 contains a list of files to be  restored. Bacula will thus read the list from
550 that file. Multiple  file=xxx specifications may be specified on the command
551 line. 
552 \item {\bf jobid=nnn} -- specify a JobId to be restored. 
553 \item {\bf pool=pool-name} -- specify a Pool name to be used for selection  of
554    Volumes when specifying options 5 and 6 (restore current system,  and restore
555    current system before given date). This permits you to  have several Pools,
556 possibly one offsite, and to select the Pool to  be used for restoring.  
557 \item {\bf yes} -- automatically run the restore without prompting  for
558    modifications (most useful in batch scripts). 
559    \end{itemize}
560
561 \subsection*{Restoring Directory Attributes}
562 \index[general]{Attributes!Restoring Directory }
563 \index[general]{Restoring Directory Attributes }
564 \addcontentsline{toc}{subsection}{Restoring Directory Attributes}
565
566 Depending how you do the restore, you may or may not get the directory entries
567 back to their original state. Here are a few of the problems you can
568 encounter, and for same machine restores, how to avoid them. 
569
570 \begin{itemize}
571 \item You backed up on one machine and are restoring to another that is 
572    either a different OS or doesn't have the same users/groups defined.  Bacula
573    does the best it can in these situations.  
574 \item You are restoring into a directory that is already created and has  file
575    creation restrictions. Bacula tries to reset everything  but without walking
576    up the full chain of directories and modifying  them all during the restore,
577    which Bacula does and will not do,  getting permissions back correctly in
578 this
579    situation depends to a  large extent on your OS.  
580 \item You selected one or more files in a directory, but did not select  the
581    directory entry to be restored. In that case, if the directory  is not on
582 disk
583    Bacula simply creates the directory with some default  attributes which may
584    not be the same as the original.  If you do not select a directory and all
585 its
586    contents to be restored,  you can still select items within the directory to
587    be restored by  individually marking those files, but in that case, you
588 should
589    individually use the ''markdir`` command to select all higher level 
590    directory entries (one at a time) to be restored if you want the  directory
591    entries properly restored. 
592 \end{itemize}
593
594 \label{Windows}
595
596 \subsection*{Restoring on Windows}
597 \index[general]{Restoring on Windows }
598 \index[general]{Windows!Restoring on }
599 \addcontentsline{toc}{subsection}{Restoring on Windows}
600
601 If you are restoring on WinNT/2K/XP systems, Bacula will restore the files
602 with the original ownerships and permissions as would be expected.  This is
603 also true if you are restoring those files to an alternate directory (using
604 the Where option in restore).  However, if the alternate directory does not
605 already exist, the Bacula File daemon (Client) will try to create it.  In
606 some cases, it may not create the directories, and if it does since the
607 File daemon runs under the SYSTEM account, the directory will be created
608 with SYSTEM ownership and permissions.  In this case, you may have problems
609 accessing the newly restored files.
610
611 To avoid this problem, you should create any alternate directory before doing
612 the
613 restore. Bacula will not change the ownership and permissions of the directory
614 if it is already created as long as it is not one of the directories being
615 restored (i.e. written to tape). 
616
617 The default restore location is {\bf /tmp/bacula-restores/} and if you are
618 restoring from drive {\bf E:}, the default will be 
619 {\bf /tmp/bacula-restores/e/}, so you should ensure that this directory
620 exists before doing the restore, or use the {\bf mod} option to
621 select a different {\bf where} directory that does exist.
622
623 Some users have experienced problems restoring files that participate in
624 the Active Directory. They also report that changing the userid under which
625 Bacula (bacula-fd.exe) runs, from SYSTEM to a Domain Admin userid, resolves
626 the problem.
627
628
629 \subsection*{Restoring Files Can Be Slow}
630 \index[general]{Slow!Restoring Files Can Be }
631 \index[general]{Restoring Files Can Be Slow }
632 \addcontentsline{toc}{subsection}{Restoring Files Can Be Slow}
633
634 Restoring files is generally {\bf much} slower than backing it up for several
635 reasons. The first is that during a backup the tape is normally already
636 positioned and Bacula only needs to write. On the other hand, because restoring
637 files is done so rarely, Bacula keeps only the he start file and block on the
638 tape for the whole job rather than on a file by file basis which would use
639 quite a lot of space in the catalog. 
640
641 Bacula versions 1.31a and older would seek to the first file on the first
642 tape, then sequentially search the tape for the specified files. If you were
643 doing a full restore, this is OK, but if you want to restore one or two files,
644 the process could be quite long. 
645
646 This deficiency has been corrected in version 1.32. The consequence is that
647 Bacula will forward space to the correct file mark on the tape for the Job,
648 then forward space to the correct block, and finally sequentially read each
649 record until it gets to the correct one(s) for the file or files you want to
650 restore. Once the desired files are restored, Bacula will stop reading the
651 tape. For restoring a small number of files, version 1.32 and greater are
652 hundreds of times faster than previous versions. 
653
654 Finally, instead of just reading a file for backup, during the restore, Bacula
655 must create the file, and the operating system must allocate disk space for
656 the file as Bacula is restoring it. 
657
658 For all the above reasons the restore process is generally much slower than
659 backing up (sometimes it takes three times as long).
660
661 \subsection*{Problems Restoring Files}
662 \index[general]{Files!Problems Restoring }
663 \index[general]{Problems Restoring Files }
664 \addcontentsline{toc}{subsection}{Problems Restoring Files}
665
666 The most frequent problems users have restoring files are error messages such
667 as: 
668
669 \footnotesize
670 \begin{verbatim}
671 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
672 block.c:868 Volume data error at 20:0! Short block of 512 bytes on
673 device /dev/tape discarded.
674 \end{verbatim}
675 \normalsize
676
677 or 
678
679 \footnotesize
680 \begin{verbatim}
681 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
682 block.c:264 Volume data error at 20:0! Wanted ID: "BB02", got ".".
683 Buffer discarded.
684 \end{verbatim}
685 \normalsize
686
687 Both these kinds of messages indicate that you were probably running your tape
688 drive in fixed block mode rather than variable block mode. Fixed block mode
689 will work with any program that reads tapes sequentially such as tar, but
690 Bacula repositions the tape on a block basis when restoring files because this
691 will speed up the restore by orders of magnitude when only a few files are being
692 restored. There are several ways that you can attempt to recover from this
693 unfortunate situation. 
694
695 Try the following things, each separately, and reset your Device resource to
696 what it is now after each individual test: 
697
698 \begin{enumerate}
699 \item Set ''Block Positioning = no`` in your Device resource  and try the
700    restore. This is a new directive and untested. 
701 \item Set ''Minimum Block Size = 512`` and ''Maximum  Block Size = 512`` and
702    try the restore. Again send me the  full job report output. If you are able
703 to
704    determine the  block size your drive was previously using, you should try 
705    that size if 512 does not work. 
706 \item Try editing the restore.bsr file at the Run xxx yes/mod/no prompt 
707    before starting the restore job and remove all the VolBlock  statements.
708 These
709    are what causes Bacula to reposition the tape,  and where problems occur if
710    you have a fixed block size set  for your drive. The VolFile commands also
711    cause repositioning,  but this will work regardless of the block size. 
712 \item Use bextract to extract the files you want -- it reads the  Volume
713    sequentially if you use the include list feature, or  if you use a .bsr file,
714    but remove all the VolBlock statements  after the .bsr file is created (at
715 the
716    Run yes/mod/no) prompt but  before you start the restore. 
717 \end{enumerate}
718
719 \subsection*{Example Restore Job Resource}
720 \index[general]{Example Restore Job Resource }
721 \index[general]{Resource!Example Restore Job }
722 \addcontentsline{toc}{subsection}{Example Restore Job Resource}
723
724 \footnotesize
725 \begin{verbatim}
726 Job {
727   Name = "RestoreFiles"
728   Type = Restore
729   Client = Any-client
730   FileSet = "Any-FileSet"
731   Storage = Any-storage
732   Where = /tmp/bacula-restores
733   Messages = Standard
734   Pool = Default
735 }
736 \end{verbatim}
737 \normalsize
738
739 If {\bf Where} is not specified, the default location for restoring files will
740 be their original locations. 
741 \label{Selection}
742
743 \subsection*{File Selection Commands}
744 \index[general]{Commands!File Selection }
745 \index[general]{File Selection Commands }
746 \addcontentsline{toc}{subsection}{File Selection Commands}
747
748 After you have selected the Jobs to be restored and Bacula has created the
749 in-memory directory tree, you will enter file selection mode as indicated by
750 the dollar sign ({\bf \$}) prompt. While in this mode, you may use the
751 commands listed above. The basic idea is to move up and down the in memory
752 directory structure with the {\bf cd} command much as you normally do on the
753 system. Once you are in a directory, you may select the files that you want
754 restored. As a default no files are marked to be restored. If you wish to
755 start with all files, simply enter: {\bf cd /} and {\bf mark *}. Otherwise
756 proceed to select the files you wish to restore by marking them with the {\bf
757 mark} command. The available commands are: 
758
759 \begin{description}
760
761 \item [cd]
762    The {\bf cd} command changes the current directory to  the argument
763 specified.
764    It operates much like the Unix {\bf cd} command.  Wildcard specifications are
765    not permitted.  
766
767    Note, on Windows systems, the various drives (c:, d:, ...) are treated  like
768 a
769    directory within the file tree while in the file  selection mode. As a
770    consequence, you must do a {\bf cd c:} or  possibly in some cases a {\bf cd
771    C:} (note upper case)  to get down to the first directory.  
772
773 \item [dir]
774    \index[dir]{dir }
775    The {\bf dir} command is similar to the {\bf ls} command,  except that it
776    prints it in long format (all details). This command  can be a bit slower
777 than
778    the {\bf ls} command because it must access  the catalog database for the
779    detailed information for each file.  
780
781 \item [estimate]
782    \index[dir]{estimate }
783    The {\bf estimate} command prints a summary of  the total files in the tree,
784    how many are marked to be restored, and  an estimate of the number of bytes
785 to
786    be restored. This can be useful  if you are short on disk space on the
787 machine
788    where the files will be  restored.  
789
790 \item [find]
791    \index[dir]{find }
792    The {\bf find} command accepts one or more arguments  and displays all files
793    in the tree that match that argument. The argument  may have wildcards. It is
794    somewhat similar to the Unix command  {\bf find / -name arg}.  
795
796 \item [ls]
797    The {\bf ls} command produces a listing of all the files  contained in the
798    current directory much like the Unix {\bf ls} command.  You may specify an
799    argument containing wildcards, in which case only  those files will be
800 listed.
801    Any file that is marked to be restored will  have its name preceded by an
802    asterisk ({\bf *}). Directory names  will be terminated with a forward slash
803    ({\bf /}) to distinguish them  from filenames.  
804
805 \item [lsmark]
806    \index[fd]{lsmark }
807    The {\bf lsmark} command is the same as the  {\bf ls} except that it will
808    print only those files marked for  extraction. The other distinction is that
809    it will recursively  descend into any directory selected. 
810
811 \item [mark]
812    \index[dir]{mark }
813    The {\bf mark} command allows you to mark files  to be restored. It takes a
814    single argument which is the filename  or directory name in the current
815    directory to be marked for extraction.  The argument may be a wildcard
816    specification, in which  case all files that match in the current directory
817    are marked to be  restored. If the argument matches a directory rather than a
818    file,  then the directory and all the files contained in that directory
819    (recursively)  are marked to be restored. Any marked file will have its name 
820    preceded with an asterisk ({\bf *}) in the output produced by the  {\bf ls}
821 or
822    {\bf dir} commands. Note, supplying a full path on  the mark command does not
823    work as expected to select a file or  directory in the current directory.
824    Also, the {\bf mark} command works  on the current and lower directories but
825    does not touch higher level  directories.  
826
827    After executing the {\bf mark} command, it will print a brief summary:  
828
829 \footnotesize
830 \begin{verbatim}
831     No files marked.
832     
833 \end{verbatim}
834 \normalsize
835
836    If no files were marked, or:  
837
838 \footnotesize
839 \begin{verbatim}
840     nn files marked.
841     
842 \end{verbatim}
843 \normalsize
844
845    if some files are marked.  
846
847 \item [unmark]
848    \index[dir]{unmark }
849    The {\bf unmark} is identical to the {\bf mark}  command, except that it
850    unmarks the specified file or files so that  they will not be restored. Note:
851    the {\bf unmark} command works from  the current directory, so it does not
852    unmark any files at a higher  level. First do a {\bf cd /} before the {\bf
853    unmark *} command if  you want to unmark everything.  
854
855 \item [pwd]
856    \index[dir]{pwd }
857    The {\bf pwd} command prints the current working  directory. It accepts no
858    arguments.  
859
860 \item [count]
861    \index[dir]{count }
862    The {\bf count} command prints the total files in the  directory tree and the
863    number of files marked to be restored.  
864
865 \item [done]
866    \index[dir]{done }
867    This command terminates file selection mode.  
868
869 \item [exit]
870    \index[fd]{exit }
871    This command terminates file selection mode (the same as  done).  
872
873 \item [quit]
874    \index[fd]{quit }
875    This command terminates the file selection and does  not run the restore
876 job. 
877
878
879 \item [help]
880    \index[fd]{help }
881    This command prints a summary of the commands available.  
882
883 \item [?]
884    This command is the same as the {\bf help} command.  
885 \end{description}
886
887 \subsection*{Restoring When Things Go Wrong}
888 \index[general]{Restoring When Things Go Wrong }
889 \addcontentsline{toc}{subsection}{Restoring When Things Go Wrong}
890
891 This and the following sections will try to present a few of the kinds of
892 problems that can come up making restoring more difficult. I'll try to
893 provide a few ideas how to get out of these problem situations.
894
895 \begin{description}
896 \item [Problem]
897    Your catalog has been damaged and Bacula either doesn't work or prints
898    errors.
899 \item[Solution]
900    For SQLite, use the vacuum command to try to fix the database. For either
901    MySQL or PostgreSQL, see the vendor's documentation. They have specific tools
902    that check and repair databases.
903
904    Assuming the above does not resolve the problem, you will need to restore
905    or rebuild your catalog.
906 \item[Problem]
907    How do I restore my catalog?
908 \item[Solution]
909    If you have backed up your database nightly (as you should) and you
910    have made a bootstrap file, you can immediately load back your
911    database (or the ASCII SQL output).  Make a copy of your current
912    database, then re-initialize it, by running the following scripts:
913 \begin{verbatim}
914    ./drop_bacula_tables
915    ./make_bacula_tables
916 \end{verbatim}
917    After re-initializing the database, you should be able to run 
918    Bacula. If you now try to use the restore command, it will not 
919    work because the database will be empty. However, you can manually
920    run a restore job and specify your bootstrap file. You do so
921    by entering the {bf run} command in the console and selecting the
922    restore job.  If you are using the default bacula-dir.conf, this
923    Job will be named {\bf RestoreFiles}. Most likely it will prompt
924    you with something such as:
925 \footnotesize
926 \begin{verbatim}
927 Run Restore job
928 JobName:    RestoreFiles
929 Bootstrap:  /home/kern/bacula/working/restore.bsr
930 Where:      /tmp/bacula-restores
931 Replace:    always
932 FileSet:    Full Set
933 Client:     rufus-fd
934 Storage:    File
935 When:       2005-07-10 17:33:40
936 Catalog:    MyCatalog
937 Priority:   10
938 OK to run? (yes/mod/no): 
939 \end{verbatim}
940 \normalsize
941    A number of the items will be different in your case. What you want
942    to do is: to use the mod option to change the Bootstrap to point to 
943    your saved bootstrap file; and to make sure all the other items
944    such as Client, Storage, Catalog, and Where are correct. The
945    FileSet is not used when you specify a bootstrap file.
946    Once you have set all the correct values, run the Job and
947    it will restore the backup of your database. You will then
948    need to follow the instructions for your database type to
949    recreate the database from the ASCII backup file.
950
951       
952 \item[Solution]
953    If you did save your database but did not make a bootstrap file, then 
954    recovering the database 
955    is more difficult. You will probably need to use bextract to extract the
956    backup copy.
957    First you should locate the listing of the job report from the last catalog
958    backup.  It has important information that will allow you to quickly find
959    your database file.  For example, in the job report for the CatalogBackup
960    shown below, the critical items are the Volume name(s), the Volume Session Id
961    and the Volume Session Time.  If you know those, you can easily restore your
962    Catalog.
963 \footnotesize
964 \begin{verbatim}
965
966 22-Apr 10:22 HeadMan: Start Backup JobId 7510,
967 Job=CatalogBackup.2005-04-22_01.10.0
968 22-Apr 10:23 HeadMan: Bacula 1.37.14 (21Apr05): 22-Apr-2005 10:23:06
969   JobId:                  7510
970   Job:                    CatalogBackup.2005-04-22_01.10.00
971   Backup Level:           Full
972   Client:                 Polymatou
973   FileSet:                "CatalogFile" 2003-04-10 01:24:01
974   Pool:                   "Default"
975   Storage:                "DLTDrive"
976   Start time:             22-Apr-2005 10:21:00
977   End time:               22-Apr-2005 10:23:06
978   FD Files Written:       1
979   SD Files Written:       1
980   FD Bytes Written:       210,739,395
981   SD Bytes Written:       210,739,521
982   Rate:                   1672.5 KB/s
983   Software Compression:   None
984   Volume name(s):         DLT-22Apr05
985   Volume Session Id:      11
986   Volume Session Time:    1114075126
987   Last Volume Bytes:      1,428,240,465
988   Non-fatal FD errors:    0
989   SD Errors:              0
990   FD termination status:  OK
991   SD termination status:  OK
992   Termination:            Backup OK
993
994 \end{verbatim}
995 \normalsize
996   From the above information, you can manually create a bootstrap file,
997   and then follow the instructions given above for restoring your database.
998   A reconstructed bootstrap file for the above backup Job would look
999   like the following:
1000 \footnotesize
1001 \begin{verbatim}
1002 Volume="DLT-22Apr05"
1003 VolSessionId=11
1004 VolSessionTime=1114075126
1005 FileIndex=1-1
1006 \end{verbatim}
1007 \normalsize    
1008   Where we have inserted the Volume name, Volume Session Id, and Volume Session Time that
1009   correspond to the values in the job report.  We've also used a FileIndex of one,
1010   which will always be the case providing that there was only one file
1011   backed up in the job.
1012   
1013   The disadvantage of this bootstrap file compared to what is created when you
1014   ask for one to be written, is that there is no File and Block specified, so
1015   the restore code must search all data in the Volume to find the requested
1016   file. A fully specified bootstrap file would have the File and Blocks specified
1017   as follows:
1018 \footnotesize
1019 \begin{verbatim}
1020 Volume="DLT-22Apr05"
1021 VolSessionId=11
1022 VolSessionTime=1114075126
1023 VolFile=118-118
1024 VolBlock=0-4053
1025 FileIndex=1-1
1026 \end{verbatim}
1027 \normalsize
1028 \item [Problem]
1029   You don't have a bootstrap file, and you don't have the Job report for
1030   the backup of your database, but you did backup the database, and you
1031   know the Volume to which it was backed up.
1032   
1033 \item [Solution]
1034   Use {\bf bls} to indicate where it is on the tape. For example:
1035
1036 \footnotesize
1037 \begin{verbatim}
1038 ./bls -j -V DLT-22Apr05 /dev/nst0
1039 \end{verbatim}
1040 \normalsize
1041   Might produce the following output:
1042 \footnotesize
1043 \begin{verbatim}
1044 bls: butil.c:258 Using device: "/dev/nst0" for reading.
1045 21-Jul 18:34 bls: Ready to read from volume "DLT-22Apr05" on device "DLTDrive" (/dev/nst0).
1046 Volume Record: File:blk=0:0 SessId=11 SessTime=1114075126 JobId=0 DataLen=164
1047 ...
1048 Begin Job Session Record: File:blk=118:0 SessId=11 SessTime=1114075126 JobId=7510
1049    Job=CatalogBackup.2005-04-22_01.10.0 Date=22-Apr-2005 10:21:00 Level=F Type=B
1050 End Job Session Record: File:blk=118:4053 SessId=11 SessTime=1114075126 JobId=7510
1051    Date=22-Apr-2005 10:23:06 Level=F Type=B Files=1 Bytes=210,739,395 Errors=0 Status=T
1052 ...
1053 21-Jul 18:34 bls: End of Volume at file 201 on device "DLTDrive" (/dev/nst0), Volume "DLT-22Apr05"
1054 21-Jul 18:34 bls: End of all volumes.
1055 \end{verbatim}
1056 \normalsize
1057   Of course, there will be many more records printed, but we have indicated
1058   the essential lines of output. From the information on the Begin Job and End 
1059   Job Session Records, you can reconstruct a bootstrap file such as the one
1060   shown above.
1061
1062 \end{description}