
#include "bacula_template.inc" title="Backing Up to Disk Volumes" num=12

<h1>Backing Up to Disk Volumes</h1>
If you have a lot of harddisk storage or you absolutely must have
your backups run within a small time window, you may want to 
direct Bacula to backup to disk Volumes rather than tape Volumes.
This chapter is intended to give you some of the options that
are available to you so that you can manage those disk volumes.

<h2>Key Concepts and Resource Records</h2>
Getting Bacula to write to disk rather than tape in the simplest
case is rather easy. 
In the Storage daemon's configuration file, you simply define an
<b>Archive Device</b> to be a directory. For example, if you want your
disk backups to go into the directory <b>/home/bacula/backups</b>, you
could use the following:
<pre>
Device {
  Name = FileBackup
  Media Type = File
  Archive Device = /home/bacula/backups
  Random Access = Yes;
  AutomaticMount = yes;
  RemovableMedia = no;
  AlwaysOpen = no;
}
</pre>
Assuming you have the appropriate <b>Storage</b> resource in your
Director's configuration file that references the above Device resource,
<pre>
Storage {
  Name = FileStorage
  Address = ...
  Password = ...
  Device = FileBackup
  Media Type = File
}
</pre>
Bacula will then write the archive to the file
<b>/home/bacula/backups/&lt;volume-name&gt;</b> where
&lt;volume-name&gt; is the volume name of a Volume defined in the Pool.
For example, if you have labeled a Volume named <b>Vol001</b>, Bacula will
write to the file <b>/home/bacula/backups/Vol001</b>.  Although
you can later move the archive file to another directory, you should
not rename it or it will become unreadable by Bacula. This  
is because each archive has the filename as part of the internal label, 
and the internal label must agree with the system filename before
Bacula will use it.
<p>Although this is quite simple, there are a number of
problems, the first is that unless you specify otherwise, 
Bacula will always write to the same volume until you 
run out of disk space.
<p>
<h3>Pool Options to Limit the Volume Usage</h3>
Some of the options you have, all of which are specified in
the Pool record, are:
<ul>
  <li>To write each Volume only once (i.e. one Job per Volume or file
      in this case), use:<p>
      <b>UseVolumeOnce = yes</b>. </li>
  <li>To write nnn Jobs to each Volume, use:<p>
      <b>Maximum Job Volumes = nnn</b>.</li>
  <li>To limit the maximum size of each Volume, use:<p>
      <b>Maximum Volume Bytes = mmmm</b>.</li>
  <li>To limit the use time (i.e. write the Volume for
      a maximum of 5 days), use:<p>
      <b>Volume Use Duration = ttt</b>.</li>
</ul>

As mentioned above, each of those directives are specified in the
Pool or Pools that you use for your Volumes. In the case of
<b>Maximum Job Volumes</b>, <b>Maximum Volume Bytes</b>, and
<b>Volume Use Duration</b>, you can actually specify the desired
value on a Volume by Volume basis. The value specified in the
Pool record becomes the default when labeling new Volumes.
As an example of the use of one of the above, suppose your
Pool resource contains:
<pre>
Pool {
  Name = File
  Pool Type = Backup
  Volume Use Duration = 23h
}
</pre>
then if you run a backup once a day (every 24 hours), Bacula
will use a new Volume each backup because each Volume it writes
can only be used for 23 hours after the first write.

<h3>Automatic Volume Labeling</h3>
Use of the above records brings up another problem -- that of
labeling your Volumes. For automated disk backup, you can either
manually label each of your Volumes, or you can have Bacula automatically
label new Volumes when they are needed. The current automatic
Volume labeling is a bit simplistic, but it does allow for 
automation. Automatic Volume labeling is accomplished by making
a change to both the Pool resource (Director) and to the Device resource 
(Storage daemon) shown
above.  In the case of the Pool resource, you must provide Bacula
with a label format that it will use to create new names.  The
label format is simply the Volume name, to which Bacula will append
a four digit number. This number starts at 0001 and is incremented
for each Volume the pool contains.  Thus if you modify your Pool
resource to be:
<pre>
Pool {
  Name = File
  Pool Type = Backup
  Volume Use Duration = 23h
  LabelFormat = Vol
}
</pre>
Bacula will create Volume names Vol0001, Vol0002, and so on when
new Volumes are needed.  The second change that is necessary to make
this work is to give the Storage daemon permission to automatically
label Volumes. Do so by adding <b>LabelMedia = yes</b> to the 
Device resource as follows:
<pre>
Device {
  Name = File
  Media Type = File
  Archive Device = /home/bacula/backups
  Random Access = Yes;
  AutomaticMount = yes;
  RemovableMedia = no;
  AlwaysOpen = no;
  LabelMedia = yes
}
</pre>

<h3>Restricting the Number of Volumes and Recycling</h3>
Automatic labeling discussed above brings up the problem of Volume
management.  With the above scheme, a new Volume will be created every
day.  If you have not specified Retention periods, your Catalog
will continue to fill keeping track of all the files Bacula has backed
up, and this procedure will create one new archive file (Volume) every day.

<p>The tools Bacula gives you to help automatically manage these
problems are the following:
<ol>
  <li>Catalog file record retention periods, the 
      <a href="dirdconf.html#FileRetention"><b>File Retention = ttt</b></a>
      record in the Client resource.</li>
  <li>Catalog job record retention periods, the 
      <a href="dirdconf.html#JobRetention"><b>Job Retention = ttt</b></a>
      record in the Client resource.</li>
  <li>The <a href="dirdconf.html#AutoPrune">
     <b>AutoPrune = yes</b></a> record in the Client resource to permit
      application of the above two retention periods.</li>
  <li>The <a href="dirdconf.html#VolRetention">
      <b>Volume Retention = ttt</b></a> record in the Pool resource.</li>
  <li>The <a href="dirdconf.html#PoolAutoPrune">
     <b>AutoPrune = yes</b></a> record in the Pool resource to permit
      application of the Volume retention period.</li>
  <li>The <a href="dirdconf.html#PoolRecycle">
     <b>Recycle = yes</b></a> record in the Pool resource to permit
      automatic recycling of Volumes whose Volume retention period has
      expired.</li>
  <li>The <a href="dirdconf.html#RecycleOldest">
     <b>Recycle Oldest Volume = yes</b></a> record in the Pool resource to
      permit a forced recycling of the oldest Volume when a new one is
      needed. 
      <b>N.B. This record ignores retention periods!</b></li>
  <li>The <a href="dirdconf.html#MaxVolumes">
      <b>Maximum Volumes = nnn</b></a> record in the Pool resource to limit
      the number of Volumes that can be created.</li>
</ol>
The first three records (File Retention, Job Retention, and AutoPrune)
determine the amount of time that Job and File records will remain
in your Catalog, and they
are discussed in detail in the <a href="recycling.html">Automatic 
Volume Recycling</a> chapter of this manual.
<p>Volume Retention, AutoPrune, and Recycle determine how long
Bacula will keep your Volumes before reusing them, and they are
also discussed in detail in the <a href="recycling.html">Automatic 
Volume Recycling</a> chapter of this manual.
<p>The Maximum Volumes record can also be used in conjunction with
the Volume Retention period to limit the total number of archive
Volumes (files) that Bacula will create. By setting an appropriate
Volume Retention period, a Volume will be purged just before it
is needed and thus Bacula can cycle through a fixed set of Volumes.
Cycling through a fixed set of Volumes can also be done by setting
<b>Recycle Oldest Volume = yes</b>. In this case, when Bacula needs
a new Volume, it will purge the oldest Volume without out regard
to retention periods. This guarantees that the oldest Volume will
be reused, but you should take care that you understand how this
works or you could cause Bacula to overwrite valid data. At a minimum
you must define a reasonable number of Volumes before running any
job so that the current Volume isn't immediately recycled and
reused when it is full!

<h2>An Example</h2>
The following example is not very practical, but can be used
to demonstrate the proof of concept in a relatively short 
period of time. The example consists of a single client that
is backed up to a set of 12 archive files (Volumes). Each
Volume is used (written) only once, and there are
four Full saves done every hour (so the whole thing cycles
around after three hours).

<p>The Director's configuration file is as follows:
<pre>
Director {
  Name = my-dir
  QueryFile = "~/bacula/bin/query.sql"
  PidDirectory = "~/bacula/working"
  SubSysDirectory = "~/bacula/working"
  WorkingDirectory = "~/bacula/working"
  Password = dir_password
}

Schedule {
  Name = "FourPerHour"
  Run = Level=Full Pool=Recycle Storage=File hourly at 0:05
  Run = Level=Full Pool=Recycle Storage=File hourly at 0:20
  Run = Level=Full Pool=Recycle Storage=File hourly at 0:35
  Run = Level=Full Pool=Recycle Storage=File hourly at 0:50
}

Job {
  Name = "RecycleExample"
  Type = Backup
  Level = Full
  Client = Rufus
  FileSet= "Example FileSet"
  Messages = Standard
  Storage = FileStorage 
  Pool = Recycle
  Schedule = FourPerHour
}

FileSet {
  Name = "Example FileSet"
  Include = compression=GZIP signature=SHA1 { 
    /home/kern/bacula/bin
  }
}

Client {
  Name = Rufus
  Address = rufus
  Catalog = BackupDB
  Password = client_password
}


Storage {
  Name = FileStorage
  Address = rufus
  Password = local_storage_password   # password for Storage daemon
  Device = RecyleDir                  # must be same as Device in Storage daemon
  Media Type = File                   # must be same as MediaType in Storage daemon
}

Catalog {
  Name = BackupDB
  dbname = bacula; user = bacula; password = ""
}

Messages {
  Name = Standard
  ...
}

Pool {
  Name = Recycle
  Use Volume Once = yes
  Pool Type = Backup
  LabelFormat = Vol
  AutoPrune = yes
  VolumeRetention = 2h
  Maximum Volumes = 12
  Recycle = yes
}
</pre>

and the Storage daemon's configuration file is:

<pre>
Storage {
  Name = my-sd    
  WorkingDirectory = "~/bacula/working"
  Pid Directory = "~/bacula/working"
  Subsys Directory = "~/bacula/working"
  MaximumConcurrentJobs = 10
}

Director {
  Name = my-dir
  Password = local_storage_password
}

Device {
  Name = RecyleDir
  Media Type = File
  Archive Device = /home/bacula/backups
  LabelMedia = yes;                   # lets Bacula label unlabeled media
  Random Access = Yes;
  AutomaticMount = yes;               # when device opened, read it
  RemovableMedia = no;
  AlwaysOpen = no;
}

Messages {
  Name = Standard
  director = my-dir = all
}
</pre>

In this example, the Jobs will be backed up to directory 
<b>/home/bacula/backups</b> with Volume names Vol0001, Vol0002, ...
Vol0012. Every backup Job will write a new volume cycling    
through the volume numbers, and two hours after a job has
started, the volume will be pruned <b>Volume Retention = 2h</b>.
<p>
With a little bit of work, you can change the above example
into a weekly or monthly cycle (take care about the amount of
archive disk space used).

<h2>Considerations for Multiple Clients</h2>
If we take the above example and add a second Client, here
are a few considerations:
<ul>
  <li>Although the second client can write to the same set of
      Volumes, you will probably want to write to a different
      set. </li>
  <li>You can write to a different set of Volumes by defining
      a second Pool, which has a different name and a different
      <b>LabelFormat</b>.</li>
  <li>If you wish the Volumes for the second client to go into
      a different directory (perhaps even on a different filesystem
      to spread the load), you would do so by defining a second
      Device resource in the Storage daemon. The <b>Name</b>
      must be different, and the <b>Archive Device</b> could
      be different. To ensure that Volumes are never mixed from
      one pool to another, you might also define a different
      MediaType (e.g. <b>File1</b>).</li>
</ul>
                  
In this example, we have two clients, each with a different
Pool and a different number of archive files retained. They
also write to different directories with different Volume
labeling. 

<p>The Director's configuration file is as follows:
<pre>
Director {
  Name = my-dir
  QueryFile = "~/bacula/bin/query.sql"
  PidDirectory = "~/bacula/working"
  SubSysDirectory = "~/bacula/working"
  WorkingDirectory = "~/bacula/working"
  Password = dir_password
}

\# Basic weekly schedule
Schedule {
  Name = "WeeklySchedule"
  Run = Level=Full fri at 1:30
  Run = Level=Incremental sat-thu at 1:30
}

FileSet {
  Name = "Example FileSet"
  Include = compression=GZIP signature=SHA1 { 
    /home/kern/bacula/bin
  }
}

Job {
  Name = "Backup-client1"
  Type = Backup
  Level = Full
  Client = client1
  FileSet= "Example FileSet"
  Messages = Standard
  Storage = File1
  Pool = client1
  Schedule = "WeeklySchedule"
}

Job {
  Name = "Backup-client2"
  Type = Backup
  Level = Full
  Client = client2
  FileSet= "Example FileSet"
  Messages = Standard
  Storage = File2
  Pool = client2
  Schedule = "WeeklySchedule"
}

Client {
  Name = client1
  Address = client1
  Catalog = BackupDB
  Password = client1_password
  File Retention = 7d               # keep files in catalog only 7 days
}

Client {
  Name = client2
  Address = client2
  Catalog = BackupDB
  Password = client2_password
}

\# Two Storage definitions permits different directories
Storage {
  Name = File1
  Address = rufus
  Password = local_storage_password   # password for Storage daemon
  Device = client1                    # must be same as Device in Storage daemon
  Media Type = File                   # must be same as MediaType in Storage daemon
}

Storage {
  Name = File2
  Address = rufus
  Password = local_storage_password   # password for Storage daemon
  Device = client2                    # must be same as Device in Storage daemon
  Media Type = File                   # must be same as MediaType in Storage daemon
}

Catalog {
  Name = BackupDB
  dbname = bacula; user = bacula; password = ""
}

Messages {
  Name = Standard
  ...
}

\# Two pools permits different cycling periods and Volume names
\# Cycle through 15 Volumes (two weeks)
Pool {
  Name = client1
  Use Volume Once = yes
  Pool Type = Backup
  LabelFormat = Client1-
  AutoPrune = yes
  VolumeRetention = 13d
  Maximum Volumes = 15
  Recycle = yes
}

\# Cycle through 8 Volumes (1 week)
Pool {
  Name = client2
  Use Volume Once = yes
  Pool Type = Backup
  LabelFormat = Client2-
  AutoPrune = yes
  VolumeRetention = 6d
  Maximum Volumes = 8
  Recycle = yes
}

</pre>

and the Storage daemon's configuration file is:

<pre>
Storage {
  Name = my-sd    
  WorkingDirectory = "~/bacula/working"
  Pid Directory = "~/bacula/working"
  Subsys Directory = "~/bacula/working"
  MaximumConcurrentJobs = 10
}

Director {
  Name = my-dir
  Password = local_storage_password
}

\# Archive directory for Client1
Device {
  Name = client1
  Media Type = File
  Archive Device = /home/bacula/client1
  LabelMedia = yes;                   # lets Bacula label unlabeled media
  Random Access = Yes;
  AutomaticMount = yes;               # when device opened, read it
  RemovableMedia = no;
  AlwaysOpen = no;
}

\# Archive directory for Client2
Device {
  Name = client2
  Media Type = File
  Archive Device = /home/bacula/client2
  LabelMedia = yes;                   # lets Bacula label unlabeled media
  Random Access = Yes;
  AutomaticMount = yes;               # when device opened, read it
  RemovableMedia = no;
  AlwaysOpen = no;
}

Messages {
  Name = Standard
  director = my-dir = all
}
</pre>
 
<page_prev name="Recycling Your Volumes" url="recycling.html">
<page_next name="Using Autochangers" url="autochangers.html">
