Bacula 1.30 User's Guide | Chapter 8

The Console Program | Index | Disaster Recovery Using Bacula

# The Bacula Console Restore Command

## General

Below, we will discuss restoring files with the Console Restore command, which is the recommended way of doing it. However, there is a standalone program named bextract, which also permits restoring files. For more information on this program, please see the Bacula Utility Programs chapter of this manual. There is also a program named bscan documented in the same Bacula Utility Programs chapter that permits restoring a catalog database from tapes.

In general, to restore a file or a set of files, you must run a restore job. That is a job with Type = Restore. As a consequence, you should have a predefined restore job in your 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 restore command, explained below, they will be automatically set for you.

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 correct Client and the correct location for restoring those files. Bacula will quite willingly backup client A, and restore it by sending 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.

## The Restore Command

The restore command in the Console program allows you to first select one or more Jobs (JobIds) to be restored using various methods, explained below. Once the JobIds are selected, the File records for those Jobs are placed in an internal Bacula directory tree, and the restore enters a file selection mode that allows you to interactively walk up and down the file tree selecting individual files to be restored. This mode is somewhat similar to the standard Unix restore program's interactive file selection mode.

Within the Console program, after entering the restore command, you are presented with the following selection prompt:

    First you select one or more JobIds that contain files
    to be restored. You will be presented several methods
    of specifying the JobIds. Then you will be allowed to
    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
         4: Enter SQL list command
         5: Select the most recent backup for a client
         6: Cancel
    Select item:  (1-6):

- 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 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.
- Item 3 allows you the enter a list of comma separated JobIds whose files will be put into the directory tree.
- 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.
- 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.
- Item 6 allows you to cancel the restore command.

As an example, suppose that we select item 5. It will then ask for the desired Client, which on my system, will print the all the Clients found in the database as follows:

    Defined clients:
         1: Rufus
         2: Matou
         3: Polymatou
         4: Minimatou
         5: Minou
         6: MatouVerify
         7: PmatouVerify
         8: RufusVerify
         9: Watchdog
    Select Client (File daemon) resource (1-9):

I enter Rufus, and Bacula needs to know what FileSet is to be restored, so it prompts with:

    The defined FileSet resources are:
         1: Full Set      i7/6gj+3j/QTsV+Ukx/xsB
         2: Kerns Files   qi@s8kuw7/SRvM@Vxm/vaN
    Select FileSet resource (1-2):

To which, I choose item 1, which is my full backup. Note, the items that follow your FileSet names are an MD5 signature of the contents of the FileSet. In fact, the FileSet ID will change each time you edit the FileSet definition. As a consequence, it is possible to have two "Full Set" entries above, but each one will have a different MD5 signature. You are urged to change your FileSet name every time you change the contents to avoid any confusion of the name.

At this point, Bacula has all the information it needs to find the most recent set of backups. It will then query the database, which may take a bit of time, and it will come up with something like the following. Note, some of the columns are truncated here for presentation:

    +-------+------+----------+------------------+-------------+---------+----------+------------+
    | JobId | Levl | JobFiles | StartTime        | VolumeName  | StrtFil | VolSesId | VolSesTime |
    +-------+------+----------+------------------+-------------+---------+----------+------------+
    | 1,792 | F    |  128,374 | 2002-08-03 01:58 | DLT-19Jul02 |      67 |       18 | 1028042998 |
    | 1,792 | F    |  128,374 | 2002-08-03 01:58 | DLT-04Aug02 |       0 |       18 | 1028042998 |
    | 1,797 | I    |      254 | 2002-08-04 13:53 | DLT-04Aug02 |       5 |       23 | 1028042998 |
    | 1,798 | I    |       15 | 2002-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 ...
    Building directory tree for JobId 1798 ...

    cwd is: /
    $

Depending on the number of JobFiles for each JobId, the Building directory tree ..." can take a bit of time.

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 it that Job wrote on two different Volumes. The third Job was an incremental backup to the previous Full backup, and it only saved 254 Files compared to 128,374 for the Full backup. The fourth Job was also an incremental backup that saved 15 files.

Next Bacula entered those Jobs into the directory tree, and as a default marks all files to be restored, tells you how many files are in the tree then tells you that the current working directory (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.

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 1792,1797,1798 we would have arrived at the same point.

While in file selection mode, you can enter help or a question mark (?) to produce a summary of the available commands:

      Command    Description
      =======    ===========
      mark       mark file for restoration
      unmark     unmark file for restoration
      cd         change current directory
      pwd        print current working directory
      ls         list current directory
      dir        list current directory
      count      count marked files
      find       find files
      done       leave file selection mode
      exit       exit = done
      help       print help
      ?          print help

As a default Bacula has selected all the files in the directory tree. If you want to do a full restore, simply enter done, and Bacula will write the bootstrap records to a file and request your approval to start a restore job.

If instead, you wish to start with an empty slate (i.e. no jobs marked for restoration), simply enter unmark *. Otherwise, you can simply start looking at the tree and unmark particular files or directories if you do not want them restored.

To check what is marked or not marked, enter the count command, which displays:

    128401 total files. 128401 marked for restoration.

Each of the above commands will be described in more detail in the next section. We continue with the above example, having accepted to restore all files as Bacula set by default. On entering the done command, Bacula prints:

    Bootstrap records written to /home/kern/bacula/working/restore.bsr

    The restore job will require the following Volumes:

       DLT-19Jul02
       DLT-04Aug02

    128401 files selected to restore.

    Run Restore job
    JobName:    kernsrestore
    Bootstrap:  /home/kern/bacula/working/restore.bsr
    Where:      /tmp/bacula-restores
    Replace:    always
    FileSet:    Kerns Files
    Client:     Rufus
    Storage:    SDT-10000
    JobId:      *None*
    OK to run? (yes/mod/no):

Please examine each of the items very carefully to make sure that they are correct. In particular, look at Where, which tells you where in the directory structure the files will be restored, and 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.

The above assumes that you have defined a Restore Job resource in your Director's configuration file. Normally, you will only need one Restore Job resource definition because by its nature, restoring is a manual operation, and using the Console interface, you will be able to modify the Restore Job to do what you want.

An example Restore Job resource definition is given below.

Returning to the example, you should verify that the Client name is correct before running the Job. However, you may want to modify some of the parameters of the restore job. For example, in addition to checking the Client it is wise to check that the Storage device chosen by Bacula is indeed correct. Although the FileSet is shown, it will be ignored in restore. The restore will choose the files to be restored either by reading the Bootstrap file, or if not is specified, it will restore all files associated with the specified backup JobId (i.e. the JobId of the Job that originally backed up the files).

Finally before running the job, please note that the default location for restoring files is not their original locations, rather the directory /tmp/bacula-restores. You can change this default by modifying your bacula-dir.conf file, or you can modify it using the mod option. If you want to restore the files to their original location, you must have Where set to nothing or to the root, i.e. /.

If you now enter yes, Bacula will run the restore Job. The Storage daemon will first request Volume DLT-19Jul02 and after the appropriate files have been restored from that volume, it will request Volume DLT-04Aug02.

## Example Restore Job Resource

    Job {
      Name = "RestoreFiles"
      Type = Restore
      Client = Any-client
      FileSet = "Any-FileSet"
      Storage = Any-storage
      Where = /tmp/bacula-restores
      Messages = Standard
      Pool = Default
    }

If Where is not specified, the default location for restoring files will be their original locations.

## File Selection Commands

After you have selected the Jobs to be restored and Bacula has created the in-memory directory tree, you will enter file selection mode as indicated by the dollar sign ($) prompt. While in this mode, you may use the commands listed above. The basic idea is to select the files that you want restored. As a default all files are marked for restoration. If you wish to start with no files, simply enter: unmark *. Then proceed to select the files you wish to restore by marking them with the mark command. The available commands are:

mark
  The mark command allows you to mark files for restoration. It takes a single argument which is the filename to be marked. The argument may be a wildcard specification, in which case all files that match in the current directory are marked for restoration. If the argument matches a directory rather than a file, then the directory and all files contained in that directory (recursively) are marked for restoration. Any marked file will have its name preceded with an asterisk (*) in the output produced by the ls or dir commands.
unmark
  The unmark is identical to the mark command, except that it unmarks the specified file or files so that they will not be restored.
cd
  The cd command changes the current directory to the argument specified. It operates much like the Unix cd command. Wildcard specifications are not permitted.
pwd
  The pwd command prints the current working directory. It accepts no arguments.
ls
  The ls command produces a listing of all the files contained in the current directory much like the Unix ls command. You may specify an argument containing wildcards, in which case only those files will be listed. Any file that is marked for restoration will have its name preceded by an asterisk (*). Directories names will be terminated with a forward slash (/) to distinguish them from filenames.
dir
  The dir command is the similar to the ls command, except that it prints it in long format (all details). This command can be a bit slower than the ls command because it must access the catalog database for the detailed information for each file.
count
  The count command prints the total files in the directory tree and the number of files marked to be restored.
find
  The 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 find / -name arg.
done
  This command terminates file selection mode.
exit
  This command terminates file selection mode (the same as done).
help
  This command prints a summary of the commands available.
?
  This command is the same as the help command.

The Console Program | Index | Disaster Recovery Using Bacula

Bacula 1.30 User's Guide The Network Backup Solution | Copyright © 2000-2003 Kern Sibbald and John Walker