
#include "bacula_template.inc" title="Running Bacula" num=6

<h1>Running Bacula</h1>
The general flow of running <b>Bacula</b> is:
<ol>
   <li>cd &lt;install-directory&gt;</li>
   <li>Start the Database (if using MySQL)</li>
   <li>Start the Daemons with <b>./bacula start</b></li>
   <li>Start the Console program to interact with the Director</li>
   <li>Run a job</li>
   <li>When the tape fills, unmount the old tape, label a    
       new one, and continue running</li>
    <li>Test recovering some files from the tape just written to 
       ensure the tape is good and that you know how to recover.
       Better test before disaster strikes</li>
</ol>
Each of these steps is described in more detail below.

<h2>Before Running Bacula</h2>
Before running <b>Bacula</b> for the first time, we recommend that
you run the <b>test</b> command in the <b>btape</b> program as
described in 
the <a href="progs.html#btape">Utility Program Chapter</a> of
this manual. This will help ensure that <b>Bacula</b> functions
correctly with your tape drive.  If you have a modern HP, Sony, or
Quantum DDS or DLT tape drive running on Linux or Solaris, you
can probably skip this test as <b>Bacula</b> is well tested
with these drives and systems. For all other cases, you are
<b>strongly</b> encouraged to run the test before continuing.
<b>btape</b> also has a <b>fill</b> command that attempts to
duplicate what Bacula does when filling a tape and writing
on the next tape. You should consider trying this command
as well, but be fore warned, it can take hours (about 4 hours on
my drive) to fill a large capacity tape.

<h2><a name="StartDB">Starting the Database</a></h2>
<p>If you are using MySQL as the <b>Bacula</b> database, you should start
it before you attempt to run a job to avoid getting error messages
from <b>Bacula</b> when it starts.
The scripts <b>startmysql</b> and <b>stopmysql</b>
are what I (Kern) use to start and stop my local MySQL.  Note,
if you are using SQLite, you will not
want to use <b>startmysql</b> or <b>stopmysql</b>. If you are
running this in production, you will probably want to
find some way to automatically start MySQL after each system reboot.

<p>If you are using SQLite (i.e. you specified
the <b>--with-sqlit=xxx</b> option on the <b>./configure</b> command,
you need do nothing. SQLite is automatically started
by <b>Bacula</b>.</p>

<h2><a name="StartDaemon">Starting the Daemons</a></h2>
To start the three daemons, from your installation directory, simply enter:
<p class="tty">./bacula start</p>
This script starts the Storage daemon, the File daemon, and
the Director daemon, which all normally run as daemons in the background.
<p>Note, on Windows, currently only the File daemon is ported, and
it must be started differently. Please see the 
<a href="win32.html">Windows Version of Bacula</a> Chapter
of this manual.
<p>The installation chapter of this manual explains how you can
install scripts that will automatically restart the daemons when
the system starts.

<h2>Daemon Command Line Options</h2>
Each of the three daemons (Director, File, Storage) accepts a
small set of options on the command line. In general, each
of the daemons as well as the Console program accepts the following options:
<dl>
  <dt>-c &lt;file&gt;</dt><dd>Define the file to use as a 
     configuration file. The default is the daemon name followed
     by <b>.conf</b> i.e. <b>bacula-dir.conf</b> for the Director,
     <b>bacula-fd.conf</b> for the File daemon, and <b>bacula-sd</b>
     for the Storage daemon.</dd>
  <dt>-d nn</dt><dd>Set the debug level to <b>nn</b>. Higher levels
     of debug cause more information to displayed on STDOUT concerning
     what the daemon is doing.</dd>
  <dt>-f</dt><dd>Run the daemon in the foreground. This option is
     needed to run the daemon under the debugger.</dd>
  <dt>-s</dt><dd>Do not trap signals. This option is needed to run
     the daemon under the debugger.</dd>
  <dt>-t</dt><dd>Read the configuration file and print any error messages,
     then immediately exit. Useful for syntax testing of
     new configuration files.</dd>
  <dt>-v</dt><dd>Be more verbose or more complete in printing error
     and informational messages. Recommended.</dd>
  <dt>-?</dt><dd>Print the version and list of options.</dd>
</dl>

The Director has the following additional Director specific option:
<dl>
  <dt>-r &lt;job&gt;</dt><dd>Run the named job immediately. This is
     for debugging and should not be used.</dd>
</dl>

The File daemon has the following File daemon specific option:
<dl>
  <dt>-i</dt><dd>Assume that the daemon is called from <b>inetd</b>
     or <b>xinetd</b>. In this case, the daemon assumes that a connection
     has already been made and that it is passed as STDIN. After the
     connection terminates the daemon will exit.</dt>
</dl>

The Storage daemon has no Storage daemon specific options.
<p>
The Console program has no console specific options.



<h2>Interacting with the Director to Query or Start Jobs</h2>
To communicate with the director and to query the state of <b>Bacula</b> or
run jobs, from the top level directory, simply enter:
<p class="tty">./console</p>
<p>Alternatively, if you have GNOME installed and used the
<b>--enable-gnome</b> on the configure command, you may
use the GNOME Console program:
<p class="tty">./gnome-console</p>
<p>For simplicity, here we will describe only the <b>./console</b>
program. Most of what is described here applies equally well
to <b>./gnome-console</b>.
<p>The <b>./console</b> runs the Bacula Console program,
which connects to the Director daemon. Since <b>Bacula</b> is a network
program, you can run the Console program anywhere on your network. 
Most frequently, however, one runs it on the same machine as the
Director.  Normally, the Console program will
print something similar to the following:
<pre>
[kern@polymatou bin]$ ./console
Connecting to Director lpmatou:9101
1000 OK: HeadMan Version: 1.30 (28 April 2003)
*
</pre>
the asterisk is the console command prompt.
<p></p>
Type <b>help</b> to see a list of available commands:
<pre>
*help
  Command    Description
  =======    ===========
  add        add media to a pool
  autodisplay autodisplay [on/off] -- console messages
  automount  automount [on/off] -- after label
  cancel     cancel job=nnn -- cancel a job
  create     create DB Pool from resource
  delete     delete [pool=&lt;pool-name&gt; | media volume=&lt;volume-name&gt;]
  help       print this command
  label      label a tape
  relabel    relabel a tape
  list       list [pools | jobs | jobtotals | media &lt;pool&gt; | 
             files job=&lt;nn&gt;]; from catalog
  llist      full or long list like list command
  messages   messages
  mount      mount &lt;storage-name&gt;
  restore    restore files
  prune      prune expired records from catalog
  purge      purge records from catalog
  run        run <job-name>
  setdebug   sets debug level
  show       show (resource records) [jobs | pools | ... | all]
  sqlquery   use SQL to query catalog
  status     status [storage | client]=&lt;name&gt;
  unmount    unmount &lt;storage-name&gt;
  update     update Volume or Pool
  use        use catalog xxx
  version    print Director version
  quit       quit
  query      query catalog
  time       print current time
  exit       exit = quit
  wait       wait until no jobs are running
*
</pre>
Details of the console program's commands are explained in
the <a href="console.html">Console Chapter</a> of this 
manual.

<h2>Have Patience When Starting the Daemons or Mounting Blank Tapes</h2>
<p>When you start the <b>Bacula</b> daemons, the Storage daemon
attempts to open all defined storage devices and verify the
currently mounted Volume (if configured). Until all the          
storage devices are verified, the Storage daemon will not 
accept connections from the Console program. If a tape
was previously used, it will be rewound, and on some devices
this can take several minutes. As a consequence,
you may need to have a bit of patience when first
contacting the Storage daemon after starting the daemons.
<p>
The same considerations apply if you have just mounted a blank tape in a
drive such as an HP DLT. It can take a minute or two before the drive
properly recognizes that the tape is blank.  If you attempt to
<b>mount</b> the tape with the Console program during this recognition
period, it is quite possible that you will hang your SCSI driver (at
least on my RedHat Linux system).  As a consequence, you are again urged
to have patience when inserting blank tapes.  Let the device settle down
before attempting to access it.

<h2>Last Steps Before Running a Job</h2>
There are only three more steps before you can run a job.
<ol>
  <li>Create a Pool to hold Volume names. Bacula will
      automatically create all Pools you defined in the
      Director's configuration file.</li>
  <li>You must label one or more Volume. That is
      physically write a label on the tape Volume. This
      can be done &quot;on the fly&quot; if you wish. </li>
  <li>You must add one or more Volume names (tapes, or files) to the
      Pool database.  If you use the <b>label</b> command, this last
      step will automatically be done.</li>

</ol>
<h2><a name="Pool">Creating a Pool</a></h2>
Creating the Pool is automatically done when <b>Bacula</b>
starts, so if you understand Pools, you can skip to the next section.
<p>
When you run a job, one of the things that <b>Bacula</b> must
know is what Volumes to use to backup the FileSet. Instead of
specifying a Volume (tape) directly, you specify which
Pool of Volumes you want <b>Bacula</b> to consult when it
wants a tape for writing backups. Bacula will
select the first available Volume from the Pool that
is appropriate for the Storage device you have specified
for the Job being run.
When a volume has filled up with data, <b>Bacula</b>
will change its VolStatus from <b>Append</b> to <b>Full</b>, and then
<b>Bacula</b> will use the next volume and so on. If no appendable
Volume exists in the Pool, the Director will attempt to recycle
an old Volume, if there are still no appendable Volumes available,
<b>Bacula</b> send messages requesting
the operator to create an appropriate Volume.
<p>
<b>Bacula</b> keeps track of the Pool name, the volumes contained in the
Pool, and a number of attributes of each of those Volumes.
<p></p>
When <b>Bacula</b> starts, it ensures that all
Pool resource definitions have been recorded in the
catalog. You can verify this by entering:
<pre>
list pools
</pre>
to the console program, which should print something like
the following:
<pre>
*list pools
Using default Catalog name=MySQL DB=bacula
+--------+---------+---------+---------+----------+-------------+
| PoolId | Name    | NumVols | MaxVols | PoolType | LabelFormat |
+--------+---------+---------+---------+----------+-------------+
| 1      | Default | 3       | 0       | Backup   | *           |
| 2      | File    | 12      | 12      | Backup   | File        |
+--------+---------+---------+---------+----------+-------------+
*
</pre>
If you attempt to create the same Pool name a second time, 
<b>Bacula</b> will print:
<pre>
Error: Pool Default already exists.
<p>Once created, you may use the <b>update</b> command to
modify many of the values in the Pool record.
</pre>

<h2><a name="Labeling">Labeling Your Volumes</a></h2>
Bacula requires that each Volume contain a software label.
There are several strategies for labeling volumes. The one
I use is to label them as they are needed by <b>Bacula</b>
using the console program. That is when <b>Bacula</b> needs
a new Volume, and it does not find one in the catalog, it
will send me an email message requesting that I add Volumes
to the Pool. I then use the <b>label</b> command in the
Console program to label a new Volume and to define 
it in the Pool database, after which <b>Bacula</b> will
begin writing on the new Volume.  Alternatively, I can
use the Console <b>relabel</b> command to relabel a Volume
that is no longer used providing it has VolStatus <b>Purged</b>.
<p>
Another strategy is to label
a set of volumes at the start, then use them as <b>Bacula</b>
requests them. This is most often done if you are cycling 
through a set of tapes, for example using an autochanger.  
For more details on recycling,
please see the <a href="recycling.html">Automatic Volume
Recycling</a> chapter of this manual.
<p>
If you run a <b>Bacula</b> job, and you have no labeled tapes
in the Pool, <b>Bacula</b> will inform you, and you can
create them &quot;on-the-fly&quot; so to speak. In my
case, I label my tapes with the date, for example:
<b>DLT-18April2002</b>.  See below for the details
of using the <b>label</b> command.

<h2>Labeling Volumes with the Console Program</h2>
Labeling volumes is normally done
by using the console program. 
<ol>
  <li>./console</li>
  <li>label</li>
</ol>
If <b>Bacula</b> complains that you cannot label the
tape because it is already labeled, simply 
<b>unmount</b> the tape using the <b>unmount</b>
command in the console, then physically mount
a blank tape and re-issue the <b>label</b>
command.
<p>
Since the physical storage media is different for
each device, the <b>label</b> command
will provide you with a list of the defined Storage resources
such as the following:
<pre>
The defined Storage resources are:
     1: Floppy
     2: File
     3: 8mmDrive
     4: DLTDrive
     5: SDT-10000
Select Storage resource (1-5):
</pre>
At this point, you should have a blank tape in the
drive corresponding to the Storage resource that you select.
<p>
It will then ask you for the Volume name.
<pre>
Enter new Volume name:
</pre>
If <b>Bacula</b> complains:
<pre>
Media record for Volume xxxx already exists.
</pre>
It means that the volume name <b>xxxx</b> that you entered
already exists in the Media database.  You can list all 
the defined Media (Volumes) with the <b>list media</b> command.
Note, the LastWritten column has been truncated for proper printing.
<font size=-2>
<pre>
+---------------+-----------+-----------+----------------+-----/~/-+------------+---------+
| VolumeName    | MediaType | VolStatus | VolBytes       | LastWri | VolReten   | Recycle |
+---------------+-----------+-----------+----------------+---------+------------+---------+
| DLTVol0002    | DLT8000   | Purged    | 56,128,042,217 | 2001-10 | 31,536,000 |       0 |
| DLT-07Oct2001 | DLT8000   | Full      | 56,172,030,586 | 2001-11 | 31,536,000 |       0 |
| DLT-08Nov2001 | DLT8000   | Full      | 55,691,684,216 | 2001-12 | 31,536,000 |       0 |
| DLT-01Dec2001 | DLT8000   | Full      | 55,162,215,866 | 2001-12 | 31,536,000 |       0 |
| DLT-28Dec2001 | DLT8000   | Full      | 57,888,007,042 | 2002-01 | 31,536,000 |       0 |
| DLT-20Jan2002 | DLT8000   | Full      | 57,003,507,308 | 2002-02 | 31,536,000 |       0 |
| DLT-16Feb2002 | DLT8000   | Full      | 55,772,630,824 | 2002-03 | 31,536,000 |       0 |
| DLT-12Mar2002 | DLT8000   | Full      | 50,666,320,453 | 1970-01 | 31,536,000 |       0 |
| DLT-27Mar2002 | DLT8000   | Full      | 57,592,952,309 | 2002-04 | 31,536,000 |       0 |
| DLT-15Apr2002 | DLT8000   | Full      | 57,190,864,185 | 2002-05 | 31,536,000 |       0 |
| DLT-04May2002 | DLT8000   | Full      | 60,486,677,724 | 2002-05 | 31,536,000 |       0 |
| DLT-26May02   | DLT8000   | Append    |  1,336,699,620 | 2002-05 | 31,536,000 |       1 |
+---------------+-----------+-----------+----------------+-----/~/-+------------+---------+
</pre>
</font>
<p>

Once <b>Bacula</b> has verified that the volume does not already exist,
it will then prompt you for the name of the Pool in which the Volume
(tape) to be created.  If there is only one Pool (Default), it will be
automatically selected.
<p>
If the tape is successfully labeled, a media record will also
be created in the Pool.  That is the Volume name and all its other
attributes will appear when you list the Pool. In addition, that
Volume will be available for backup if the MediaType matches
what is requested by the Storage daemon.
<p>When you labeled the tape, you answered very few questions
about it -- principally the Volume name, and perhaps the Slot.
However, a Volume record in the catalog database (internally known
as a Media record) contains quite a few attributes. Most of these
attributes will be filled in from the default values that were
defined in the Pool (i.e. the Pool holds most of the default attributes
used when creating a Volume).
<p>It is also possible to
add media to the pool without physically labeling the   
Volumes. This can be done with the <b>add</b> command.
For more information, please see
the <a href="console.html">Console Chapter</a> of this 
manual.


<h2><a name="Running">Running a Job</a></h2>
At this point, we assume you have done the following:
<ul>
 <li>Configured Bacula with <b>./configure --your-options</b></li>
 <li>Built Bacula using <b>make</b></li>
 <li>Installed Bacula using <b>make install</b></li>
 <li>Have created your database with, for example,
     <b>./create_sqlite_database</b></li>
 <li>Have created the Bacula database tables with,
     <b>./make_bacula_tables</b></li>
 <li>Have possibly edited your <b>bacula-dir.conf</b> file
     to personalize it a bit.  BE CAREFUL! if you change the
     Director's name or password, you will need to make similar
     modifications in the other .conf files. For the moment it is
     probably better to make the minimum changes.</li>
  <li>You have started Bacula with <b>./bacula start</b></li>
  <li>You have invoked the Console program with <b>./console</b></li>
</ul>
Furthermore, we assume for the moment you are using the default
configuration files. 
<p>
At this point, enter the following command:
<pre>
show filesets
</pre>
and you should get something similar to:
<pre>
FileSet: name=Full Set
      Inc: /home/kern/bacula/bacula-1.30
      Exc: /proc
      Exc: /tmp
      Exc: /.journal
      Exc: /.fsck
FileSet: name=Catalog
      Inc: /home/kern/bacula/testbin/working/bacula.sql
</pre>
This is a pre-defined <b>FileSet</b> that will backup the 
Bacula source directory. The actual directory names printed should
correspond to your configuration.  For testing purposes, we have
chosen a directory of moderate size (about 40 Megabytes)
and complexity without being too big. The FileSet <b>Catalog</b>
is used for backing up Bacula's catalog and is not of interest
to us for the moment. The <b>Inc:</b> entries are the files or
directories that will be included in the backup and the <b>Exc:</b>
are those that will be excluded.
<p>
Now is the time to run your first backup job. We are going to
backup your Bacula source director to a File Volume in your
<b>/tmp</b> directory just to show you how easy it is.
Now enter:
<pre>
status dir
</pre>
and you should get the following output:
<pre>
rufus-dir Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Console connected at 28-Apr-2003 14:03
No jobs are running.
Level          Type     Scheduled          Name
=================================================================
Incremental    Backup   29-Apr-2003 01:05  NightlySave
Full           Backup   29-Apr-2003 01:10  BackupCatalog
====
</pre>
where the times and the Director's name will be different
according to your setup.  This shows that an Incremental job
is scheduled to run for the Job <b>NightlySave</b> at 1:05am
and that at 1:10, a <b>BackupCatalog</b> is scheduled to
run. 
<p>
Now enter:
<pre>
status client
</pre>
and you should get something like:
<pre>
The defined Client resources are:
     1: rufus-fd
Item 1 selected automatically.
Connecting to Client rufus-fd at rufus:8102

rufus-fd Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Director connected at: 28-Apr-2003 14:14
No jobs running.
====
</pre>
In this case, the client is named <b>rufus-fd</b> your name will
be different, but the line beginning with <b>rufus-fd Version ...</b>
is printed by your File daemon, so we are now sure it is up and running.
<p>
Finally do the same for your Storage daemon with:
<pre>
status storage
</pre>
and you should get:
<pre>
The defined Storage resources are:
     1: File
Item 1 selected automatically.
Connecting to Storage daemon File at rufus:8103

rufus-sd Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Device /tmp is not open.
No jobs running.
====
</pre>
You will notice that the default Storage daemon device is named <b>File</b>
and that it will use device <b>/tmp</b>, which is not currently open.
<p>
Now, let's actually run a job with:
<pre>
run
</pre>
you should get the following output:
<pre>
Using default Catalog name=MyCatalog DB=bacula
A job name must be specified.
The defined Job resources are:
     1: NightlySave
     2: BackupCatalog
     3: RestoreFiles
Select Job resource (1-3): 
</pre>
Here, <b>Bacula</b> has listed the three different Jobs that you
can run, and you should choose number <b>1</b> and type enter,
at which point you will get:
<pre>
Run Backup job
JobName:  NightlySave
FileSet:  Full Set
Level:    Incremental
Client:   rufus-fd
Storage:  File
Pool:     Default
When:     2003-04-28 14:18:57
OK to run? (yes/mod/no): 
</pre>
At this point, take some time to look carefully at what is printed 
and understand it.  It is asking you if it is OK to run a job named
<b>NightlySave</b> with FileSet <b>Full Set</b> (we listed above) as
an Incremental job on your Client (your client name will be different),
and to use Storage <b>File</b> and Pool <b>Default</b>, and finally,
it wants to run it now (the current time should be displayed by
your console).
<p>
Here we have the choice to run (<b>yes</b>), to modify one or more of
the above parameters (<b>mod</b>), or to not run the job (<b>no</b>).
Please enter <b>yes</b>, at which point you should immediately get the
command prompt (an asterisk). If you wait a few seconds, then enter
the command <b>messages</b> you will get back something like:
<pre>
28-Apr-2003 14:22 rufus-dir: Last FULL backup time not found. Doing 
                  FULL backup.
28-Apr-2003 14:22 rufus-dir: Start Backup JobId 1, 
                  Job=NightlySave.2003-04-28_14.22.33
28-Apr-2003 14:22 rufus-sd: Job NightlySave.2003-04-28_14.22.33 waiting. 
                  Cannot find any appendable volumes.
Please use the "label"  command to create a new Volume for:
    Storage:      FileStorage
    Media type:   File
    Pool:         Default
</pre>
The first message, indicates that no previous Full backup was done, so Bacula
is upgrading our Incremental job to a Full backup (this is normal).  The
second message indicates that the job started with JobId 1., and the third
message tells us that Bacula cannot find any Volumes in the Pool for writing the
output. This is normal because we have not yet created (labeled) any Volumes.
Bacula indicates to you all the details of the volume it needs.
<p>
At this point, the job is blocked waiting for a Volume. You can check this
if you want by doing a <b>status dir</b>. In order to continue, we label a
Volume with:
<pre>
label
</pre>
and Bacula will print:
<pre>
The defined Storage resources are:
     1: File
Item 1 selected automatically.
Enter new Volume name:
</pre>
at which point, you should enter some name beginning with a letter and
containing only letters and numbers (period, hypen, and underscore) are
also permitted.  For example, enter <b>TestVolume001</b>, and you
should get back:
<pre>
Defined Pools:
     1: Default
Item 1 selected automatically.
Connecting to Storage daemon File at rufus:8103 ...
Sending label command for Volume "TestVolume001" Slot 0 ...
3000 OK label. Volume=TestVolume001 Device=/tmp
Catalog record for Volume "TestVolume002", Slot 0  successfully created.
Requesting mount FileStorage ...
3001 OK mount. Device=/tmp
</pre>
Finally, enter <b>messages</b> and you should get something like:
<pre>
28-Apr-2003 14:30 rufus-sd: Wrote label to prelabeled Volume 
   "TestVolume001" on device /tmp
28-Apr-2003 14:30 rufus-dir: Bacula 1.30 (28Apr03): 28-Apr-2003 14:30
JobId:                  1
Job:                    NightlySave.2003-04-28_14.22.33
FileSet:                Full Set
Backup Level:           Full
Client:                 rufus-fd
Start time:             28-Apr-2003 14:22
End time:               28-Apr-2003 14:30
Files Written:          1,444
Bytes Written:          38,988,877
Rate:                   81.2 KB/s
Software Compression:   None
Volume names(s):        TestVolume001
Volume Session Id:      1
Volume Session Time:    1051531381
Last Volume Bytes:      39,072,359
FD termination status:  OK
SD termination status:  OK
Termination:            Backup OK

28-Apr-2003 14:30 rufus-dir: Begin pruning Jobs.
28-Apr-2003 14:30 rufus-dir: No Jobs found to prune.
28-Apr-2003 14:30 rufus-dir: Begin pruning Files.
28-Apr-2003 14:30 rufus-dir: No Files found to prune.
28-Apr-2003 14:30 rufus-dir: End auto prune.
</pre>
If you don't see the output immediately, you can keep entering <b>messages</b>
until the job terminates, or you can enter, <b>autodisplay on</b>
and your messages will automatically be displayed as soon as they are
ready.
<p>
If you do an <b>ls -l</b> of your <b>/tmp</b> directory, you will see that
you have the following item:
<pre>
-rw-r-----    1 kern     kern     39072153 Apr 28 14:30 TestVolume001
</pre>
This is the file Volume that you just wrote and it contains all
the data of the job just run. If you run additional jobs, they will
be appended to this Volume unless you specify otherwise.
<p>
If you would like to stop here, you can simply enter
<b>quit</b> in the Console program, and you can stop Bacula
with <b>./bacula stop</b>. To clean up, simply delete
the file <b>/tmp/TestVolume001</b>, and you should also re-initialize
your database using:
<pre>
./drop_bacula_tables
./make_bacula_tables
</pre>
Please note that this will erase all information about the 
previous jobs that have run, and that you might want to do
it now while testing but that normally you will not want
to re-initialize your database.
<p>
If you would like to try restoring the files that you just
backed up, read the following section. 

<h2>Restoring Your Files</h2>
If you have run the default configuration and the save of the 
Bacula source code as demonstrated above, you can restore
the backed up files in the Console program by entering:
<pre>
restore
</pre>
where you will get:
<pre>

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): 
</pre>
As you can see, there are a number of options, but for the current
demonstration, please enter <b>5</b> to do a restore of the last
backup you did, and you will get the following output:
<pre>
Defined Clients:
     1: rufus-fd
Item 1 selected automatically.
The defined FileSet resources are:
     1: 1  Full Set  49Eann5no/ZR7+/uW95U6D
Item 1 selected automatically.
+-------+-------+----------+---------------------+---------------+
| JobId | Level | JobFiles | StartTime           | VolumeName    |
+-------+-------+----------+---------------------+---------------+
| 1     | F     | 1444     | 2003-04-28 14:22:33 | TestVolume002 |
+-------+-------+----------+---------------------+---------------+
You have selected the following JobId: 1
Building directory tree for JobId 1 ...
1 items inserted into the tree and marked for extraction.
The defined Storage resources are:
     1: File
Item 1 selected automatically.

You are now entering file selection mode where you add and
remove files to be restored. All files are initially added.
Enter "done" to leave this mode.

cwd is: /
$ 
</pre>
where I have truncated the listing on the right side to make it
more readable.  As you can see by starting at the top of the listing,
Bacula knows what client you have, and since there was only one, it
selected it automatically, likewise for the FileSet. Then Bacula produced
a listing containing all the jobs that form the current backup, in this
case, there is only one, and the Storage daemon was also automatically
chosen.  Bacula then took all the files that were in Job number 1 and
entered them into a <b>directory tree</b> (a sort of in memory representation
of your filesystem). At this point, you can use the <b>cd</b> and <b>ls</b>
ro <b>dir</b> commands to walk up and down the directory tree and view
what files will be restored. For example, if I enter <b>cd /home/kern/bacula/bacula-1.30</b>
and then enter <b>dir</b> I will get a listing of all the files in the
Bacula source directory. On your system, the path will be somewhat different.
For more information on this, please refer to the
<a href="restore.html">Restore Command Chapter</a> of this manual for
more details.
<p>
To exit this mode, simply enter:
<pre>
done
</pre>
and you will get the following output:
<pre>
Bootstrap records written to 
   /home/kern/bacula/testbin/working/restore.bsr

The restore job will require the following Volumes:
   
   TestVolume001


1444 files selected to restore.

Run Restore job
JobName:    RestoreFiles
Bootstrap:  /home/kern/bacula/testbin/working/restore.bsr
Where:      /tmp/bacula-restores
Replace:    always
FileSet:    Full Set
Client:     rufus-fd
Storage:    File
JobId:      *None*
When:       2003-04-28 14:53:54
OK to run? (yes/mod/no): 
</pre>
If you answer <b>yes</b> your files will be restored to <b>/tmp/bacula-restores</b>.
If you want to restore the files to their original locations, you must
use the <b>mod</b> option and explicitly set <b>Where:</b> to nothing (or to /).
We recommend you go ahead and answer <b>yes</b> and after a brief moment, enter
<b>messages</b>, at which point you should get a listing of all the
files that were restored as well as a summary of the job that looks similar
to this:
<pre>
28-Apr-2003 14:56 rufus-dir: Bacula 1.30 (28Apr03): 28-Apr-2003 14:56
JobId:                  2
Job:                    RestoreFiles.2003-04-28_14.56.06
Client:                 rufus-fd
Start time:             28-Apr-2003 14:56
End time:               28-Apr-2003 14:56
Files Restored:         1,444
Bytes Restored:         38,816,381
Rate:                   9704.1 KB/s
FD termination status:  OK
Termination:            Restore OK

28-Apr-2003 14:56 rufus-dir: Begin pruning Jobs.
28-Apr-2003 14:56 rufus-dir: No Jobs found to prune.
28-Apr-2003 14:56 rufus-dir: Begin pruning Files.
28-Apr-2003 14:56 rufus-dir: No Files found to prune.
28-Apr-2003 14:56 rufus-dir: End auto prune.
</pre>

After exiting the Cosole program, you can examine the files in <b>/tmp/bacula-restores</b>,
which will contain a small directory tree with all the files. Be sure to
clean up at the end with:
<pre>
rm -rf /tmp/bacula-restore
</pre>

<h2>Quitting the Console Program</h2>
Simply enter the command <b>quit</b>.


<h2><a name="FullTape">When The Tape Fills</a></h2>
If you have scheduled your job, typically nightly, there 
will come a time when the tape fills up and <b>Bacula</b>
cannot continue. In this case, <b>Bacula</b> will send you
a message similar to the following:
<pre>
rufus-sd: block.c:337 === Write error errno=28: ERR=No space left 
          on device
</pre>
This indicates that <b>Bacula</b> got a write error because the
tape is full. <b>Bacula</b> will then search the Pool specified for
your Job looking for an appendable volume. In the best of all
cases, you will have properly set your Retention Periods and you
will have all your tapes marked to be Recycled, and <b>Bacula</b>
will automatically recycle the tapes in your pool requesting and
overwriting old Volumes.
 
<p>If like me, you have a very large set of Volumes and you
label them with the date the Volume was first writting, or
you have not set up your Retention periods, Bacula will
not find a tape in the pool, and it will send you a message similar
to the following:
<pre>
rufus-sd: Job kernsave.2002-09-19.10:50:48 waiting. Cannot find any 
          appendable volumes.
Please use the "label"  command to create a new Volume for:
    Storage:      SDT-10000
    Media type:   DDS-4
    Pool:         Default
</pre>
Until you create a new Volume,
this message will be repeated an hour later, then two hours later, and
so on doubling the interval each time up to a maximum interval of 1 day.
<p>The obvious question at this point is: What do I do now? 
<p>The answer is simple: first, using the Console program, release
the tape using the <b>unmount</b> command. If you only have a single
drive, it will be automatically selected, otherwise, make sure you
release the one specified on the message (in this case <b>STD-10000</b>).
<p>Next, you remove the tape from the drive and insert a new blank
tape. Note, on some older tape drives, you may need to write an end of
file mark (<b>mt -f /dev/nst0 weof</b>) to prevent the drive from 
running away when <b>Bacula</b> attempts to read the label.
<p>Finally, you use the <b>label</b> command in the Console to write
a label to the new Volume. The <b>label</b> command will contact the
Storage daemon to write the software label, if it is successful, it
will add the new Volume to the Pool, then issue a <b>mount</b> command
to the Storage daemon. See the previous sections of this chapter
for more details on labeling tapes.
<p>The result is that <b>Bacula</b> will continue the previous Job
writing the backup to the new Volume.

<p>If like me, you have your Volume retention periods set correctly,
but you have no more free Volumes, you can relabel and reuse a     
Volume as follows:
<ul>
  <li>Do a <b>list volumes</b> in the Console and select the oldest
      Volume for relabeling.</li>
  <li>If you have setup your Retention periods correctly, the
      Volume should have VolStatus <b>Purged</b>.</li>
  <li>If the VolStatus is not set to Purged, you will need to purge
      the database of Jobs that are written on that Volume. Do so
      by using the command <b>purge jobs volume</b> in the Console.  
      If you have multiple Pools, you will be prompted for the 
      Pool then enter the VolumeName (or MediaId) when requested.
      </li>
  <li>Then simply use the <b>relabel</b> command to relabel the
      Volume.</li>
</ul>
<p>
To manually relabel the Volume use the following additional steps:
<ul>
  <li>To delete the Volume from the catalog use the <b>delete volume</b>
      command in the Console and select the VolumeName (or MediaId) to be
      deleted.</li>
  <li>Use the <b>unmount</b> command in the Console to unmount the
      old tape.</li>
  <li>Physically relabel the old Volume that you deleted so that it
      can be reused.</li>
  <li>Insert the old Volume in the tape drive.</li>
  <li>From a command line do: <b>mt -f /dev/st0 rewind</b> and
      <b>mt -f /dev/st0 weof</b>, where you need to use the proper
      tape drive name for your system in place of <b>/dev/st0</b>.</li>
  <li>Use the <b>label</b> command in the Console to write a new
      <b>Bacula</b> label on your tape.</li>
  <li>Use the <b>mount</b> command in the Console if it is not automatcally
      done, so that <b>Bacula</b> starts using your newly labeled tape.</li>
</ul>

<h2>Other Useful Console Commands</h2>
<dl>
  <dt>status dir</dt><dd>Print a status of all running jobs and jobs
     scheduled in the next 24 hours.</dd>
  <dt>status</dt><dd>The console program will prompt you to select
     a daemon type, then will request the daemon's status.</dd>
  <dt>status jobid=nn</dt><dd>Print a status of JobId nn if it is running.
     The Storage daemon is contacted and requested to print a current
         status of the job as well.</dd>
  <dt>list pools</dt><dd>List the pools defined in the Catalog (normally
     only Default is used).</dd>
  <dt>list media</dt><dd>Lists all the media defined in the Catalog.</dd>
  <dt>list jobs</dt><dd>Lists all jobs in the Catalog that have run.</dd>
  <dt>list jobid=nn</dt><dd>Lists JobId nn from the Catalog.</dd>
  <dt>list jobtotals</dt><dd>Lists totals for all jobs in the Catalog.</dd>
  <dt>list files jobid=nn</dt><dd>List the files that were saved for JobId nn.</dd>
  <dt>list jobmedia</dt><dd>List the media information for each Job run.</dd>
  <dt>messages</dt><dd>Prints any messages that have been directed to the console.</dd>
  <dt>unmount storage=storage-name</dt><dd>Unmounts the drive associated with the storage
     device with the name <b>storage-name</b> if the drive is not currently being
         used. This command is used if you wish <b>Bacula</b> to free the drive so
         that you can use it to label a tape.</dd>
  <dt>mount storage=storage-name</dt><dd>Causes the drive associated with the
     storage device to be mounted again. When 
         <b>Bacula</b> reaches the end of a volume and requests you to mount a
         new volume, you must issue this command after you have placed the
         new volume in the drive. In effect, it is the signal needed by
         <b>Bacula</b> to know to start reading or writing the new volume.</dd>
  <dt>quit</dt><dd>Exit or quit the console program.</dd>
</dl>
Most of the commands given above, with the exception of <b>list</b>, will
prompt you for the necessary arguments if you simply enter the command
name.

<h2>Debug Daemon Output</h2>
<p>If you want debug output from the daemons as
they are running, start the daemons from the install
directory as follows:
<pre>
./bacula start -d20
</pre>
To stop the three daemons, enter the following from the install directory:
<pre>
./bacula stop
</pre>
<p>The execution of <b>bacula stop</b> may complain about pids not found.
This is OK, especially if one of the daemons has died, which is very
rare.
<p>To do a full system save, each File daemon must be running as root
so that it will have permission to access all the files. None of the other
daemons require root privileges. However, the Storage daemon must be able
to open the tape drives. On many systems, only root can access the tape
drives. Either run the Storage daemon as root, or change the permissions
on the tape devices to permit non-root access.  MySQL can
be installed and run with any userid; root privilege is not necessary.

<page_prev name="Console Configuration" url="consoleconf.html">
<page_next name="The Console Program" url="console.html">
