]> git.sur5r.net Git - bacula/docs/blobdiff - docs/manual/restore.tex
Updates
[bacula/docs] / docs / manual / restore.tex
index 2c2ef406b8838a78c6bbdaab6ee21d504357c095..4085e7748516a7c34545b1bd521a20bd9ca8fbb2 100644 (file)
@@ -11,7 +11,7 @@
 \index[general]{General }
 \addcontentsline{toc}{subsection}{General}
 
-Below, we will discuss restoring files with the Console {\bf Restore} command,
+Below, we will discuss restoring files with the Console {\bf restore} command,
 which is the recommended way of doing it. However, there is a standalone
 program named {\bf bextract}, which also permits restoring files. For more
 information on this program, please see the 
@@ -27,8 +27,9 @@ job. That is a job with {\bf Type = Restore}. As a consequence, you will need
 a predefined {\bf restore} job in your {\bf bacula-dir.conf} (Director's
 config) file. The exact parameters (Client, FileSet, ...) that you define are
 not important as you can either modify them manually before running the job or
-if you use the {\bf restore} command, explained below, they will be
-automatically set for you. 
+if you use the {\bf restore} command, explained below, Bacula will  
+automatically set them for you. In fact, you can no longer simply run a restore
+job.  You must use the restore command.                                  
 
 Since Bacula is a network backup program, you must be aware that when you
 restore files, it is up to you to ensure that you or Bacula have selected the
@@ -37,8 +38,13 @@ correct Client and the correct hard disk location for restoring those files.
 the files to a different directory on client B. Normally, you will want to
 avoid this, but assuming the operating systems are not too different in their
 file structures, this should work perfectly well, if so desired. 
-\label{Example1}
+By default, Bacula will restore data to the same Client that was backed
+up, and those data will be restored not to the original places but to
+{\bf /tmp/bacula-restores}.  You may modify any of these defaults when the
+restore command prompts you to run the job by selecting the {\bf mod}
+option.
 
+\label{Example1}
 \subsection*{The Restore Command}
 \index[general]{Command!Restore }
 \index[general]{Restore Command }
@@ -57,6 +63,9 @@ interactively walk up and down the file tree selecting individual files to be
 restored. This mode is somewhat similar to the standard Unix {\bf restore}
 program's interactive file selection mode. 
 
+If your Files have been pruned, the {\bf restore} command will be unable
+to find any files to restore. See below for more details on this. 
+
 Within the Console program, after entering the {\bf restore} command, you are
 presented with the following selection prompt:  
 
@@ -69,48 +78,101 @@ select which files from those JobIds are to be restored.
 To select the JobIds, you have the following choices:
      1: List last 20 Jobs run
      2: List Jobs where a given File is saved
-     3: Enter list of JobIds to select
+     3: Enter list of comma separated JobIds to select
      4: Enter SQL list command
      5: Select the most recent backup for a client
      6: Select backup for a client before a specified time
      7: Enter a list of files to restore
      8: Enter a list of files to restore before a specified time
-     9: Cancel
-Select item:  (1-9):
-     
+     9: Find the JobIds of the most recent backup for a client
+    10: Find the JobIds for a backup for a client before a specified time
+    11: Enter a list of directories to restore for found JobIds
+    12: Cancel
+Select item:  (1-12):
 \end{verbatim}
 \normalsize
 
 \begin{itemize}
-\item Item 1 will list the last 20 jobs run. If you find the  Job you want,
-   you can then select item 3 and enter its JobId(s). 
+\item Item 1 will list the last 20 jobs run. If you find the Job you want,
+   you can then select item 3 and enter its JobId(s).
+
 \item Item 2 will list all the Jobs where a specified file is saved.  If you
-   find the Job you want, you can then select item 3 and  enter the JobId. 
+   find the Job you want, you can then select item 3 and enter the JobId.
+
 \item Item 3 allows you the enter a list of comma separated JobIds whose 
-   files will be put into the directory tree. 
+   files will be put into the directory tree. You may then select which
+   files from those JobIds to restore.
+
 \item Item 4 allows you to enter any arbitrary SQL command. This is  probably
    the most primitive way of finding the desired JobIds,  but at the same time,
    the most flexible.  Once you have found the JobId(s), you can select item 3
-and enter  them.  
+   and enter  them.
+
 \item Item 5 will automatically select the most recent Full backup and all 
-   subsequent incremental and differential backups for a specified  Client. These
-   are the Jobs and Files which, if reloaded, will  restore your system to the most
-current saved state. It  automatically enters the JobIds found into the 
-directory tree. This is probably the most convenient of all the  above options
-to use if you wish to restore a selected Client to  its most recent state.  
+   subsequent incremental and differential backups for a specified Client.
+   These are the Jobs and Files which, if reloaded, will restore your
+   system to the most current saved state.  It automatically enters the
+   JobIds found into the directory tree.  This is probably the most
+   convenient of all the above options to use if you wish to restore a
+   selected Client to its most recent state.
+
+   There are two important things to note. First, this automatic selection
+   will never select a job that failed (terminated with an error status).
+   If you have such a job and want to recover one or more files from it,
+   you will need to explicitly enter the JobId in item 3, then choose the
+   files to restore.
+
+   If some of the Jobs that are needed to do the restore have had their 
+   File records pruned, the restore will be incomplete. Bacula currently
+   does not correctly detect this condition.  You can however, check for
+   this by looking carefully at the list of Jobs that Bacula selects and
+   prints. If you find Jobs with the JobFiles column set to zero, when
+   files should have been backed up, then you should expect problems.
+
+   If all the File records have been pruned, Bacula will realize that there
+   are no file records in any of the JobIds chosen and will inform you. It
+   will then propose doing a full restore (non-selective) of those JobIds.
+   This is possible because Bacula still knows where the beginning of the
+   Job data is on the Volumes, even if it does not know where particular
+   files are located.
+
 \item Item 6 allows you to specify a date and time, after which Bacula  will
    automatically select the most recent Full backup and all  subsequent
    incremental and differential backups that started  before the specified date
-and time.  
+  and time.  
+
 \item Item 7 allows you to specify one or more filenames  (complete path
    required) to be restored. Each filename  is entered one at a time or if you
    prefix a filename  with the less-than symbol (\lt{}) Bacula will read that 
-file and assume it is a list of filenames to be restored.  The filename entry
-mode is terminated by entering a  blank line.  
+   file and assume it is a list of filenames to be restored.  The filename entry
+   mode is terminated by entering a  blank line.
+
 \item Item 8 allows you to specify a date and time before  entering the
-   filenames. See Item 7 above for more  details.  
-\item Item 9 allows you to cancel the restore command.  
-   \end{itemize}
+   filenames. See Item 7 above for more  details.
+
+\item Item 9 allows you find the JobIds of the most recent backup for
+   a client. This is much like option 5 (it uses the same code), but
+   those JobIds are retained internally as if you had entered them
+   manually.  You may then select item 11 (see below) to restore one
+   or more directories.
+
+\item Item 10 is the same as item 9, except that it allows you to enter
+   a before date (as with item 6). These JobIds will then be retained
+   internally.
+
+\index[general]{Restore Directories}
+\item Item 11 allows you to enter a list of JobIds from which you can
+   select directories to be restored. The list of JobIds can have been
+   previously created by using either item 9 or 10 on the menu.  You
+   may then enter a full path to a directory name or a filename preceded
+   by a less than sign (\lt{}). The filename should contain a list
+   of directories to be restored.  All files in those directories will
+   be restored, but if the directory contains subdirectories, nothing
+   will be restored in the subdirectory unless you explicitly enter its
+   name.
+
+\item Item 12 allows you to cancel the restore command.  
+\end{itemize}
 
 As an example, suppose that we select item 5 (restore to most recent state).
 It will then ask for the desired Client, which on my system, will print all
@@ -159,14 +221,22 @@ the columns are truncated here for presentation:
 
 \footnotesize
 \begin{verbatim}
-+-------+------+----------+-------------+-------------+------+-------+------------+
-| JobId | Levl | JobFiles | StartTime   | VolumeName  | File | SesId | VolSesTime |
-+-------+------+----------+-------------+-------------+------+-------+------------+
-| 1,792 | F    |  128,374 | 08-03 01:58 | DLT-19Jul02 |   67 |    18 | 1028042998 |
-| 1,792 | F    |  128,374 | 08-03 01:58 | DLT-04Aug02 |    0 |    18 | 1028042998 |
-| 1,797 | I    |      254 | 08-04 13:53 | DLT-04Aug02 |    5 |    23 | 1028042998 |
-| 1,798 | I    |       15 | 08-05 01:05 | DLT-04Aug02 |    6 |    24 | 1028042998 |
-+-------+------+----------+-------------+-------------+------+-------+------------+
++-------+------+----------+-------------+-------------+------+-------+----------
+--+
+| JobId | Levl | JobFiles | StartTime   | VolumeName  | File | SesId |
+VolSesTime |
++-------+------+----------+-------------+-------------+------+-------+----------
+--+
+| 1,792 | F    |  128,374 | 08-03 01:58 | DLT-19Jul02 |   67 |    18 |
+1028042998 |
+| 1,792 | F    |  128,374 | 08-03 01:58 | DLT-04Aug02 |    0 |    18 |
+1028042998 |
+| 1,797 | I    |      254 | 08-04 13:53 | DLT-04Aug02 |    5 |    23 |
+1028042998 |
+| 1,798 | I    |       15 | 08-05 01:05 | DLT-04Aug02 |    6 |    24 |
+1028042998 |
++-------+------+----------+-------------+-------------+------+-------+----------
+--+
 You have selected the following JobId: 1792,1792,1797
 Building directory tree for JobId 1792 ...
 Building directory tree for JobId 1797 ...
@@ -177,7 +247,10 @@ $
 \normalsize
 
 Depending on the number of {\bf JobFiles} for each JobId, the {\bf Building
-directory tree ...``} can take a bit of time. 
+directory tree ..."} can take a bit of time. If you notice ath all the
+JobFiles are zero, your Files have probably been pruned and you will not be
+able to select any individual files -- it will be restore everything or
+nothing.
 
 In our example, Bacula found four Jobs that comprise the most recent backup of
 the specified Client and FileSet. Two of the Jobs have the same JobId because
@@ -191,11 +264,14 @@ to be restored as a default, tells you how many files are in the tree, and
 tells you that the current working directory ({\bf cwd}) is /. Finally, Bacula
 prompts with the dollar sign (\$) to indicate that you may enter commands to
 move around the directory tree and to select files. 
+             
+If you want all the files to automatically be marked when the directory
+tree is built, enter the command {\bf restore all}.
 
 Instead of choosing item 5 on the first menu (Select the most recent backup
 for a client), if we had chosen item 3 (Enter list of JobIds to select) and we
 had entered the JobIds {\bf 1792,1797,1798} we would have arrived at the same
-point. 
+point.                 
 
 One point to note, if you are manually entering JobIds, is that you must enter
 them in the order they were run (generally in increasing JobId order). If you
@@ -203,35 +279,38 @@ enter them out of order and the same file was saved in two or more of the
 Jobs, you may end up with an old version of that file (i.e. not the most
 recent). 
 
+Directly entering the JobIds can also permit you to recover data from
+a Job that wrote files to tape but that terminated with an error status.
+
 While in file selection mode, you can enter {\bf help} or a question mark (?)
 to produce a summary of the available commands:  
 
 \footnotesize
 \begin{verbatim}
 Command    Description
+ Command    Description
   =======    ===========
   cd         change current directory
   count      count marked files in and below the cd
-  dir        list current directory
+  dir        long list current directory, wildcards allowed
   done       leave file selection mode
   estimate   estimate restore size
-  exit       exit = done
-  find       find files -- wildcards allowed
+  exit       same as done command
+  find       find files, wildcards allowed
   help       print help
-  ls         list current directory -- wildcards allowed
+  ls         list current directory, wildcards allowed
   lsmark     list the marked files in and below the cd
-  mark       mark file to be restored
-  markdir    mark directory entry to be restored -- nonrecursive
+  mark       mark dir/file to be restored recursively in dirs
+  markdir    mark directory name to be restored (no files)
   pwd        print current working directory
-  unmark     unmark file to be restored
-  unmarkdir  unmark directory -- no recursion
-  quit       quit
+  unmark     unmark dir/file to be restored recursively in dir
+  unmarkdir  unmark directory name only no recursion
+  quit       quit and do not do restore
   ?          print help
-     
 \end{verbatim}
 \normalsize
 
-As a default no files have been selected for restore. If you want to restore
+As a default no files have been selected for restore (unless you
+added {\bf all} to the command line. If you want to restore
 everything, at this point, you should enter {\bf mark *}, and then {\bf done}
 and {\bf Bacula} will write the bootstrap records to a file and request your
 approval to start a restore job. 
@@ -282,11 +361,13 @@ OK to run? (yes/mod/no):
 \normalsize
 
 Please examine each of the items very carefully to make sure that they are
-correct. In particular, look at {\bf Where}, which tells you where in the
-directory structure the files will be restored, and {\bf Client}, which tells
-you which client will receive the files. These items will not always be
-completed with the correct values depending on which of the restore options
-you chose. 
+correct.  In particular, look at {\bf Where}, which tells you where in the
+directory structure the files will be restored, and {\bf Client}, which
+tells you which client will receive the files.  Note that by default the
+Client which will receive the files is the Client that was backed up.
+These items will not always be completed with the correct values depending
+on which of the restore options you chose.  You can change any of these
+default items by entering {\bf mod} and responding to the prompts.
 
 The above assumes that you have defined a {\bf Restore} Job resource in your
 Director's configuration file. Normally, you will only need one Restore Job
@@ -336,14 +417,17 @@ prompt list:
 To select the JobIds, you have the following choices:
      1: List last 20 Jobs run
      2: List Jobs where a given File is saved
-     3: Enter list of JobIds to select
+     3: Enter list of comma separated JobIds to select
      4: Enter SQL list command
      5: Select the most recent backup for a client
      6: Select backup for a client before a specified time
      7: Enter a list of files to restore
      8: Enter a list of files to restore before a specified time
-     9: Cancel
-Select item:  (1-9): 7
+     9: Find the JobIds of the most recent backup for a client
+    10: Find the JobIds for a backup for a client before a specified time
+    11: Enter a list of directories to restore for found JobIds
+    12: Cancel
+Select item:  (1-12):
 \end{verbatim}
 \normalsize
 
@@ -427,7 +511,7 @@ restore client=Rufus file=</tmp/file-list
 \normalsize
 
 If in modifying the parameters for the Run Restore job, you find that Bacula
-asks you to enter a Job number, this is because you have no yet specified
+asks you to enter a Job number, this is because you have not yet specified
 either a Job number or a Bootstrap file. Simply entering zero will allow you
 to continue and to select another option to be modified. 
 \label{CommandArguments}
@@ -471,7 +555,8 @@ automatically find the most  recent prior Full save and all Differential and
 Incremental  saves run before the date you specify. Note, this command is  not
 too user friendly in that you must specify the date/time  exactly as shown. 
 \item {\bf file=filename} -- specify a filename to be restored. You  must
-   specify the full path and filename. Prefixing the entry  with a less-than sign
+   specify the full path and filename. Prefixing the entry  with a less-than
+sign
    (\lt{}) will cause Bacula to assume that the  filename is on your system and
 contains a list of files to be  restored. Bacula will thus read the list from
 that file. Multiple  file=xxx specifications may be specified on the command
@@ -497,21 +582,38 @@ encounter, and for same machine restores, how to avoid them.
 \begin{itemize}
 \item You backed up on one machine and are restoring to another that is 
    either a different OS or doesn't have the same users/groups defined.  Bacula
-   does the best it can in these situations.  
-\item You are restoring into a directory that is already created and has  file
-   creation restrictions. Bacula tries to reset everything  but without walking
-   up the full chain of directories and modifying  them all during the restore,
-which Bacula does and will not do,  getting permissions back correctly in this
-situation depends to a  large extent on your OS.  
-\item You selected one or more files in a directory, but did not select  the
-   directory entry to be restored. In that case, if the directory  is not on disk
-   Bacula simply creates the directory with some default  attributes which may
-not be the same as the original.  If you do not select a directory and all its
-contents to be restored,  you can still select items within the directory to
-be restored by  individually marking those files, but in that case, you should
-individually use the ''markdir`` command to select all higher level 
-directory entries (one at a time) to be restored if you want the  directory
-entries properly restored. 
+   does the best it can in these situations. Note, Bacula has saved the
+   user/groups in numeric form, which means on a different machine, they
+   may map to different user/group names.
+\item You are restoring into a directory that is already created and has
+   file creation restrictions.  Bacula tries to reset everything but
+   without walking up the full chain of directories and modifying them all
+   during the restore, which Bacula does and will not do, getting
+   permissions back correctly in this situation depends to a large extent
+   on your OS.
+\item You are doing a recursive restore of a directory tree.  In this case
+   Bacula will restore a file before restoring the file's parent directory
+   entry.  In the process of restoring the file Bacula will create the
+   parent directory with open permissions and ownership of the file being
+   restored.  Then when Bacula tries to restore the parent directory Bacula
+   sees that it already exists (Similar to the previous situation).  If you
+   had set the Restore job's "Replace" property to "never" then Bacula will
+   not change the directory's permissions and ownerships to match what it
+   backed up, you should also notice that the actual number of files
+   restored is less then the expected number.  If you had set the Restore
+   job's "Replace" property to "always" then Bacula will change the
+   Directory's ownership and permissions to match what it backed up, also
+   the actual number of files restored should be equal to the expected
+   number.
+\item You selected one or more files in a directory, but did not select the
+   directory entry to be restored.  In that case, if the directory is not
+   on disk Bacula simply creates the directory with some default attributes
+   which may not be the same as the original.  If you do not select a
+   directory and all its contents to be restored, you can still select
+   items within the directory to be restored by individually marking those
+   files, but in that case, you should individually use the "markdir"
+   command to select all higher level directory entries (one at a time) to
+   be restored if you want the directory entries properly restored.
 \end{itemize}
 
 \label{Windows}
@@ -531,10 +633,10 @@ File daemon runs under the SYSTEM account, the directory will be created
 with SYSTEM ownership and permissions.  In this case, you may have problems
 accessing the newly restored files.
 
-To avoid this problem, you should create any alternate directory before doing the
-restore. Bacula will not change the ownership and permissions of the directory
-if it is already created as long as it is not one of the directories being
-restored (i.e. written to tape). 
+To avoid this problem, you should create any alternate directory before
+doing the restore.  Bacula will not change the ownership and permissions of
+the directory if it is already created as long as it is not one of the
+directories being restored (i.e.  written to tape).
 
 The default restore location is {\bf /tmp/bacula-restores/} and if you are
 restoring from drive {\bf E:}, the default will be 
@@ -553,32 +655,25 @@ the problem.
 \index[general]{Restoring Files Can Be Slow }
 \addcontentsline{toc}{subsection}{Restoring Files Can Be Slow}
 
-Restoring files is generally {\bf much} slower than backing it up for several
+Restoring files is generally {\bf much} slower than backing them up for several
 reasons. The first is that during a backup the tape is normally already
 positioned and Bacula only needs to write. On the other hand, because restoring
-files is done so rarely, Bacula keeps only the he start file and block on the
+files is done so rarely, Bacula keeps only the start file and block on the
 tape for the whole job rather than on a file by file basis which would use
 quite a lot of space in the catalog. 
 
-Bacula versions 1.31a and older would seek to the first file on the first
-tape, then sequentially search the tape for the specified files. If you were
-doing a full restore, this is OK, but if you want to restore one or two files,
-the process could be quite long. 
-
-This deficiency has been corrected in version 1.32. The consequence is that
 Bacula will forward space to the correct file mark on the tape for the Job,
 then forward space to the correct block, and finally sequentially read each
 record until it gets to the correct one(s) for the file or files you want to
 restore. Once the desired files are restored, Bacula will stop reading the
-tape. For restoring a small number of files, version 1.32 and greater are
-hundreds of times faster than previous versions. 
+tape. 
 
 Finally, instead of just reading a file for backup, during the restore, Bacula
 must create the file, and the operating system must allocate disk space for
 the file as Bacula is restoring it. 
 
 For all the above reasons the restore process is generally much slower than
-backing up
+backing up (sometimes it takes three times as long).
 
 \subsection*{Problems Restoring Files}
 \index[general]{Files!Problems Restoring }
@@ -618,23 +713,60 @@ Try the following things, each separately, and reset your Device resource to
 what it is now after each individual test: 
 
 \begin{enumerate}
-\item Set ''Block Positioning = no`` in your Device resource  and try the
+\item Set "Block Positioning = no" in your Device resource  and try the
    restore. This is a new directive and untested. 
-\item Set ''Minimum Block Size = 512`` and ''Maximum  Block Size = 512`` and
-   try the restore. Again send me the  full job report output. If you are able to
-   determine the  block size your drive was previously using, you should try 
-that size if 512 does not work. 
+\item Set "Minimum Block Size = 512" and "Maximum  Block Size = 512" and
+   try the restore.  If you are able to determine the block size your drive
+   was previously using, you should try that size if 512 does not work.
 \item Try editing the restore.bsr file at the Run xxx yes/mod/no prompt 
-   before starting the restore job and remove all the VolBlock  statements. These
-   are what causes Bacula to reposition the tape,  and where problems occur if
-you have a fixed block size set  for your drive. The VolFile commands also
-cause repositioning,  but this will work regardless of the block size. 
+   before starting the restore job and remove all the VolBlock statements.
+   These are what causes Bacula to reposition the tape, and where problems
+   occur if you have a fixed block size set for your drive.  The VolFile
+   commands also cause repositioning, but this will work regardless of the
+   block size.
 \item Use bextract to extract the files you want -- it reads the  Volume
-   sequentially if you use the include list feature, or  if you use a .bsr file,
-   but remove all the VolBlock statements  after the .bsr file is created (at the
-Run yes/mod/no) prompt but  before you start the restore. 
+   sequentially if you use the include list feature, or if you use a .bsr
+   file, but remove all the VolBlock statements after the .bsr file is
+   created (at the Run yes/mod/no) prompt but before you start the restore.
 \end{enumerate}
 
+\subsection*{Restore Errors}
+\index[general]{Errors!Restore}
+\index[general]{Restore Errors}
+\addcontentsline{toc}{subsection}{Restore Errors}
+
+There are a number of reasons why there may be restore errors or
+warning messages. Some of the more common ones are:
+
+\begin{description}
+
+\item [file count mismatch]
+  This can occur for the following reasons:
+  \begin{itemize}
+  \item You requested Bacula not to overwrite existing or newer
+     files.
+  \item A Bacula miscount of files/directories. This is an
+     on-going problem due to the complications of directories,
+     soft/hard link, and such.  Simply check that all the files you
+     wanted were actually restored.
+  \end{itemize}
+\item [file size error]
+   When Bacula restores files, it checks that the size of the
+   restored file is the same as the file status data it saved 
+   when starting the backup of the file. If the sizes do not
+   agree, Bacula will print an error message. This size mismatch
+   most often occurs because the file was being written as Bacula
+   backed up the file. In this case, the size that Bacula
+   restored will be greater than the status size.  This often
+   happens with log files.
+
+   If the restored size is smaller, then you should be concerned
+   about a possible tape error and check the Bacula output as
+   well as your system logs.
+\end{description}
+
+
+
 \subsection*{Example Restore Job Resource}
 \index[general]{Example Restore Job Resource }
 \index[general]{Resource!Example Restore Job }
@@ -678,65 +810,72 @@ mark} command. The available commands are:
 \begin{description}
 
 \item [cd]
-   The {\bf cd} command changes the current directory to  the argument specified.
+   The {\bf cd} command changes the current directory to  the argument
+   specified.
    It operates much like the Unix {\bf cd} command.  Wildcard specifications are
-not permitted.  
+   not permitted.  
 
-Note, on Windows systems, the various drives (c:, d:, ...) are treated  like a
-directory within the file tree while in the file  selection mode. As a
-consequence, you must do a {\bf cd c:} or  possibly in some cases a {\bf cd
-C:} (note upper case)  to get down to the first directory.  
+   Note, on Windows systems, the various drives (c:, d:, ...) are treated  like
+   a
+   directory within the file tree while in the file  selection mode. As a
+   consequence, you must do a {\bf cd c:} or  possibly in some cases a {\bf cd
+   C:} (note upper case)  to get down to the first directory.  
 
 \item [dir]
    \index[dir]{dir }
    The {\bf dir} command is similar to the {\bf ls} command,  except that it
-prints it in long format (all details). This command  can be a bit slower than
-the {\bf ls} command because it must access  the catalog database for the
-detailed information for each file.  
+   prints it in long format (all details). This command  can be a bit slower
+   than
+   the {\bf ls} command because it must access  the catalog database for the
+   detailed information for each file.  
 
 \item [estimate]
    \index[dir]{estimate }
    The {\bf estimate} command prints a summary of  the total files in the tree,
-how many are marked to be restored, and  an estimate of the number of bytes to
-be restored. This can be useful  if you are short on disk space on the machine
-where the files will be  restored.  
+   how many are marked to be restored, and  an estimate of the number of bytes
+   to
+   be restored. This can be useful  if you are short on disk space on the
+   machine
+   where the files will be  restored.  
 
 \item [find]
    \index[dir]{find }
    The {\bf find} command accepts one or more arguments  and displays all files
-in the tree that match that argument. The argument  may have wildcards. It is
-somewhat similar to the Unix command  {\bf find / -name arg}.  
+   in the tree that match that argument. The argument  may have wildcards. It is
+   somewhat similar to the Unix command  {\bf find / -name arg}.  
 
 \item [ls]
    The {\bf ls} command produces a listing of all the files  contained in the
    current directory much like the Unix {\bf ls} command.  You may specify an
-argument containing wildcards, in which case only  those files will be listed.
-Any file that is marked to be restored will  have its name preceded by an
-asterisk ({\bf *}). Directory names  will be terminated with a forward slash
-({\bf /}) to distinguish them  from filenames.  
+   argument containing wildcards, in which case only  those files will be
+listed.
+   Any file that is marked to be restored will  have its name preceded by an
+   asterisk ({\bf *}). Directory names  will be terminated with a forward slash
+   ({\bf /}) to distinguish them  from filenames.  
 
 \item [lsmark]
    \index[fd]{lsmark }
    The {\bf lsmark} command is the same as the  {\bf ls} except that it will
-print only those files marked for  extraction. The other distinction is that
-it will recursively  descend into any directory selected. 
+   print only those files marked for  extraction. The other distinction is that
+   it will recursively  descend into any directory selected. 
 
 \item [mark]
    \index[dir]{mark }
-   The {\bf mark} command allows you to mark files  to be restored. It takes a
-single argument which is the filename  or directory name in the current
-directory to be marked for extraction.  The argument may be a wildcard
-specification, in which  case all files that match in the current directory
-are marked to be  restored. If the argument matches a directory rather than a
-file,  then the directory and all the files contained in that directory
-(recursively)  are marked to be restored. Any marked file will have its name 
-preceded with an asterisk ({\bf *}) in the output produced by the  {\bf ls} or
-{\bf dir} commands. Note, supplying a full path on  the mark command does not
-work as expected to select a file or  directory in the current directory.
-Also, the {\bf mark} command works  on the current and lower directories but
-does not touch higher level  directories.  
-
-After executing the {\bf mark} command, it will print a brief summary:  
+   The {\bf mark} command allows you to mark files to be restored. It takes a
+   single argument which is the filename  or directory name in the current
+   directory to be marked for extraction.  The argument may be a wildcard
+   specification, in which  case all files that match in the current directory
+   are marked to be  restored. If the argument matches a directory rather than a
+   file,  then the directory and all the files contained in that directory
+   (recursively)  are marked to be restored. Any marked file will have its name 
+   preceded with an asterisk ({\bf *}) in the output produced by the  {\bf ls}
+or
+   {\bf dir} commands. Note, supplying a full path on  the mark command does not
+   work as expected to select a file or  directory in the current directory.
+   Also, the {\bf mark} command works  on the current and lower directories but
+   does not touch higher level  directories.  
+
+   After executing the {\bf mark} command, it will print a brief summary:  
 
 \footnotesize
 \begin{verbatim}
@@ -745,7 +884,7 @@ After executing the {\bf mark} command, it will print a brief summary:
 \end{verbatim}
 \normalsize
 
-If no files were marked, or:  
+   If no files were marked, or:  
 
 \footnotesize
 \begin{verbatim}
@@ -754,25 +893,25 @@ If no files were marked, or:
 \end{verbatim}
 \normalsize
 
-if some files are marked.  
+   if some files are marked.  
 
 \item [unmark]
    \index[dir]{unmark }
    The {\bf unmark} is identical to the {\bf mark}  command, except that it
-unmarks the specified file or files so that  they will not be restored. Note:
-the {\bf unmark} command works from  the current directory, so it does not
-unmark any files at a higher  level. First do a {\bf cd /} before the {\bf
-unmark *} command if  you want to unmark everything.  
+   unmarks the specified file or files so that  they will not be restored. Note:
+   the {\bf unmark} command works from  the current directory, so it does not
+   unmark any files at a higher  level. First do a {\bf cd /} before the {\bf
+   unmark *} command if  you want to unmark everything.  
 
 \item [pwd]
    \index[dir]{pwd }
    The {\bf pwd} command prints the current working  directory. It accepts no
-arguments.  
+   arguments.  
 
 \item [count]
    \index[dir]{count }
    The {\bf count} command prints the total files in the  directory tree and the
-number of files marked to be restored.  
+   number of files marked to be restored.  
 
 \item [done]
    \index[dir]{done }
@@ -784,7 +923,8 @@ number of files marked to be restored.
 
 \item [quit]
    \index[fd]{quit }
-   This command terminates the file selection and does  not run the restore job. 
+   This command terminates the file selection and does  not run the restore
+job. 
 
 
 \item [help]
@@ -793,4 +933,333 @@ number of files marked to be restored.
 
 \item [?]
    This command is the same as the {\bf help} command.  
-   \end{description}
+\end{description}
+
+\label{database_restore}
+\subsection*{Restoring When Things Go Wrong}
+\index[general]{Restoring When Things Go Wrong }
+\index[general]{Restoring Your Database}
+\index[general]{Database!Restoring}
+\addcontentsline{toc}{subsection}{Restoring When Things Go Wrong}
+
+This and the following sections will try to present a few of the kinds of
+problems that can come up making restoring more difficult. I'll try to
+provide a few ideas how to get out of these problem situations.
+In addition to what is presented here, there is more specific information
+on restoring a \ilink{Client}{restore_client} and your
+\ilink{Server}{restore_server} in the \ilink{Disaster Recovery Using
+Bacula}{_ChapterRescue} chapter of this manual.
+
+\begin{description}
+\item[Problem]
+   My database is broken.
+\item[Solution]
+   For SQLite, use the vacuum command to try to fix the database. For either
+   MySQL or PostgreSQL, see the vendor's documentation. They have specific tools
+   that check and repair databases, see the \ilink{database
+   repair}{DatabaseRepair} sections of this manual for links to vendor    
+   information.
+
+   Assuming the above does not resolve the problem, you will need to restore
+   or rebuild your catalog.  Note, if it is a matter of some
+   inconsistencies in the Bacula tables rather than a broken database, then
+   running \ilink{dbcheck}{dbcheck} might help, but you will need to ensure
+   that your database indexes are properly setup.  Please see
+   the \ilink{Database Performance Issues}{DatabasePerformance} sections
+   of this manual for more details.
+
+\item[Problem]
+   How do I restore my catalog?
+\item[Solution with a Catalog backup]
+   If you have backed up your database nightly (as you should) and you
+   have made a bootstrap file, you can immediately load back your
+   database (or the ASCII SQL output).  Make a copy of your current
+   database, then re-initialize it, by running the following scripts:
+\begin{verbatim}
+   ./drop_bacula_tables
+   ./make_bacula_tables
+\end{verbatim}
+   After re-initializing the database, you should be able to run 
+   Bacula. If you now try to use the restore command, it will not 
+   work because the database will be empty. However, you can manually
+   run a restore job and specify your bootstrap file. You do so
+   by entering the {bf run} command in the console and selecting the
+   restore job.  If you are using the default bacula-dir.conf, this
+   Job will be named {\bf RestoreFiles}. Most likely it will prompt
+   you with something such as:
+\footnotesize
+\begin{verbatim}
+Run Restore job
+JobName:    RestoreFiles
+Bootstrap:  /home/kern/bacula/working/restore.bsr
+Where:      /tmp/bacula-restores
+Replace:    always
+FileSet:    Full Set
+Client:     rufus-fd
+Storage:    File
+When:       2005-07-10 17:33:40
+Catalog:    MyCatalog
+Priority:   10
+OK to run? (yes/mod/no): 
+\end{verbatim}
+\normalsize
+   A number of the items will be different in your case.  What you want to
+   do is: to use the mod option to change the Bootstrap to point to your
+   saved bootstrap file; and to make sure all the other items such as
+   Client, Storage, Catalog, and Where are correct.  The FileSet is not
+   used when you specify a bootstrap file.  Once you have set all the
+   correct values, run the Job and it will restore the backup of your
+   database, which is most likely an ASCII dump. 
+
+   You will then need to follow the instructions for your
+   database type to recreate the database from the ASCII backup file.
+   See the \ilink {Catalog Maintenance}{_ChapterStart12} chapter of
+   this manual for examples of the command needed to restore a 
+   database from an ASCII dump (they are shown in the Compacting Your
+   XXX Database sections).
+    
+   Also, please note that after you restore your database from an ASCII
+   backup, you do NOT want to do a {\bf make_bacula_tables}  command, or
+   you will probably erase your newly restored database tables.
+
+      
+\item[Solution with a Job listing]
+   If you did save your database but did not make a bootstrap file, then
+   recovering the database is more difficult.  You will probably need to
+   use bextract to extract the backup copy.  First you should locate the
+   listing of the job report from the last catalog backup.  It has
+   important information that will allow you to quickly find your database
+   file.  For example, in the job report for the CatalogBackup shown below,
+   the critical items are the Volume name(s), the Volume Session Id and the
+   Volume Session Time.  If you know those, you can easily restore your
+   Catalog.
+\footnotesize
+\begin{verbatim}
+
+22-Apr 10:22 HeadMan: Start Backup JobId 7510,
+Job=CatalogBackup.2005-04-22_01.10.0
+22-Apr 10:23 HeadMan: Bacula 1.37.14 (21Apr05): 22-Apr-2005 10:23:06
+  JobId:                  7510
+  Job:                    CatalogBackup.2005-04-22_01.10.00
+  Backup Level:           Full
+  Client:                 Polymatou
+  FileSet:                "CatalogFile" 2003-04-10 01:24:01
+  Pool:                   "Default"
+  Storage:                "DLTDrive"
+  Start time:             22-Apr-2005 10:21:00
+  End time:               22-Apr-2005 10:23:06
+  FD Files Written:       1
+  SD Files Written:       1
+  FD Bytes Written:       210,739,395
+  SD Bytes Written:       210,739,521
+  Rate:                   1672.5 KB/s
+  Software Compression:   None
+  Volume name(s):         DLT-22Apr05
+  Volume Session Id:      11
+  Volume Session Time:    1114075126
+  Last Volume Bytes:      1,428,240,465
+  Non-fatal FD errors:    0
+  SD Errors:              0
+  FD termination status:  OK
+  SD termination status:  OK
+  Termination:            Backup OK
+
+\end{verbatim}
+\normalsize
+
+  From the above information, you can manually create a bootstrap file,
+  and then follow the instructions given above for restoring your database.
+  A reconstructed bootstrap file for the above backup Job would look
+  like the following:
+
+\footnotesize
+\begin{verbatim}
+Volume="DLT-22Apr05"
+VolSessionId=11
+VolSessionTime=1114075126
+FileIndex=1-1
+\end{verbatim}
+\normalsize    
+
+  Where we have inserted the Volume name, Volume Session Id, and Volume
+  Session Time that correspond to the values in the job report.  We've also
+  used a FileIndex of one, which will always be the case providing that
+  there was only one file backed up in the job.
+  
+  The disadvantage of this bootstrap file compared to what is created when
+  you ask for one to be written, is that there is no File and Block
+  specified, so the restore code must search all data in the Volume to find
+  the requested file.  A fully specified bootstrap file would have the File
+  and Blocks specified as follows:
+
+\footnotesize
+\begin{verbatim}
+Volume="DLT-22Apr05"
+VolSessionId=11
+VolSessionTime=1114075126
+VolFile=118-118
+VolBlock=0-4053
+FileIndex=1-1
+\end{verbatim}
+\normalsize
+
+   Once you have restored the ASCII dump of the database,
+   you will then to follow the instructions for your
+   database type to recreate the database from the ASCII backup file.
+   See the \ilink {Catalog Maintenance}{_ChapterStart12} chapter of
+   this manual for examples of the command needed to restore a 
+   database from an ASCII dump (they are shown in the Compacting Your
+   XXX Database sections).
+    
+   Also, please note that after you restore your database from an ASCII
+   backup, you do NOT want to do a {\bf make_bacula_tables}  command, or
+   you will probably erase your newly restored database tables.
+
+\item [Solution withou a Job Listing]
+   If you do not have a job listing, then it is a bit more difficult.
+   Either you use the \ilink{bscan}{bscan} program to scan the contents
+   of your tape into a database, which can be very time consuming 
+   depending on the size of the tape, or you can use the \ilink{bls}{bls}
+   program to list everything on the tape, and reconstruct a bootstrap 
+   file from the bls listing for the file or files you want following
+   the instructions given above.
+
+   There is a specific example of how to use {\bf bls} below.
+
+\item [Problem]
+   I try to restore the last known good full backup by specifying
+   item 3 on the restore menu then the JobId to restore.  Bacula 
+   then reports:
+
+\footnotesize
+\begin{verbatim}
+   1 Job 0 Files
+\end{verbatim}
+\normalsize
+   and restores nothing.
+\item[Solution]
+   Most likely the File records were pruned from the database either due
+   to the File Retention period expiring or by explicitly purging the
+   Job. By using the "llist jobid=nn" command, you can obtain all the
+   important information about the job:
+\footnotesize
+\begin{verbatim}
+llist jobid=120
+           JobId: 120
+             Job: save.2005-12-05_18.27.33
+        Job.Name: save
+     PurgedFiles: 0
+            Type: B
+           Level: F
+    Job.ClientId: 1
+     Client.Name: Rufus
+       JobStatus: T
+       SchedTime: 2005-12-05 18:27:32
+       StartTime: 2005-12-05 18:27:35
+         EndTime: 2005-12-05 18:27:37
+        JobTDate: 1133803657
+    VolSessionId: 1
+  VolSessionTime: 1133803624
+        JobFiles: 236
+       JobErrors: 0
+ JobMissingFiles: 0
+      Job.PoolId: 4
+       Pool.Name: Full
+   Job.FileSetId: 1
+ FileSet.FileSet: BackupSet
+\end{verbatim}
+\normalsize
+
+   Then you can find the Volume(s) used by doing:
+\footnotesize
+\begin{verbatim}
+sql
+select VolumeName from JobMedia,Media where JobId=1 and JobMedia.MediaId=Media.MediaId;
+\end{verbatim}
+\normalsize
+   Finally, you can create a bootstrap file as described in the previous
+   problem above using this information.
+
+   If you are using Bacula version 1.38.0 or greater, when you select
+   item 3 from the menu and enter the JobId, it will ask you if
+   you would like to restore all the files in the job, and it will
+   collect the above information and write the bootstrap file for
+   you.
+
+\item [Problem]
+  You don't have a bootstrap file, and you don't have the Job report for
+  the backup of your database, but you did backup the database, and you
+  know the Volume to which it was backed up.
+  
+\item [Solution]
+  Either bscan the tape, or use {\bf bls} to indicate where it is on the
+  tape.  For example:
+
+\footnotesize
+\begin{verbatim}
+./bls -j -V DLT-22Apr05 /dev/nst0
+\end{verbatim}
+\normalsize
+  Might produce the following output:
+\footnotesize
+\begin{verbatim}
+bls: butil.c:258 Using device: "/dev/nst0" for reading.
+21-Jul 18:34 bls: Ready to read from volume "DLT-22Apr05" on device "DLTDrive"
+(/dev/nst0).
+Volume Record: File:blk=0:0 SessId=11 SessTime=1114075126 JobId=0 DataLen=164
+...
+Begin Job Session Record: File:blk=118:0 SessId=11 SessTime=1114075126
+JobId=7510
+   Job=CatalogBackup.2005-04-22_01.10.0 Date=22-Apr-2005 10:21:00 Level=F Type=B
+End Job Session Record: File:blk=118:4053 SessId=11 SessTime=1114075126
+JobId=7510
+   Date=22-Apr-2005 10:23:06 Level=F Type=B Files=1 Bytes=210,739,395 Errors=0
+Status=T
+...
+21-Jul 18:34 bls: End of Volume at file 201 on device "DLTDrive" (/dev/nst0),
+Volume "DLT-22Apr05"
+21-Jul 18:34 bls: End of all volumes.
+\end{verbatim}
+\normalsize
+  Of course, there will be many more records printed, but we have indicated
+  the essential lines of output. From the information on the Begin Job and End 
+  Job Session Records, you can reconstruct a bootstrap file such as the one
+  shown above.
+
+\item[Problem]
+  How can I find where a file is stored.
+\item[Solution]
+  Normally, it is not necessary, you just use the {\bf restore} command to
+  restore the most recently saved version (menu option 5), or a version
+  saved before a given date (menu option 8).  If you know the JobId of the
+  job in which it was saved, you can use menu option 3 to enter that JobId.
+
+  If you would like to know the JobId where a file was saved, select
+  restore menu option 2.
+
+  You can also use the {\bf query} command to find information such as: 
+\footnotesize
+\begin{verbatim}
+*query
+Available queries:
+     1: List Job totals:
+     2: List up to 20 places where a File is saved regardless of the directory:
+     3: List where the most recent copies of a file are saved:
+     4: List last 20 Full Backups for a Client:
+     5: List all backups for a Client after a specified time
+     6: List all backups for a Client
+     7: List Volume Attributes for a selected Volume:
+     8: List Volumes used by selected JobId:
+     9: List Volumes to Restore All Files:
+    10: List Pool Attributes for a selected Pool:
+    11: List total files/bytes by Job:
+    12: List total files/bytes by Volume:
+    13: List Files for a selected JobId:
+    14: List Jobs stored in a selected MediaId:
+    15: List Jobs stored for a given Volume name:
+Choose a query (1-15):
+\end{verbatim}
+\normalsize
+
+
+\end{description}