Saturday, January 28, 2012

Add a new bacula client

To add a new client to bacula you have to let the director know the new client first. Go into the bacula configuration directory and add the client to the client resource:

# cd /opt/bacula/latest/etc
# vi common/client.conf
...
Client {
  Name = dc01-fd
  Address = dc01
  FDPort = 9102
  Catalog = MyCatalog
  Password = "3DaL1f6SxjlcVzxyURu+Q+IJNvcpG3y1vqwsItCWW8Cd"
  File Retention = 30 days
  Job Retention = 6 months
  AutoPrune = yes
}
...

Of course you need a job for the new client, otherwise you wouldn't want to add the new client:

# vi common/jobs.conf
...
Job {
  Name = "dc01_etc"
  Type = Backup
  Client = dc01-fd
  Schedule = "etc"
  Storage = DDS-3-01
  Pool = etc
  Messages = Standard
  Priority = 10
  Level = Full
  FileSet="etc"
}
...

Next add the client itself. First you need the software (I assume you have still the sources). Extract the source package and change into the new directory containing the sources. Then run the configure script with --enable-client-only option. This will build the file daemon only:

# ./configure --prefix=/opt/bacula/5.2.3 --enable-client-only
...
# make
...
# make install
...

After the installation finished, change into bacula configuration directory and remove all the sample configuration. You don't need it here:

# cd /opt/bacula/latest/etc
# rm -rf *

Then create your own bacula file daemon configuration:

# vi bacula-fd.conf
Director {
  Name = bck01-dir
  Password = "3DaL1f6SxjlcVzxyURu+Q+IJNvcpG3y1vqwsItCWW8Cd"
}

Messages {
  Name = Standard
  director = bck01-dir = all, !skipped, !restored
}

FileDaemon {
  Name = dc01-fd
  FDport = 9102
  WorkingDirectory = /opt/bacula/5.2.3/var/bacula/working
  Pid Directory = /var/run
  Maximum Concurrent Jobs = 20
}

Finally start the client:

# /opt/bacula/latest/sbin/bacula-fd -c /opt/bacula/latest/etc/bacula-fd.conf

Check that the file daemon is running:

# pgrep -fl bacula
1526 /opt/bacula/latest/sbin/bacula-fd -c /opt/bacula/latest/etc/bacula-fd.conf

Then go back to the server which is running the director and restart the bacula director:

# kill -15 `pgrep bacula-dir`
# /opt/bacula/latest/sbin/bacula-dir -c /opt/bacula/latest/etc/bacula-dir.conf

Finally start bconsole and try to run a backup job for the new client:

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: BackupCatalog
     2: bck01_etc
     3: dc01_etc
     4: RestoreFiles
Select Job resource (1-4): 3
Run Backup job
JobName:  dc01_etc
Level:    Full
Client:   dc01-fd
FileSet:  etc
Pool:     etc (From Job resource)
Storage:  DDS-3-01 (From Job resource)
When:     2012-01-28 10:33:49
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=22
28-Jan 10:34 bck01-dir JobId 22: Start Backup JobId 22, Job=dc01_etc.2012-01-28_10.33.59_10
28-Jan 10:34 bck01-dir JobId 22: Using Device "DDS-3-01"
... Print Friendly and PDF

Friday, January 27, 2012

Creating a new bacula job

This time I want you to show how to create a new job within bacula to backup your files. In this article I will setup a job to backup /etc from my master server which is very easy. To do this go into the bacula configuration directory and edit the jobs resource file to add the new job:

# cd /opt/bacula/latest/etc
# vi common/jobs.conf
...
Job {
  Name = "bck01_etc"
  Type = Backup
  Client = bck01-fd
  Schedule = "etc"
  Storage = DDS-3-01
  Pool = etc
  Messages = Standard
  Priority = 10
  Level = Full
  FileSet="etc"
}
...

The file above is pretty easy. It contains a name directive (bck01_etc), client (bck01) and explains where to store the files (DDS-3-01). Two other important directives I use here is the schedule and the fileset. First take a look at my defined schedule:

# vi common/schedule.conf
...
Schedule {
  Name = "etc"
  Run = Full 1st sun at 04:00
  Run = Incremental mon-sat at 04:00
}
...

The schedule above will perform a full backup every sunday at 04:00 AM and incremental backup from monday till saturday at 04:00 AM. Then edit the fileset:

# vi common/fileset.conf
...
FileSet {
  Name = "etc"
  Include {
    Options {
      signature = MD5
    }
    File = "/etc"
  }
  Exclude {
    File = /etc/svc/volatile
  }
}
...

The above fileset defines to backup /etc except for /etc/svc/volatile (which is a seperate filesystem in Solaris). After creating a new job, a new schedule and a new fileset you have to restart the bacula director:

# kill -15 `pgrep bacula-dir`
# /opt/bacula/latest/sbin/bacula-dir -c /opt/bacula/latest/etc/bacula-dir.conf

Then run the job to see if it works. First start bconsole:

# bconsole
Connecting to Director bck01:9101
1000 OK: bck01-dir Version: 5.2.3 (16 December 2011)
Enter a period to cancel a command.

Then use the run command to start the new job:

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: BackupCatalog
     2: bck01_etc
     3: RestoreFiles
Select Job resource (1-3): 2
Run Backup job
JobName:  bck01_etc
Level:    Full
Client:   bck01-fd
FileSet:  etc
Pool:     etc (From Job resource)
Storage:  DDS-3-01 (From Job resource)
When:     2012-01-27 20:15:31
Priority: 10
OK to run? (yes/mod/no): y
Job queued. JobId=17

As you can see all prior defined options will be used and the job will be started. Take a look at the messages or mails to see if the job works. Print Friendly and PDF

Thursday, January 26, 2012

Using a stand alone tape with bacula

This time I want you to show how to use a stand alone tape drive with bacula. I have a couple of DDS-3 tape drives which all work with Solaris 10 X86 and bacula. Before you begin you need to know the device file for your tape drive. Under Solaris use iostat:

# iostat -En
...
rmt/0            Soft Errors: 0 Hard Errors: 0 Transport Errors: 0
Vendor: SONY     Product: SDT-9000         Revision: 0400 Serial No: 03/05/98
...

Then change into your bacula configuration directory and add the tape drive to the bacula storage device configuration like this:

# cd /opt/bacula/latest/etc
# vi bacula-sd.conf
...
Device {
  Name = DDS-3-01
  Media Type = DDS-3
  Archive Device = /dev/rmt/0n
  AutomaticMount = yes;
  AlwaysOpen = yes;
  RemovableMedia = yes;
  RandomAccess = no;
  Maximum File Size = 12GB
}
...

Also let the bacula director know that there is a tape drive available:

# vi common/storage.conf
...
Storage {
  Name = DDS-3-01
  Address = bck01
  SDPort = 9103
  Password = "QLBrhBa8ebxbTjWwy74qIfvPlTFN44dCfmymfmmL41i8"
  Device = DDS-3-01
  Media Type = DDS-3
  Autochanger = no
}
...

Then add a pool for your tapes. I called the pool etc because I want to backup all my configuration from my servers stored under /etc:

# vi common/pool.conf
...
Pool {
  Name = etc
  Pool Type = Backup
  Recycle = yes
  AutoPrune = yes
  Volume Retention = 7 days
  Maximum Volume Bytes = 12G
  Maximum Volumes = 10
}
...

To take effect of all your changes you have to restart the bacula director and bacula storage daemon:

# kill -15 `pgrep bacula-dir`
# kill -15 `pgrep bacula-sd`
# /opt/bacula/latest/sbin/bacula-dir -c /opt/bacula/latest/etc/bacula-dir.conf
# /opt/bacula/latest/sbin/bacula-sd -c /opt/bacula/latest/etc/bacula-sd.conf

Finally label a tape to make it ready for usage. First start bconsole:

# bconsole
Connecting to Director bck01:9101
1000 OK: bck01-dir Version: 5.2.3 (16 December 2011)
Enter a period to cancel a command.

Then run the label command. As storage ressource use the prior defined tape. As name you can use whatever you want. I just like to number my tapes like tape01, tape02 etc:

*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
     1: File
     2: DDS-3-01
Select Storage resource (1-2): 2
Enter new Volume name: tape01
Defined Pools:
     1: File
     2: etc
Select the Pool (1-2): 2
Connecting to Storage daemon DDS-3-01 at bck01:9103 ...
Sending label command for Volume "tape01" Slot 0 ...
3000 OK label. VolBytes=64512 DVD=0 Volume="tape01" Device="DDS-3-01" (/dev/rmt/0n)
Catalog record for Volume "tape01", Slot 0  successfully created.
Requesting to mount DDS-3-01 ...
3001 Device ""DDS-3-01" (/dev/rmt/0n)" is mounted with Volume "tape01"

If you work with different pools then it may be wise to use something like poolname1_tape01, poolname1_tape02, poolname2_tape01 etc.
When the tape is labeled then it is ready to use inside bacula. Run any job and modify it to use the new tape.
If you have these stupid Python tape drives - don't use them. The just suck:

1. under Solaris you can only use the low density device, eg /dev/rmt/1l
2. they are killing tapes like hell

Both points are just my personal experience. Print Friendly and PDF

Sunday, January 22, 2012

Basic bacula installation and configuration

With this article I want you to show how to install bacula from source and how to create a basic configuration. The topics in this artice will be the following:

Install bacula from source under Solaris 10 x86
Create the bacula database under Slackware Linux 13.1
Configure the bacula director
Configure the bacula storage daemon
Configure the bacula file daemon
First start
Configure the bacula console
Run a backup job
Run a restore job

The installation of bacula should work very similar under any Unix/Linux. If you have only one machine available then you can run bacula and mysql on it, you don't need seperate machines for it. Also this article is a very simple description, I don't explain all options that I am using here (and mostly I am using the default settings created during the installation). For details look in to the documentation provided on http://www.bacula.org.

Install bacula from source under Solaris 10 x86

Before you begin you should install a proper mysql package. I like to use the mysql from the blastwave repositories, see http://www.blastwave.org for details. Also make sure that you have /usr/sfw and /usr/ccs in your PATH variable, eg:

# export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/sfw/bin:/usr/sfw/sbin:/usr/ccs/bin:/opt/csw/bin:/opt/csw/sbin

The above PATH variable is my current setting. When you have installed a useable mysql package then download the latest source release from http://www.bacula.org. When the download has finished extract the source under /usr/src:

# cd /usr/src
# gunzip -dc bacula-5.2.3.tar.gz | tar xf -

Next run the configure script, compile the sources and install the binaries. Don't forget to set the appropiate mysql path when executing the configure script:

# ./configure --prefix=/opt/bacula/5.2.3 --with-mysql=/opt/csw/mysql5
...
# make
...
# make install
...

If everyting has compiled then you should have the binaries under /

# ls /opt/bacula/5.2.3/sbin/
...
bacula-fd
bacula-dir
bacula-sd
...

The last step is to create a symbolic link. Thet will make it easier to handle multiple bacula version (eg. updates etc):

# cd /opt/bacula
# ln -s 5.2.3 latest

bacula is now compiled and installed.

Create the bacula database under Slackware Linux 13.1

You are ready now to install the database. First login into your database server (when the bacula server is not the database server like mine) and connect to mysql as root:

# mysql -u root -p
Enter password:
...

Create the bacula database and exit:

mysql> create database bacula;
Query OK, 1 row affected (0.00 sec)
mysql> exit

To create the tables inside the database use the shipped make_mysql_tables within the sources:

# cd /usr/src/bacula-5.2.3/src/cats
# sh make_mysql_tables -p
Enter password:
Creation of Bacula MySQL tables succeeded.

With the -p option mysql will ask for a password. Finally try to connect from the bacula server to the database server as user bacula:

# /opt/csw/mysql5/bin/mysql -u bacula -h 192.168.1.73 -p
Enter password:
...

That's it, the creation of the database has finished.

Configure the bacula director

Before you begin with the configuration drop the installed configuration. Don't delete it just move it to another place:

# cd /opt/bacula/latest/etc
# mkdir orig
# mv * orig/

Now begin to configure the bacula director. The bacula director holds all configuration about the jobs, schedules, available storage and file daemons and so on. I try to split the configuration file, hopefully it will make the configuration not too hard. First create the bacula-dir.conf in /opt/bacula/latest/etc:

# cd /opt/bacula/latest/etc
# vi bacula-dir.conf
Director {
  Name = bck01-dir
  DIRport = 9101
  QueryFile = "/opt/bacula/5.2.3/etc/query.sql"
  WorkingDirectory = "/opt/bacula/5.2.3/var/bacula/working"
  PidDirectory = "/var/run"
  Maximum Concurrent Jobs = 1
  Password = "mlaO4VoMtSztiaYYho4JBiLc2QIWbe2+os6c+5MmDyfT"
  Messages = Daemon
}

Catalog {
  Name = MyCatalog
  dbname = "bacula"; dbuser = "bacula"; dbpassword = "bacula"; DB Address = "192.168.1.73"
}

Console {
  Name = bck01-mon
  Password = "Q1WBj91S2bJExh4xuXjfAB0tHQqkYZThrgsktrWqY+nQ"
  CommandACL = status, .status
}

# JOBS
@/opt/bacula/latest/etc/common/jobs.conf

# FILESETS
@/opt/bacula/latest/etc/common/fileset.conf

# SCHEDULES
@/opt/bacula/latest/etc/common/schedule.conf

# MESSAGES
@/opt/bacula/latest/etc/common/message.conf

# CLIENTS AND STORAGE DAEMONS
@/opt/bacula/latest/etc/common/client.conf
@/opt/bacula/latest/etc/common/storage.conf

# VOLUME POOLS
@/opt/bacula/latest/etc/common/pool.conf

The first section 'Director' has some basic configuration about the director itself, like the name, working directory etc. The second section 'Catalog' contains the database configuration. The third section 'Console' is for the program bconsole. bconsole is used to interact with bacule (coming later). The last lines beginning with the @ include more files available under /opt/bacula/latest/etc/common/. To continue create the directory and change into it:

# mkdir /opt/bacula/latest/etc/common
# cd /opt/bacula/latest/etc/common

Now create jobs.conf file:

# vi jobs.conf
Job {
  Name = "BackupCatalog"
  Type = Backup
  Client = bck01-fd
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = File
  Priority = 10
  Write Bootstrap = "/opt/bacula/5.2.3/var/bacula/working/%c.bsr"
  Level = Full
  FileSet="Catalog"
  RunBeforeJob = "/opt/bacula/5.2.3/etc/scripts/make_catalog_backup.pl MyCatalog"
  RunAfterJob  = "/opt/bacula/5.2.3/etc/scripts/delete_catalog_backup"
  Write Bootstrap = "/opt/bacula/5.2.3/var/bacula/working/%n.bsr"
  Priority = 11
}

Job {
  Name = "RestoreFiles"
  Type = Restore
  Client=bck01-fd
  FileSet="Catalog"
  Storage = File
  Pool = File
  Messages = Standard
  Where = /tmp/bacula-restores
}

The file above defines the jobs. In this case two jobs are defined, one job for backing up the catalog and another job to restore. The BackupCatalog job contains some configuration about the client, schedule, which storage to use etc. Important for the RestoreFiles job is the Where option. When ever you run a restore job then all files will be restored under the given directory. Now continue with the fileset.conf file:

# vi fileset.conf
FileSet {
  Name = "Catalog"
  Include {
    Options {
      signature = MD5
    }
    File = "/opt/bacula/5.2.3/var/bacula/working/bacula.sql"
  }
}

The Catalog fileset has only on file which is /opt/bacula/5.2.3/var/bacula/working/bacula.sql. When take a look in the jobs.conf file then you will notice the RunBeforeJob option. This options runs a script that creates a mysql dump of the bacula database which will be stored as /opt/bacula/5.2.3/var/bacula/working/bacula.sql and backup by bacula. The next file will be the schedule.conf file, it holds all schedules when to perform a backup:

# vi schedule.conf
Schedule {
  Name = "WeeklyCycle"
  Run = Full 1st sun at 23:05
  Run = Incremental mon-sat at 23:05   
}

The schedule above will run a full backup on sunday and incremental backups the other days.
Then create the configuration file for the messages:

# vi message.conf
Messages {
  Name = Standard
  mailcommand = "/opt/bacula/5.2.3/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/opt/bacula/5.2.3/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
  mail = root@localhost = all, !skipped
  operator = root@localhost = mount
  console = all, !skipped, !saved
  append = "/opt/bacula/5.2.3/var/bacula/working/log" = all, !skipped
  catalog = all
}

Messages {
  Name = Daemon
  mailcommand = "/opt/bacula/5.2.3/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
  mail = root@localhost = all, !skipped
  console = all, !skipped, !saved
  append = "/opt/bacula/5.2.3/var/bacula/working/log" = all, !skipped
}

The message.conf file defines who to inform when a special event happened, eg. who must informed when backup failed etc. The next file defines all clients:

# vi client.conf
Client {
  Name = bck01-fd
  Address = bck01
  FDPort = 9102
  Catalog = MyCatalog
  Password = "3DaL1f6SxjlcVzxyURu+Q+IJNvcpG3y1vqwsItCWW8Cd"
  File Retention = 30 days
  Job Retention = 6 months
  AutoPrune = yes
}

In this only one client is available and that is the director itself. The storage.conf file looks pretty much the same:

# vi storage.conf
Storage {
  Name = File
  Address = bck01
  SDPort = 9103
  Password = "QLBrhBa8ebxbTjWwy74qIfvPlTFN44dCfmymfmmL41i8"
  Device = FileStorage
  Media Type = File
}

This file defines which storage is available on which system, eg. you could have a tape library available on a different host. Then the storage daemon would get an entry in this file, but the configuration for the storage would be on the specific host. Finally the last file is the configuration file for the pool:

# vi pool.conf
Pool {
  Name = File
  Pool Type = Backup
  Recycle = yes
  AutoPrune = yes
  Volume Retention = 365 days
  Maximum Volume Bytes = 50G
  Maximum Volumes = 100
}

In this case only one pool is defined and it is for the file storage. You can define several pools for more or less critical data to avoid that critical backups get overwritten by less critical backups.
All the above configuration files are only for the director. I hope that this is not to difficult. Keep in mind that have to define a job for a client with a fileset. The job needs a schedule and storage to write to. The storage must have a pool with media available. In case that something unforseen happened then somebody needs to get a message.

Configure the bacula storage daemon

To configure the bacula storage daemon change into the etc directory and create the bacula-sd.conf file:

# cd /opt/bacula/latest/etc
# vi bacula-sd.conf
Storage {
  Name = bck01-sd
  SDPort = 9103
  WorkingDirectory = "/opt/bacula/5.2.3/var/bacula/working"
  Pid Directory = "/var/run"
  Maximum Concurrent Jobs = 20
}

Director {
  Name = bck01-dir
  Password = "QLBrhBa8ebxbTjWwy74qIfvPlTFN44dCfmymfmmL41i8"
}

Messages {
  Name = Standard
  director = bck01-dir = all
}

Device {
  Name = FileStorage
  Media Type = File
  Archive Device = /local/bacula_storage
  LabelMedia = yes;
  Random Access = Yes;
  AutomaticMount = yes;
  RemovableMedia = no;
  AlwaysOpen = no;
}

The file above is very simple. The first three sections are defining the storage daemon, the director and how to send messages. The last section is the storage device itself. In this case it is file storage known from bacula director configuration. All backups will be written to /local/bacula_storage (after labeling one media).

Configure the bacula file daemon

The file daemon is typically used to configure a client. Everytime you want to add a client you have to configure the bacula-fd.conf file:

# cd /opt/bacula/latest/etc
# vi bacula-fd.conf
Director {
  Name = bck01-dir
  Password = "3DaL1f6SxjlcVzxyURu+Q+IJNvcpG3y1vqwsItCWW8Cd"
}

Messages {
  Name = Standard
  director = bck01-dir = all, !skipped, !restored
}

FileDaemon {
  Name = bck01-fd
  FDport = 9102
  WorkingDirectory = /opt/bacula/5.2.3/var/bacula/working
  Pid Directory = /var/run
  Maximum Concurrent Jobs = 20
}

This file contains three sections for the director, the messages and the client it self.

First start

After the basic configuration from above (I hope you made it so far) you are ready for a first start. First start the storage daemon, then the file daemon and at least the director:

# /opt/bacula/latest/sbin/bacula-sd -c /opt/bacula/latest/etc/bacula-sd.conf
# /opt/bacula/latest/sbin/bacula-fd -c /opt/bacula/latest/etc/bacula-fd.conf
# /opt/bacula/latest/sbin/bacula-dir -c /opt/bacula/latest/etc/bacula-dir.conf

Check that all daemons are up and running:

# pgrep -fl bacula
 1359 /opt/bacula/latest/sbin/bacula-dir -c /opt/bacula/latest/etc/bacula-dir.conf
 1423 /opt/bacula/latest/sbin/bacula-sd -c /opt/bacula/latest/etc/bacula-sd.conf
 1420 /opt/bacula/latest/sbin/bacula-fd -c /opt/bacula/latest/etc/bacula-fd.conf

If you have trouble getting one of the daemons to start then use the debug option, eg:

# /opt/bacula/latest/sbin/bacula-dir -d 1 -c /opt/bacula/latest/etc/bacula-dir.conf

Configure the bacula console

To interact with bacula you have to use bconsole. Of course it needs it's own configuration file:

# cd /opt/bacula/latest/etc
# vi bconsole.conf
Director {
  Name = bck01-dir
  DIRport = 9101
  address = bck01
  Password = "mlaO4VoMtSztiaYYho4JBiLc2QIWbe2+os6c+5MmDyfT"
}

Luckily it just needs to know how to reach the director. Now start the console:

# /opt/bacula/latest/sbin/bconsole -c /opt/bacula/latest/etc/bconsole.conf
Connecting to Director bck01:9101
1000 OK: bck01-dir Version: 5.2.3 (16 December 2011)
Enter a period to cancel a command.
*

Run a backup job

Before you can run a job now you have to label the media on the file storage. You only have to do this once. If your media get's full then you need to label another media:

*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: File
Enter new Volume name: file01
Connecting to Storage daemon File at bck01:9103 ...
Sending label command for Volume "file01" Slot 0 ...
3000 OK label. VolBytes=188 DVD=0 Volume="file01" Device="FileStorage" (/local/bacula_storage)
Catalog record for Volume "file01", Slot 0  successfully created.
Requesting to mount FileStorage ...
3001 OK mount requested. Device="FileStorage" (/local/bacula_storage)

To start a job use the run command:

*run
A job name must be specified.
The defined Job resources are:
     1: BackupCatalog
     2: RestoreFiles
Select Job resource (1-2): 1
Run Backup job
...
OK to run? (yes/mod/no): yes
Job queued. JobId=6
...
  Termination:            Backup OK
...

When you get a message similar to the one above then the backup of the catalog database was succesfull.

Run a restore job:

More important then having a backup is to perform a restore (I know a lot people with a working backup and a unknown restore situation). You have various possibilities to restore a file. Currently I only have a backup of the bacula database dump so this is the only file I can restore until now. To restore it start bconsole again and use the restore command:

*restore
...
To select the JobIds, you have the following choices:
...
     7: Enter a list of files to restore
...
Select item:  (1-13): 7
...
Enter full filename: /opt/bacula/5.2.3/var/bacula/working/bacula.sql
Enter full filename:
...
1 file selected to be restored.
Run Restore job
JobName:         RestoreFiles
...
OK to run? (yes/mod/no): yes
Job queued. JobId=8
...
  Termination:            Restore OK

After all this I hope you will be able to perform a backup and a restore. Print Friendly and PDF