4 \section*{The Bacula Console Restore Command}
6 \index[general]{Command!Bacula Console Restore }
7 \index[general]{Bacula Console Restore Command }
10 \index[general]{General }
12 Below, we will discuss restoring files with the Console {\bf restore} command,
13 which is the recommended way of doing it. However, there is a standalone
14 program named {\bf bextract}, which also permits restoring files. For more
15 information on this program, please see the
16 \ilink{Bacula Utility Programs}{bextract} chapter of this manual.
17 You will also want to look at the {\bf bls} program in the same chapter, which
18 allows you to list the contents of your Volumes. Finally, if you have an old
19 Volume that is no longer in the catalog, you can restore the catalog entries
20 using the program named {\bf bscan}, documented in the same
21 \ilink{Bacula Utility Programs}{bextract} chapter.
23 In general, to restore a file or a set of files, you must run a {\bf restore}
24 job. That is a job with {\bf Type = Restore}. As a consequence, you will need
25 a predefined {\bf restore} job in your {\bf bacula-dir.conf} (Director's
26 config) file. The exact parameters (Client, FileSet, ...) that you define are
27 not important as you can either modify them manually before running the job or
28 if you use the {\bf restore} command, explained below, Bacula will
29 automatically set them for you. In fact, you can no longer simply run a restore
30 job. You must use the restore command.
32 Since Bacula is a network backup program, you must be aware that when you
33 restore files, it is up to you to ensure that you or Bacula have selected the
34 correct Client and the correct hard disk location for restoring those files.
35 {\bf Bacula} will quite willingly backup client A, and restore it by sending
36 the files to a different directory on client B. Normally, you will want to
37 avoid this, but assuming the operating systems are not too different in their
38 file structures, this should work perfectly well, if so desired.
39 By default, Bacula will restore data to the same Client that was backed
40 up, and those data will be restored not to the original places but to
41 {\bf /tmp/bacula-restores}. You may modify any of these defaults when the
42 restore command prompts you to run the job by selecting the {\bf mod}
46 \section{The Restore Command}
47 \index[general]{Command!Restore }
48 \index[general]{Restore Command }
50 Since Bacula maintains a catalog of your files and on which Volumes (disk or
51 tape), they are stored, it can do most of the bookkeeping work, allowing you
52 simply to specify what kind of restore you want (current, before a particular
53 date), and what files to restore. Bacula will then do the rest.
55 This is accomplished using the {\bf restore} command in the Console. First you
56 select the kind of restore you want, then the JobIds are selected,
57 the File records for those Jobs are placed in an internal Bacula directory
58 tree, and the restore enters a file selection mode that allows you to
59 interactively walk up and down the file tree selecting individual files to be
60 restored. This mode is somewhat similar to the standard Unix {\bf restore}
61 program's interactive file selection mode.
63 If a Job's file records have been pruned from the catalog, the {\bf
64 restore} command will be unable to find any files to restore. See below
65 for more details on this.
67 Within the Console program, after entering the {\bf restore} command, you are
68 presented with the following selection prompt:
72 First you select one or more JobIds that contain files
73 to be restored. You will be presented several methods
74 of specifying the JobIds. Then you will be allowed to
75 select which files from those JobIds are to be restored.
76 To select the JobIds, you have the following choices:
77 1: List last 20 Jobs run
78 2: List Jobs where a given File is saved
79 3: Enter list of comma separated JobIds to select
80 4: Enter SQL list command
81 5: Select the most recent backup for a client
82 6: Select backup for a client before a specified time
83 7: Enter a list of files to restore
84 8: Enter a list of files to restore before a specified time
85 9: Find the JobIds of the most recent backup for a client
86 10: Find the JobIds for a backup for a client before a specified time
87 11: Enter a list of directories to restore for found JobIds
93 There are a lot of options, and as a point of reference, most people will
94 want to slect item 5 (the most recent backup for a client). The details
95 of the above options are:
98 \item Item 1 will list the last 20 jobs run. If you find the Job you want,
99 you can then select item 3 and enter its JobId(s).
101 \item Item 2 will list all the Jobs where a specified file is saved. If you
102 find the Job you want, you can then select item 3 and enter the JobId.
104 \item Item 3 allows you the enter a list of comma separated JobIds whose
105 files will be put into the directory tree. You may then select which
106 files from those JobIds to restore. Normally, you would use this option
107 if you have a particular version of a file that you want to restore and
108 you know its JobId. The most common options (5 and 6) will not select
109 a job that did not terminate normally, so if you know a file is
110 backed up by a Job that failed (possibly because of a system crash), you
111 can access it through this option by specifying the JobId.
113 \item Item 4 allows you to enter any arbitrary SQL command. This is
114 probably the most primitive way of finding the desired JobIds, but at
115 the same time, the most flexible. Once you have found the JobId(s), you
116 can select item 3 and enter them.
118 \item Item 5 will automatically select the most recent Full backup and all
119 subsequent incremental and differential backups for a specified Client.
120 These are the Jobs and Files which, if reloaded, will restore your
121 system to the most current saved state. It automatically enters the
122 JobIds found into the directory tree in an optimal way such that only
123 the most recent copy of any particular file found in the set of Jobs
124 will be restored. This is probably the most convenient of all the above
125 options to use if you wish to restore a selected Client to its most
128 There are two important things to note. First, this automatic selection
129 will never select a job that failed (terminated with an error status).
130 If you have such a job and want to recover one or more files from it,
131 you will need to explicitly enter the JobId in item 3, then choose the
134 If some of the Jobs that are needed to do the restore have had their
135 File records pruned, the restore will be incomplete. Bacula currently
136 does not correctly detect this condition. You can however, check for
137 this by looking carefully at the list of Jobs that Bacula selects and
138 prints. If you find Jobs with the JobFiles column set to zero, when
139 files should have been backed up, then you should expect problems.
141 If all the File records have been pruned, Bacula will realize that there
142 are no file records in any of the JobIds chosen and will inform you. It
143 will then propose doing a full restore (non-selective) of those JobIds.
144 This is possible because Bacula still knows where the beginning of the
145 Job data is on the Volumes, even if it does not know where particular
146 files are located or what their names are.
148 \item Item 6 allows you to specify a date and time, after which Bacula will
149 automatically select the most recent Full backup and all subsequent
150 incremental and differential backups that started before the specified date
153 \item Item 7 allows you to specify one or more filenames (complete path
154 required) to be restored. Each filename is entered one at a time or if you
155 prefix a filename with the less-than symbol (\lt{}) Bacula will read that
156 file and assume it is a list of filenames to be restored. If you
157 prefix the filename with a question mark (?), then the filename will
158 be interpreted as an SQL table name, and Bacula will include the rows
159 of that table in the list to be restored. The table must contain the
160 JobId in the first column and the FileIndex in the second column.
161 This table feature is intended for external programs that want to build
162 their own list of files to be restored.
163 The filename entry mode is terminated by entering a blank line.
165 \item Item 8 allows you to specify a date and time before entering the
166 filenames. See Item 7 above for more details.
168 \item Item 9 allows you find the JobIds of the most recent backup for
169 a client. This is much like option 5 (it uses the same code), but
170 those JobIds are retained internally as if you had entered them
171 manually. You may then select item 11 (see below) to restore one
174 \item Item 10 is the same as item 9, except that it allows you to enter
175 a before date (as with item 6). These JobIds will then be retained
178 \index[general]{Restore Directories}
179 \item Item 11 allows you to enter a list of JobIds from which you can
180 select directories to be restored. The list of JobIds can have been
181 previously created by using either item 9 or 10 on the menu. You
182 may then enter a full path to a directory name or a filename preceded
183 by a less than sign (\lt{}). The filename should contain a list
184 of directories to be restored. All files in those directories will
185 be restored, but if the directory contains subdirectories, nothing
186 will be restored in the subdirectory unless you explicitly enter its
189 \item Item 12 allows you to cancel the restore command.
192 As an example, suppose that we select item 5 (restore to most recent state).
193 If you have not specified a client=xxx on the command line, it
194 it will then ask for the desired Client, which on my system, will print all
195 the Clients found in the database as follows:
209 Select Client (File daemon) resource (1-9):
213 You will probably have far fewer Clients than this example, and if you have
214 only one Client, it will be automatically selected. In this case, I enter
215 {\bf Rufus} to select the Client. Then Bacula needs to know what FileSet is
216 to be restored, so it prompts with:
220 The defined FileSet resources are:
223 Select FileSet resource (1-2):
227 If you have only one FileSet defined for the Client, it will be selected
228 automatically. I choose item 1, which is my full backup. Normally, you
229 will only have a single FileSet for each Job, and if your machines are
230 similar (all Linux) you may only have one FileSet for all your Clients.
232 At this point, {\bf Bacula} has all the information it needs to find the most
233 recent set of backups. It will then query the database, which may take a bit
234 of time, and it will come up with something like the following. Note, some of
235 the columns are truncated here for presentation:
239 +-------+------+----------+-------------+-------------+------+-------+----------
241 | JobId | Levl | JobFiles | StartTime | VolumeName | File | SesId |
243 +-------+------+----------+-------------+-------------+------+-------+----------
245 | 1,792 | F | 128,374 | 08-03 01:58 | DLT-19Jul02 | 67 | 18 |
247 | 1,792 | F | 128,374 | 08-03 01:58 | DLT-04Aug02 | 0 | 18 |
249 | 1,797 | I | 254 | 08-04 13:53 | DLT-04Aug02 | 5 | 23 |
251 | 1,798 | I | 15 | 08-05 01:05 | DLT-04Aug02 | 6 | 24 |
253 +-------+------+----------+-------------+-------------+------+-------+----------
255 You have selected the following JobId: 1792,1792,1797
256 Building directory tree for JobId 1792 ...
257 Building directory tree for JobId 1797 ...
258 Building directory tree for JobId 1798 ...
264 Depending on the number of {\bf JobFiles} for each JobId, the {\bf Building
265 directory tree ..."} can take a bit of time. If you notice ath all the
266 JobFiles are zero, your Files have probably been pruned and you will not be
267 able to select any individual files -- it will be restore everything or
270 In our example, Bacula found four Jobs that comprise the most recent backup of
271 the specified Client and FileSet. Two of the Jobs have the same JobId because
272 that Job wrote on two different Volumes. The third Job was an incremental
273 backup to the previous Full backup, and it only saved 254 Files compared to
274 128,374 for the Full backup. The fourth Job was also an incremental backup
277 Next Bacula entered those Jobs into the directory tree, with no files marked
278 to be restored as a default, tells you how many files are in the tree, and
279 tells you that the current working directory ({\bf cwd}) is /. Finally, Bacula
280 prompts with the dollar sign (\$) to indicate that you may enter commands to
281 move around the directory tree and to select files.
283 If you want all the files to automatically be marked when the directory
284 tree is built, you could have entered the command {\bf restore all}, or
285 at the \$ prompt, you can simply enter {\bf mark *}.
287 Instead of choosing item 5 on the first menu (Select the most recent backup
288 for a client), if we had chosen item 3 (Enter list of JobIds to select) and we
289 had entered the JobIds {\bf 1792,1797,1798} we would have arrived at the same
292 One point to note, if you are manually entering JobIds, is that you must enter
293 them in the order they were run (generally in increasing JobId order). If you
294 enter them out of order and the same file was saved in two or more of the
295 Jobs, you may end up with an old version of that file (i.e. not the most
298 Directly entering the JobIds can also permit you to recover data from
299 a Job that wrote files to tape but that terminated with an error status.
301 While in file selection mode, you can enter {\bf help} or a question mark (?)
302 to produce a summary of the available commands:
308 cd change current directory
309 count count marked files in and below the cd
310 dir long list current directory, wildcards allowed
311 done leave file selection mode
312 estimate estimate restore size
313 exit same as done command
314 find find files, wildcards allowed
316 ls list current directory, wildcards allowed
317 lsmark list the marked files in and below the cd
318 mark mark dir/file to be restored recursively in dirs
319 markdir mark directory name to be restored (no files)
320 pwd print current working directory
321 unmark unmark dir/file to be restored recursively in dir
322 unmarkdir unmark directory name only no recursion
323 quit quit and do not do restore
328 As a default no files have been selected for restore (unless you
329 added {\bf all} to the command line. If you want to restore
330 everything, at this point, you should enter {\bf mark *}, and then {\bf done}
331 and {\bf Bacula} will write the bootstrap records to a file and request your
332 approval to start a restore job.
334 If you do not enter the above mentioned {\bf mark *} command, you will start
335 with an empty slate. Now you can simply start looking at the tree and {\bf
336 mark} particular files or directories you want restored. It is easy to make
337 a mistake in specifying a file to mark or unmark, and Bacula's error handling
338 is not perfect, so please check your work by using the {\bf ls} or {\bf dir}
339 commands to see what files are actually selected. Any selected file has its
340 name preceded by an asterisk.
342 To check what is marked or not marked, enter the {\bf count} command, which
347 128401 total files. 128401 marked to be restored.
352 Each of the above commands will be described in more detail in the next
353 section. We continue with the above example, having accepted to restore all
354 files as Bacula set by default. On entering the {\bf done} command, Bacula
359 Bootstrap records written to /home/kern/bacula/working/restore.bsr
360 The job will require the following
361 Volume(s) Storage(s) SD Device(s)
362 ===========================================================================
364 DLT-19Jul02 Tape DLT8000
365 DLT-04Aug02 Tape DLT8000
367 128401 files selected to restore.
369 JobName: kernsrestore
370 Bootstrap: /home/kern/bacula/working/restore.bsr
371 Where: /tmp/bacula-restores
376 When: 2006-12-11 18:20:33
379 OK to run? (yes/mod/no):
384 Please examine each of the items very carefully to make sure that they are
385 correct. In particular, look at {\bf Where}, which tells you where in the
386 directory structure the files will be restored, and {\bf Client}, which
387 tells you which client will receive the files. Note that by default the
388 Client which will receive the files is the Client that was backed up.
389 These items will not always be completed with the correct values depending
390 on which of the restore options you chose. You can change any of these
391 default items by entering {\bf mod} and responding to the prompts.
393 The above assumes that you have defined a {\bf Restore} Job resource in your
394 Director's configuration file. Normally, you will only need one Restore Job
395 resource definition because by its nature, restoring is a manual operation,
396 and using the Console interface, you will be able to modify the Restore Job to
399 An example Restore Job resource definition is given below.
401 Returning to the above example, you should verify that the Client name is
402 correct before running the Job. However, you may want to modify some of the
403 parameters of the restore job. For example, in addition to checking the Client
404 it is wise to check that the Storage device chosen by Bacula is indeed
405 correct. Although the {\bf FileSet} is shown, it will be ignored in restore.
406 The restore will choose the files to be restored either by reading the {\bf
407 Bootstrap} file, or if not specified, it will restore all files associated
408 with the specified backup {\bf JobId} (i.e. the JobId of the Job that
409 originally backed up the files).
411 Finally before running the job, please note that the default location for
412 restoring files is {\bf not} their original locations, but rather the directory
413 {\bf /tmp/bacula-restores}. You can change this default by modifying your {\bf
414 bacula-dir.conf} file, or you can modify it using the {\bf mod} option. If you
415 want to restore the files to their original location, you must have {\bf
416 Where} set to nothing or to the root, i.e. {\bf /}.
418 If you now enter {\bf yes}, Bacula will run the restore Job. The Storage
419 daemon will first request Volume {\bf DLT-19Jul02} and after the appropriate
420 files have been restored from that volume, it will request Volume {\bf
423 \section{Selecting Files by Filename}
424 \index[general]{Selecting Files by Filename }
425 \index[general]{Filename!Selecting Files by }
427 If you have a small number of files to restore, and you know the filenames,
428 you can either put the list of filenames in a file to be read by Bacula, or
429 you can enter the names one at a time. The filenames must include the full
430 path and filename. No wild cards are used.
432 To enter the files, after the {\bf restore}, you select item number 7 from the
437 To select the JobIds, you have the following choices:
438 1: List last 20 Jobs run
439 2: List Jobs where a given File is saved
440 3: Enter list of comma separated JobIds to select
441 4: Enter SQL list command
442 5: Select the most recent backup for a client
443 6: Select backup for a client before a specified time
444 7: Enter a list of files to restore
445 8: Enter a list of files to restore before a specified time
446 9: Find the JobIds of the most recent backup for a client
447 10: Find the JobIds for a backup for a client before a specified time
448 11: Enter a list of directories to restore for found JobIds
454 which then prompts you for the client name:
462 Select the Client (1-3): 3
466 Of course, your client list will be different, and if you have only one
467 client, it will be automatically selected. And finally, Bacula requests you to
476 At this point, you can enter the full path and filename
480 Enter filename: /home/kern/bacula/k/Makefile.in
485 as you can see, it took the filename. If Bacula cannot find a copy of the
486 file, it prints the following:
490 Enter filename: junk filename
491 No database record found for: junk filename
496 If you want Bacula to read the filenames from a file, you simply precede the
497 filename with a less-than symbol (\lt{}). When you have entered all the
498 filenames, you enter a blank line, and Bacula will write the bootstrap file,
499 tells you what tapes will be used, and proposes a Restore job to be run:
504 Automatically selected Storage: DDS-4
505 Bootstrap records written to /home/kern/bacula/working/restore.bsr
506 The restore job will require the following Volumes:
509 1 file selected to restore.
511 JobName: kernsrestore
512 Bootstrap: /home/kern/bacula/working/restore.bsr
513 Where: /tmp/bacula-restores
518 When: 2003-09-11 10:20:53
520 OK to run? (yes/mod/no):
524 It is possible to automate the selection by file by putting your list of files
525 in say {\bf /tmp/file-list}, then using the following command:
529 restore client=Rufus file=</tmp/file-list
533 If in modifying the parameters for the Run Restore job, you find that Bacula
534 asks you to enter a Job number, this is because you have not yet specified
535 either a Job number or a Bootstrap file. Simply entering zero will allow you
536 to continue and to select another option to be modified.
537 \label{CommandArguments}
539 \section{Command Line Arguments}
540 \index[general]{Arguments!Command Line }
541 \index[general]{Command Line Arguments }
543 If all the above sounds complicated, you will probably agree that it really
544 isn't after trying it a few times. It is possible to do everything that was
545 shown above, with the exception of selecting the FileSet, by using command
546 line arguments with a single command by entering:
550 restore client=Rufus select current all done yes
554 The {\bf client=Rufus} specification will automatically select Rufus as the
555 client, the {\bf current} tells Bacula that you want to restore the system to
556 the most current state possible, and the {\bf yes} suppresses the final {\bf
557 yes/mod/no} prompt and simply runs the restore.
559 The full list of possible command line arguments are:
562 \item {\bf all} -- select all Files to be restored.
563 \item {\bf select} -- use the tree selection method.
564 \item {\bf done} -- do not prompt the user in tree mode.
565 \item {\bf current} -- automatically select the most current set of backups
566 for the specified client.
567 \item {\bf client=xxxx} -- select the specified client.
568 \item {\bf jobid=nnn} -- specify a JobId or comma separated list of JobIds to
570 \item {\bf before=YYYY-MM-DD HH:MM:SS} -- specify a date and time to which
571 the system should be restored. Only Jobs started before the specified
572 date/time will be selected, and as is the case for {\bf current} Bacula will
573 automatically find the most recent prior Full save and all Differential and
574 Incremental saves run before the date you specify. Note, this command is not
575 too user friendly in that you must specify the date/time exactly as shown.
576 \item {\bf file=filename} -- specify a filename to be restored. You must
577 specify the full path and filename. Prefixing the entry with a less-than
579 (\lt{}) will cause Bacula to assume that the filename is on your system and
580 contains a list of files to be restored. Bacula will thus read the list from
581 that file. Multiple file=xxx specifications may be specified on the command
583 \item {\bf jobid=nnn} -- specify a JobId to be restored.
584 \item {\bf pool=pool-name} -- specify a Pool name to be used for selection of
585 Volumes when specifying options 5 and 6 (restore current system, and restore
586 current system before given date). This permits you to have several Pools,
587 possibly one offsite, and to select the Pool to be used for restoring.
588 \item {\bf yes} -- automatically run the restore without prompting for
589 modifications (most useful in batch scripts).
592 \section{Restoring Directory Attributes}
593 \index[general]{Attributes!Restoring Directory }
594 \index[general]{Restoring Directory Attributes }
596 Depending how you do the restore, you may or may not get the directory entries
597 back to their original state. Here are a few of the problems you can
598 encounter, and for same machine restores, how to avoid them.
601 \item You backed up on one machine and are restoring to another that is
602 either a different OS or doesn't have the same users/groups defined. Bacula
603 does the best it can in these situations. Note, Bacula has saved the
604 user/groups in numeric form, which means on a different machine, they
605 may map to different user/group names.
606 \item You are restoring into a directory that is already created and has
607 file creation restrictions. Bacula tries to reset everything but
608 without walking up the full chain of directories and modifying them all
609 during the restore, which Bacula does and will not do, getting
610 permissions back correctly in this situation depends to a large extent
612 \item You are doing a recursive restore of a directory tree. In this case
613 Bacula will restore a file before restoring the file's parent directory
614 entry. In the process of restoring the file Bacula will create the
615 parent directory with open permissions and ownership of the file being
616 restored. Then when Bacula tries to restore the parent directory Bacula
617 sees that it already exists (Similar to the previous situation). If you
618 had set the Restore job's "Replace" property to "never" then Bacula will
619 not change the directory's permissions and ownerships to match what it
620 backed up, you should also notice that the actual number of files
621 restored is less then the expected number. If you had set the Restore
622 job's "Replace" property to "always" then Bacula will change the
623 Directory's ownership and permissions to match what it backed up, also
624 the actual number of files restored should be equal to the expected
626 \item You selected one or more files in a directory, but did not select the
627 directory entry to be restored. In that case, if the directory is not
628 on disk Bacula simply creates the directory with some default attributes
629 which may not be the same as the original. If you do not select a
630 directory and all its contents to be restored, you can still select
631 items within the directory to be restored by individually marking those
632 files, but in that case, you should individually use the "markdir"
633 command to select all higher level directory entries (one at a time) to
634 be restored if you want the directory entries properly restored.
638 \section{Restoring on Windows}
639 \index[general]{Restoring on Windows }
640 \index[general]{Windows!Restoring on }
642 If you are restoring on WinNT/2K/XP systems, Bacula will restore the files
643 with the original ownerships and permissions as would be expected. This is
644 also true if you are restoring those files to an alternate directory (using
645 the Where option in restore). However, if the alternate directory does not
646 already exist, the Bacula File daemon (Client) will try to create it. In
647 some cases, it may not create the directories, and if it does since the
648 File daemon runs under the SYSTEM account, the directory will be created
649 with SYSTEM ownership and permissions. In this case, you may have problems
650 accessing the newly restored files.
652 To avoid this problem, you should create any alternate directory before
653 doing the restore. Bacula will not change the ownership and permissions of
654 the directory if it is already created as long as it is not one of the
655 directories being restored (i.e. written to tape).
657 The default restore location is {\bf /tmp/bacula-restores/} and if you are
658 restoring from drive {\bf E:}, the default will be
659 {\bf /tmp/bacula-restores/e/}, so you should ensure that this directory
660 exists before doing the restore, or use the {\bf mod} option to
661 select a different {\bf where} directory that does exist.
663 Some users have experienced problems restoring files that participate in
664 the Active Directory. They also report that changing the userid under which
665 Bacula (bacula-fd.exe) runs, from SYSTEM to a Domain Admin userid, resolves
669 \section{Restoring Files Can Be Slow}
670 \index[general]{Slow!Restoring Files Can Be }
671 \index[general]{Restoring Files Can Be Slow }
673 Restoring files is generally {\bf much} slower than backing them up for several
674 reasons. The first is that during a backup the tape is normally already
675 positioned and Bacula only needs to write. On the other hand, because restoring
676 files is done so rarely, Bacula keeps only the start file and block on the
677 tape for the whole job rather than on a file by file basis which would use
678 quite a lot of space in the catalog.
680 Bacula will forward space to the correct file mark on the tape for the Job,
681 then forward space to the correct block, and finally sequentially read each
682 record until it gets to the correct one(s) for the file or files you want to
683 restore. Once the desired files are restored, Bacula will stop reading the
686 Finally, instead of just reading a file for backup, during the restore, Bacula
687 must create the file, and the operating system must allocate disk space for
688 the file as Bacula is restoring it.
690 For all the above reasons the restore process is generally much slower than
691 backing up (sometimes it takes three times as long).
693 \section{Problems Restoring Files}
694 \index[general]{Files!Problems Restoring }
695 \index[general]{Problems Restoring Files }
697 The most frequent problems users have restoring files are error messages such
702 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
703 block.c:868 Volume data error at 20:0! Short block of 512 bytes on
704 device /dev/tape discarded.
712 04-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error:
713 block.c:264 Volume data error at 20:0! Wanted ID: "BB02", got ".".
718 Both these kinds of messages indicate that you were probably running your tape
719 drive in fixed block mode rather than variable block mode. Fixed block mode
720 will work with any program that reads tapes sequentially such as tar, but
721 Bacula repositions the tape on a block basis when restoring files because this
722 will speed up the restore by orders of magnitude when only a few files are being
723 restored. There are several ways that you can attempt to recover from this
724 unfortunate situation.
726 Try the following things, each separately, and reset your Device resource to
727 what it is now after each individual test:
730 \item Set "Block Positioning = no" in your Device resource and try the
731 restore. This is a new directive and untested.
732 \item Set "Minimum Block Size = 512" and "Maximum Block Size = 512" and
733 try the restore. If you are able to determine the block size your drive
734 was previously using, you should try that size if 512 does not work.
735 This is a really horrible solution, and it is not at all recommended
736 to continue backing up your data without correcting this condition.
737 Please see the Tape Testing chapter for more on this.
738 \item Try editing the restore.bsr file at the Run xxx yes/mod/no prompt
739 before starting the restore job and remove all the VolBlock statements.
740 These are what causes Bacula to reposition the tape, and where problems
741 occur if you have a fixed block size set for your drive. The VolFile
742 commands also cause repositioning, but this will work regardless of the
744 \item Use bextract to extract the files you want -- it reads the Volume
745 sequentially if you use the include list feature, or if you use a .bsr
746 file, but remove all the VolBlock statements after the .bsr file is
747 created (at the Run yes/mod/no) prompt but before you start the restore.
750 \section{Restore Errors}
751 \index[general]{Errors!Restore}
752 \index[general]{Restore Errors}
754 There are a number of reasons why there may be restore errors or
755 warning messages. Some of the more common ones are:
759 \item [file count mismatch]
760 This can occur for the following reasons:
762 \item You requested Bacula not to overwrite existing or newer
764 \item A Bacula miscount of files/directories. This is an
765 on-going problem due to the complications of directories,
766 soft/hard link, and such. Simply check that all the files you
767 wanted were actually restored.
769 \item [file size error]
770 When Bacula restores files, it checks that the size of the
771 restored file is the same as the file status data it saved
772 when starting the backup of the file. If the sizes do not
773 agree, Bacula will print an error message. This size mismatch
774 most often occurs because the file was being written as Bacula
775 backed up the file. In this case, the size that Bacula
776 restored will be greater than the status size. This often
777 happens with log files.
779 If the restored size is smaller, then you should be concerned
780 about a possible tape error and check the Bacula output as
781 well as your system logs.
786 \section{Example Restore Job Resource}
787 \index[general]{Example Restore Job Resource }
788 \index[general]{Resource!Example Restore Job }
793 Name = "RestoreFiles"
796 FileSet = "Any-FileSet"
797 Storage = Any-storage
798 Where = /tmp/bacula-restores
805 If {\bf Where} is not specified, the default location for restoring files will
806 be their original locations.
809 \section{File Selection Commands}
810 \index[general]{Commands!File Selection }
811 \index[general]{File Selection Commands }
813 After you have selected the Jobs to be restored and Bacula has created the
814 in-memory directory tree, you will enter file selection mode as indicated by
815 the dollar sign ({\bf \$}) prompt. While in this mode, you may use the
816 commands listed above. The basic idea is to move up and down the in memory
817 directory structure with the {\bf cd} command much as you normally do on the
818 system. Once you are in a directory, you may select the files that you want
819 restored. As a default no files are marked to be restored. If you wish to
820 start with all files, simply enter: {\bf cd /} and {\bf mark *}. Otherwise
821 proceed to select the files you wish to restore by marking them with the {\bf
822 mark} command. The available commands are:
827 The {\bf cd} command changes the current directory to the argument
829 It operates much like the Unix {\bf cd} command. Wildcard specifications are
832 Note, on Windows systems, the various drives (c:, d:, ...) are treated like
834 directory within the file tree while in the file selection mode. As a
835 consequence, you must do a {\bf cd c:} or possibly in some cases a {\bf cd
836 C:} (note upper case) to get down to the first directory.
840 The {\bf dir} command is similar to the {\bf ls} command, except that it
841 prints it in long format (all details). This command can be a bit slower
843 the {\bf ls} command because it must access the catalog database for the
844 detailed information for each file.
847 \index[dir]{estimate }
848 The {\bf estimate} command prints a summary of the total files in the tree,
849 how many are marked to be restored, and an estimate of the number of bytes
851 be restored. This can be useful if you are short on disk space on the
853 where the files will be restored.
857 The {\bf find} command accepts one or more arguments and displays all files
858 in the tree that match that argument. The argument may have wildcards. It is
859 somewhat similar to the Unix command {\bf find / -name arg}.
862 The {\bf ls} command produces a listing of all the files contained in the
863 current directory much like the Unix {\bf ls} command. You may specify an
864 argument containing wildcards, in which case only those files will be
866 Any file that is marked to be restored will have its name preceded by an
867 asterisk ({\bf *}). Directory names will be terminated with a forward slash
868 ({\bf /}) to distinguish them from filenames.
872 The {\bf lsmark} command is the same as the {\bf ls} except that it will
873 print only those files marked for extraction. The other distinction is that
874 it will recursively descend into any directory selected.
878 The {\bf mark} command allows you to mark files to be restored. It takes a
879 single argument which is the filename or directory name in the current
880 directory to be marked for extraction. The argument may be a wildcard
881 specification, in which case all files that match in the current directory
882 are marked to be restored. If the argument matches a directory rather than a
883 file, then the directory and all the files contained in that directory
884 (recursively) are marked to be restored. Any marked file will have its name
885 preceded with an asterisk ({\bf *}) in the output produced by the {\bf ls}
887 {\bf dir} commands. Note, supplying a full path on the mark command does not
888 work as expected to select a file or directory in the current directory.
889 Also, the {\bf mark} command works on the current and lower directories but
890 does not touch higher level directories.
892 After executing the {\bf mark} command, it will print a brief summary:
901 If no files were marked, or:
910 if some files are marked.
914 The {\bf unmark} is identical to the {\bf mark} command, except that it
915 unmarks the specified file or files so that they will not be restored. Note:
916 the {\bf unmark} command works from the current directory, so it does not
917 unmark any files at a higher level. First do a {\bf cd /} before the {\bf
918 unmark *} command if you want to unmark everything.
922 The {\bf pwd} command prints the current working directory. It accepts no
927 The {\bf count} command prints the total files in the directory tree and the
928 number of files marked to be restored.
932 This command terminates file selection mode.
936 This command terminates file selection mode (the same as done).
940 This command terminates the file selection and does not run the restore
946 This command prints a summary of the commands available.
949 This command is the same as the {\bf help} command.
952 \label{database_restore}
953 \section{Restoring When Things Go Wrong}
954 \index[general]{Restoring When Things Go Wrong }
955 \index[general]{Restoring Your Database}
956 \index[general]{Database!Restoring}
958 This and the following sections will try to present a few of the kinds of
959 problems that can come up making restoring more difficult. I'll try to
960 provide a few ideas how to get out of these problem situations.
961 In addition to what is presented here, there is more specific information
962 on restoring a \ilink{Client}{restore_client} and your
963 \ilink{Server}{restore_server} in the \ilink{Disaster Recovery Using
964 Bacula}{RescueChapter} chapter of this manual.
968 My database is broken.
970 For SQLite, use the vacuum command to try to fix the database. For either
971 MySQL or PostgreSQL, see the vendor's documentation. They have specific tools
972 that check and repair databases, see the \ilink{database
973 repair}{DatabaseRepair} sections of this manual for links to vendor
976 Assuming the above does not resolve the problem, you will need to restore
977 or rebuild your catalog. Note, if it is a matter of some
978 inconsistencies in the Bacula tables rather than a broken database, then
979 running \ilink{dbcheck}{dbcheck} might help, but you will need to ensure
980 that your database indexes are properly setup. Please see
981 the \ilink{Database Performance Issues}{DatabasePerformance} sections
982 of this manual for more details.
985 How do I restore my catalog?
986 \item[Solution with a Catalog backup]
987 If you have backed up your database nightly (as you should) and you
988 have made a bootstrap file, you can immediately load back your
989 database (or the ASCII SQL output). Make a copy of your current
990 database, then re-initialize it, by running the following scripts:
995 After re-initializing the database, you should be able to run
996 Bacula. If you now try to use the restore command, it will not
997 work because the database will be empty. However, you can manually
998 run a restore job and specify your bootstrap file. You do so
999 by entering the {bf run} command in the console and selecting the
1000 restore job. If you are using the default bacula-dir.conf, this
1001 Job will be named {\bf RestoreFiles}. Most likely it will prompt
1002 you with something such as:
1006 JobName: RestoreFiles
1007 Bootstrap: /home/kern/bacula/working/restore.bsr
1008 Where: /tmp/bacula-restores
1013 When: 2005-07-10 17:33:40
1016 OK to run? (yes/mod/no):
1019 A number of the items will be different in your case. What you want to
1020 do is: to use the mod option to change the Bootstrap to point to your
1021 saved bootstrap file; and to make sure all the other items such as
1022 Client, Storage, Catalog, and Where are correct. The FileSet is not
1023 used when you specify a bootstrap file. Once you have set all the
1024 correct values, run the Job and it will restore the backup of your
1025 database, which is most likely an ASCII dump.
1027 You will then need to follow the instructions for your
1028 database type to recreate the database from the ASCII backup file.
1029 See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of
1030 this manual for examples of the command needed to restore a
1031 database from an ASCII dump (they are shown in the Compacting Your
1032 XXX Database sections).
1034 Also, please note that after you restore your database from an ASCII
1035 backup, you do NOT want to do a {\bf make\_bacula\_tables} command, or
1036 you will probably erase your newly restored database tables.
1039 \item[Solution with a Job listing]
1040 If you did save your database but did not make a bootstrap file, then
1041 recovering the database is more difficult. You will probably need to
1042 use bextract to extract the backup copy. First you should locate the
1043 listing of the job report from the last catalog backup. It has
1044 important information that will allow you to quickly find your database
1045 file. For example, in the job report for the CatalogBackup shown below,
1046 the critical items are the Volume name(s), the Volume Session Id and the
1047 Volume Session Time. If you know those, you can easily restore your
1052 22-Apr 10:22 HeadMan: Start Backup JobId 7510,
1053 Job=CatalogBackup.2005-04-22_01.10.0
1054 22-Apr 10:23 HeadMan: Bacula 1.37.14 (21Apr05): 22-Apr-2005 10:23:06
1056 Job: CatalogBackup.2005-04-22_01.10.00
1059 FileSet: "CatalogFile" 2003-04-10 01:24:01
1062 Start time: 22-Apr-2005 10:21:00
1063 End time: 22-Apr-2005 10:23:06
1066 FD Bytes Written: 210,739,395
1067 SD Bytes Written: 210,739,521
1069 Software Compression: None
1070 Volume name(s): DLT-22Apr05
1071 Volume Session Id: 11
1072 Volume Session Time: 1114075126
1073 Last Volume Bytes: 1,428,240,465
1074 Non-fatal FD errors: 0
1076 FD termination status: OK
1077 SD termination status: OK
1078 Termination: Backup OK
1083 From the above information, you can manually create a bootstrap file,
1084 and then follow the instructions given above for restoring your database.
1085 A reconstructed bootstrap file for the above backup Job would look
1090 Volume="DLT-22Apr05"
1092 VolSessionTime=1114075126
1097 Where we have inserted the Volume name, Volume Session Id, and Volume
1098 Session Time that correspond to the values in the job report. We've also
1099 used a FileIndex of one, which will always be the case providing that
1100 there was only one file backed up in the job.
1102 The disadvantage of this bootstrap file compared to what is created when
1103 you ask for one to be written, is that there is no File and Block
1104 specified, so the restore code must search all data in the Volume to find
1105 the requested file. A fully specified bootstrap file would have the File
1106 and Blocks specified as follows:
1110 Volume="DLT-22Apr05"
1112 VolSessionTime=1114075126
1119 Once you have restored the ASCII dump of the database,
1120 you will then to follow the instructions for your
1121 database type to recreate the database from the ASCII backup file.
1122 See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of
1123 this manual for examples of the command needed to restore a
1124 database from an ASCII dump (they are shown in the Compacting Your
1125 XXX Database sections).
1127 Also, please note that after you restore your database from an ASCII
1128 backup, you do NOT want to do a {\bf make\_bacula\_tables} command, or
1129 you will probably erase your newly restored database tables.
1131 \item [Solution without a Job Listing]
1132 If you do not have a job listing, then it is a bit more difficult.
1133 Either you use the \ilink{bscan}{bscan} program to scan the contents
1134 of your tape into a database, which can be very time consuming
1135 depending on the size of the tape, or you can use the \ilink{bls}{bls}
1136 program to list everything on the tape, and reconstruct a bootstrap
1137 file from the bls listing for the file or files you want following
1138 the instructions given above.
1140 There is a specific example of how to use {\bf bls} below.
1143 I try to restore the last known good full backup by specifying
1144 item 3 on the restore menu then the JobId to restore. Bacula
1152 and restores nothing.
1154 Most likely the File records were pruned from the database either due
1155 to the File Retention period expiring or by explicitly purging the
1156 Job. By using the "llist jobid=nn" command, you can obtain all the
1157 important information about the job:
1162 Job: save.2005-12-05_18.27.33
1170 SchedTime: 2005-12-05 18:27:32
1171 StartTime: 2005-12-05 18:27:35
1172 EndTime: 2005-12-05 18:27:37
1173 JobTDate: 1133803657
1175 VolSessionTime: 1133803624
1182 FileSet.FileSet: BackupSet
1186 Then you can find the Volume(s) used by doing:
1190 select VolumeName from JobMedia,Media where JobId=1 and JobMedia.MediaId=Media.MediaId;
1193 Finally, you can create a bootstrap file as described in the previous
1194 problem above using this information.
1196 If you are using Bacula version 1.38.0 or greater, when you select
1197 item 3 from the menu and enter the JobId, it will ask you if
1198 you would like to restore all the files in the job, and it will
1199 collect the above information and write the bootstrap file for
1203 You don't have a bootstrap file, and you don't have the Job report for
1204 the backup of your database, but you did backup the database, and you
1205 know the Volume to which it was backed up.
1208 Either bscan the tape, or use {\bf bls} to indicate where it is on the
1213 ./bls -j -V DLT-22Apr05 /dev/nst0
1216 Might produce the following output:
1219 bls: butil.c:258 Using device: "/dev/nst0" for reading.
1220 21-Jul 18:34 bls: Ready to read from volume "DLT-22Apr05" on device "DLTDrive"
1222 Volume Record: File:blk=0:0 SessId=11 SessTime=1114075126 JobId=0 DataLen=164
1224 Begin Job Session Record: File:blk=118:0 SessId=11 SessTime=1114075126
1226 Job=CatalogBackup.2005-04-22_01.10.0 Date=22-Apr-2005 10:21:00 Level=F Type=B
1227 End Job Session Record: File:blk=118:4053 SessId=11 SessTime=1114075126
1229 Date=22-Apr-2005 10:23:06 Level=F Type=B Files=1 Bytes=210,739,395 Errors=0
1232 21-Jul 18:34 bls: End of Volume at file 201 on device "DLTDrive" (/dev/nst0),
1233 Volume "DLT-22Apr05"
1234 21-Jul 18:34 bls: End of all volumes.
1237 Of course, there will be many more records printed, but we have indicated
1238 the essential lines of output. From the information on the Begin Job and End
1239 Job Session Records, you can reconstruct a bootstrap file such as the one
1243 How can I find where a file is stored.
1245 Normally, it is not necessary, you just use the {\bf restore} command to
1246 restore the most recently saved version (menu option 5), or a version
1247 saved before a given date (menu option 8). If you know the JobId of the
1248 job in which it was saved, you can use menu option 3 to enter that JobId.
1250 If you would like to know the JobId where a file was saved, select
1251 restore menu option 2.
1253 You can also use the {\bf query} command to find information such as:
1258 1: List up to 20 places where a File is saved regardless of the
1260 2: List where the most recent copies of a file are saved
1261 3: List last 20 Full Backups for a Client
1262 4: List all backups for a Client after a specified time
1263 5: List all backups for a Client
1264 6: List Volume Attributes for a selected Volume
1265 7: List Volumes used by selected JobId
1266 8: List Volumes to Restore All Files
1267 9: List Pool Attributes for a selected Pool
1268 10: List total files/bytes by Job
1269 11: List total files/bytes by Volume
1270 12: List Files for a selected JobId
1271 13: List Jobs stored on a selected MediaId
1272 14: List Jobs stored for a given Volume name
1273 15: List Volumes Bacula thinks are in changer
1274 16: List Volumes likely to need replacement from age or errors
1275 Choose a query (1-16):