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