04 May 2010

Bacula Server

We all know that Bacula server are a good backup server but a hell to configure properly, and sometimes doesn't work at all. I got experience with some weird distros that even you puting my same configuration doesn't work. So.. if you fail trying to configuring, just take a look in other distros, maybe isn't your fault. ;)
As well, my example as used and tested in my home-server using Gentoo and my work testing server Ubuntu.






1. Installing packages
Bacula provides some backends to configuration, like mysql, postgreSQL and sqlite3.


Ubuntu: You'll have a lot of packages, so take a look what you really need (since after install you'll have some wizards to configure databases, the basic installation is very simple. So take note that bacula in ubuntu is an old release, if you really want to use 2.x server, i'ts to you.


Gentoo: You'll need to unmask bacula to get the last version (If you use gentoo, you already now what you're doing, I'll not explain here that you unmask things at your own risk and so on). Just in case, this is my USEFLAGS:


[ebuild R   ] app-backup/bacula-5.0.1-r2  USE="ipv6 mysql python readline ssl tcpd -X -bacula-clientonly -bacula-nodir -bacula-nosd -logwatch -postgres -qt4 -sqlite3 -static" 0 kB


2. Configuration files


If you have some problems, I recommend using webmin backend for Bacula, because it's very simple to detect some errors and more intuitive to configure.

I’m using mysql for backend db (mysql db are done during the installation) and no Tape (this is a file-backup based example), but will be easy to configure a tape looking on commented examples.
The file storage and work directory on this example are all located in /mnt/sda4/Backup.




/etc/bacula/bacula-dir.conf (This is your Bacula Server configuration file, also called the Director Server)


   1: #
   2:
   3: Director {                           
# define myself
   4:
   Name = example-dir
   5:
   DIRport = 9101
   6:   QueryFile =
"/usr/libexec/bacula/query.sql"
   7:
   WorkingDirectory = /mnt/sda4/Backup/work/
   8:   PidDirectory =
"/var/run"
   9:
   Maximum Concurrent Jobs = 10
  10:   Password = "mypasswordhash"        
# Console password
  11:
   Messages = Standard
  12:
}
  13:
  14:
JobDefs {
  15:   Name =
"DefaultJob"
  16:
   Type = Backup
  17:
   Level = Incremental
  18:
   Client = example-fd 
  19:   FileSet =
"Local Server Set"
  20:   Schedule =
"WeeklyCycle"
  21:
   Storage = File
  22:
   Messages = Standard
  23:
   Pool = File
  24:
   Priority = 10
  25:   Write Bootstrap =
"/var/lib/bacula/%c.bsr"
  26:
}
  27:
  28:
  29:
#
  30:
# Define the main nightly save backup job
  31:
#   By default, this job will back up to disk in /tmp
  32:
Job {
  33:   Name =
"Local Server Job"
  34:
   Type = Backup
  35:
   Level = Incremental
  36:
   Client = example-fd
  37:   FileSet =
"Local Server Set"
  38:
   Schedule = WeeklyCycle
  39:
   Storage = File
  40:
   Pool = File
  41:
   Messages = Standard
  42:
}
  43:
  44:
#Job {
  45:
#  Name = "BackupClient2"
  46:
#  Client = example2-fd
  47:
#  JobDefs = "DefaultJob"
  48:
#}
  49:
  50:
# Backup the catalog database (after the nightly save)
  51:
Job {
  52:   Name =
"BackupCatalog"
  53:   JobDefs =
"DefaultJob"
  54:
   Level = Full
  55:   FileSet=
"Catalog"
  56:   Schedule =
"WeeklyCycleAfterBackup"
  57:  
# This creates an ASCII copy of the catalog
  58:  
# Arguments to make_catalog_backup.pl are:
  59:  
#  make_catalog_backup.pl <catalog-name>
  60:
   RunBeforeJob =
/usr/libexec/bacula/make_catalog_backup.pl MyCatalog"
  61:  
# This deletes the copy of the catalog
  62:   RunAfterJob  =
"/usr/libexec/bacula/delete_catalog_backup"
  63:   Write Bootstrap =
"/var/lib/bacula/%n.bsr"
  64:   Priority = 11                  
# run after main backup
  65:
}
  66:
  67:
#
  68:
# Standard Restore template, to be changed by Console program
  69:
#  Only one such job is needed for all Jobs/Clients/Storage ...
  70:
#
  71:
Job {
  72:   Name =
"RestoreFiles example"
  73:
   Type = Restore
  74:
   Client = example-fd
  75:   FileSet =
"Local Server Set"
  76:
   Storage = File
  77:
   Pool = Default
  78:
   Messages = Standard
  79:
   Where = /tmp/bacula-restores
  80:
}
  81:
  82:
  83:
# List of files to be backed up
  84:
FileSet {
  85:   Name =
"Local Server Set"
  86:
   Include {
  87:
     Options {
  88:
       signature = MD5
  89:
     }
  90:
#
  91:
#  Put your list of files here, preceded by 'File =', one per line
  92:
#    or include an external list with:
  93:
#
  94:
#    File = <file-name
  95:
#
  96:
#  Note: / backs up everything on the root partition.
  97:
#    if you have other partitions such as /usr or /home
  98:
#    you will probably want to add them too.
  99:
#
 100:
#  By default this is defined to point to the Bacula binary
 101:
#    directory to give a reasonable FileSet to backup to
 102:
#    disk storage during initial testing.
 103:
#
 104:
     File = /etc/
 105:
   }
 106:
 107:
#
 108:
# If you backup the root directory, the following two excluded
 109:
#   files can be useful
 110:
#
 111:
   Exclude {
 112:
     File = /var/lib/bacula
 113:
     File = /tmp
 114:
     File = /proc
 115:
     File = /tmp
 116:
     File = /.journal
 117:
     File = /.fsck
 118:
   }
 119:
}
 120:
 121:
#
 122:
# When to do the backups, full backup on first sunday of the month,
 123:
#  differential (i.e. incremental since full) every other sunday,
 124:
#  and incremental backups other days
 125:
Schedule {
 126:
   Name = WeeklyCycle
 127:
   Run = Level=Incremental Pool=File 1st sun at 23:05
 128:
}
 129:
 130:
# This schedule does the catalog. It starts after the WeeklyCycle
 131:
Schedule {
 132:
   Name = WeeklyCycleAfterBackup
 133:
   Run = Level=Full Pool=File sun-sat at 23:10
 134:
}
 135:
 136:
# This is the backup of the catalog
 137:
FileSet {
 138:   Name =
"Catalog"
 139:
   Include {
 140:
     Options {
 141:
       signature = MD5
 142:
     }
 143:     File =
"/var/lib/bacula/bacula.sql"
 144:
   }
 145:
}
 146:
 147:
# Client (File Services) to backup
 148:
Client {
 149:
   Name = example-fd
 150:
   Address = 127.0.0.1
 151:
   FDPort = 9102
 152:
   Catalog = MyCatalog
 153:
   Password = mypasswordhash
 154:
   File Retention = 30 days
 155:
   Job Retention = 6 months
 156:
   AutoPrune = yes
 157:
}
 158:
 159:
#
1
60:
# Second Client (File Services) to backup
 161:
#  You should change Name, Address, and Password before using
 162:
#
 163:
#Client {
 164:
#  Name = example2-fd
 165:
#  Address = example2
 166:
#  FDPort = 9102
 167:
#  Catalog = MyCatalog
 168:
#  Password = "mypasswordhash"         # password for FileDaemon 2
 169:
#  File Retention = 30 days            # 30 days
 170:
#  Job Retention = 6 months            # six months
 171:
#  AutoPrune = yes                     # Prune expired Jobs/Files
 172:
#}
 173:
 174:
 175:
# Definition of file storage device
 176:
Storage {
 177:
   Name = File
 178:
# Do not use "localhost" here
 179:   Address = example                
# N.B. Use a fully qualified name here
 180:
   SDPort = 9103
 181:   Password =
"mypasswordhash"
 182:
   Device = FileStorage
 183:
   Media Type = File
 184:
}
 185:
 186:
 187:
 188:
# Definition of DDS tape storage device
 189:
#Storage {
 190:
#  Name = DDS-4
 191:
#  Do not use "localhost" here
 192:
#  Address = example                # N.B. Use a fully qualified name here
 193:
#  SDPort = 9103
 194:
#  Password = "mypasswordhash"          # password for Storage daemon
 195:
#  Device = DDS-4                      # must be same as Device in Storage daemon
 196:
#  Media Type = DDS-4                  # must be same as MediaType in Storage daemon
 197:
#  Autochanger = yes                   # enable for autochanger device
 198:
#}
 199:
 200:
# Definition of 8mm tape storage device
 201:
#Storage {
 202:
#  Name = "8mmDrive"
 203:
#  Do not use "localhost" here
 204:
#  Address = example                # N.B. Use a fully qualified name here
 205:
#  SDPort = 9103
 206:
#  Password = "mypasswordhash"
 207:
#  Device = "Exabyte 8mm"
 208:
#  MediaType = "8mm"
 209:
#}
 210:
 211:
# Definition of DVD storage device
 212:
#Storage {
 213:
#  Name = "DVD"
 214:
#  Do not use "localhost" here
 215:
#  Address = example                # N.B. Use a fully qualified name here
 216:
#  SDPort = 9103
 217:
#  Password = "mypasswordhash"
 218:
#  Device = "DVD Writer"
 219:
#  MediaType = "DVD"
 220:
#}
 221:
 222:
 223:
# Generic catalog service
 224:
Catalog {
 225:
   Name = MyCatalog
 226:
# Uncomment the following line if you want the dbi driver
 227:
# dbdriver = "dbi:mysql"; dbaddress = 127.0.0.1; dbport =
 228:   dbname = "baculadb"; dbuser = "baculauser"; dbpassword =
"somepassword"
 229:
}
 230:
 231:
# Reasonable message delivery -- send most everything to email address
 232:
#  and to the console
 233:
Messages {
 234:
   Name = Standard
 235:
#
 236:
# NOTE! If you send to two email or more email addresses, you will need
 237:
#  to replace the %r in the from field (-f part) with a single valid
 238:
#  email address in both the mailcommand and the operatorcommand.
 239:
#  What this does is, it sets the email address that emails would display
 240:
#  in the FROM field, which is by default the same email as they're being
 241:
#  sent to.  However, if you send email to more than one address, then
 242:
#  you'll have to set the FROM address manually, to a single address. 
 243:
#  for example, a [email protected]', is better since that tends to
 244:
#  tell (most) people that its coming from an automated source.
 245:
 246:
#
 247:   mailcommand =
"/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
 248:   operatorcommand =
"/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
 249:
   mail = [email protected] = all, !skipped
 250:
   operator = [email protected] = mount
 251:
   console = all, !skipped, !saved
 252:
#
 253:
# WARNING! the following will create a file that you must cycle from
 254:
#          time to time as it will grow indefinitely. However, it will
 255:
#          also keep all your messages if they scroll off the console.
 256:
#
 257:   append = "/var/lib/bacula/log"
= all, !skipped
 258:
   catalog = all
 259:
}
 260:
 261:
 262:
#
 263:
# Message delivery for daemon messages (no job).
 264:
Messages {
 265:
   Name = Daemon
 266:   mailcommand =
"/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
 267:
   mail = [email protected] = all, !skipped
 268:
   console = all, !skipped, !saved
 269:   append = "/var/lib/bacula/log"
= all, !skipped
 270:
}
 271:
 272:
# Default pool definition
 273:
Pool {
 274:
   Name = Default
 275:
   Pool Type = Backup
 276:   Recycle = yes                      
# Bacula can automatically recycle Volumes
 277:   AutoPrune = yes                    
# Prune expired volumes
 278:   Volume Retention = 365 days        
# one year
 279:
}
 280:
 281:
# File Pool definition
 282:
Pool {
 283:
   Name = File
 284:
   Pool Type = Backup
 285:
   Recycle = yes
 286:
   AutoPrune = yes
 287:
   Volume Retention = 365 days
 288:
   Maximum Volume Bytes = 2G
 289:   Maximum Volumes = 100              
# Limit number of Volumes in Pool
 290:
   LabelFormat = Tape
 291:
}
 292:
 293:
 294:
# Scratch pool definition
 295:
Pool {
 296:
   Name = Scratch
 297:
   Pool Type = Backup
 298:
}
 299:
 300:
#
 301:
# Restricted console used by tray-monitor to get the status of the director
 302:
#
 303:
Console {
 304:
   Name = example-mon
 305:   Password =
"mypasswordhash"
 306:
   CommandACL = status, .status
 307:
}
 308:
 309:
Client {
 310:
   Name = other-client
 311:
   Address = 192.168.100.101
 312:
   FDPort = 9102
 313:
   Catalog = MyCatalog
 314:
   Password = mypasswordhash
 315:
   File Retention = 30 days
 316:
   Job Retention = 6 months
 317:
   AutoPrune = yes
 318:
}
 319:
 320:
FileSet {
 321:   Name =
"Other-client Set"
 322:
   Include {
 323:
     File = C:/test/
 324:
     Options {
 325:
     }
 326:
   }
 327:
}
 328:
Job {
 329:   Name =
"Other-Client Backup"
 330:
   Type = Backup
 331:
   Level = Incremental
 332:
   Client = other-client-fd
 333:   FileSet =
"Other-client Set"
 334:
   Schedule = WeeklyCycle
 335:
   Storage = File
 336:
   Pool = File
 337:
   Messages = Standard
 338: }

/etc/bacula/bacula-fd.conf (This is your Client configuration file, also called the File Daemon).
  1: #
  2: # List Directors who are permitted to contact this File daemon
  3: #
  4: Director {
  5:   Name = example-dir
  6:   Password = "mypasswordhash"
  7: }
  8:
  9: #
 10: # Restricted Director, used by tray-monitor to get the
 11: #   status of the file daemon
 12: #
 13: Director {
 14:   Name = example-mon
 15:   Password = "mypasswordhash"
 16:   Monitor = yes
 17: }
 18:
 19: #
 20: # "Global" File daemon configuration specifications
 21: #
 22: FileDaemon {                          # this is me
 23:   Name = example-fd
 24:   FDport = 9102
 25:   WorkingDirectory = /mnt/sda4/Backup/work/
 26:   Pid Directory = /var/run
 27:   Maximum Concurrent Jobs = 20
 28: }
 29:
 30: # Send all messages except skipped files back to Director
 31: Messages {
 32:   Name = Standard
 33:   director = example-dir = all, !skipped, !restored
 34: }

/etc/bacula/bacula-sd.conf (The Storage daemon configuration file, responsible for server storage procedures).


  1: #
  2: # List Directors who are permitted to contact this File daemon
  3: #
  4: Director {
  5:   Name = example-dir
  6:   Password = "mypasswordhash"
  7: }
  8:
  9: #
 10: # Restricted Director, used by tray-monitor to get the
 11: #   status of the file daemon
 12: #
 13: Director {
 14:   Name = example-mon
 15:   Password = "mypasswordhash"
 16:   Monitor = yes
 17: }
 18:
 19: #
 20: # "Global" File daemon configuration specifications
 21: #
 22: FileDaemon {                          # this is me
 23:   Name = example-fd
 24:   FDport = 9102
 25:   WorkingDirectory = /mnt/sda4/Backup/work/
 26:   Pid Directory = /var/run
 27:   Maximum Concurrent Jobs = 20
 28: }
 29:
 30: # Send all messages except skipped files back to Director
 31: Messages {
 32:   Name = Standard
 33:   director = example-dir = all, !skipped, !restored
 34: }<?xml:namespace prefix = o />

/etc/bacula/bconsole.conf (The last one, responsible for frontend connections, user agents, console connections, etc).

  1: #
  2: # List Directors who are permitted to contact this File daemon
  3: #
  4: Director {
  5:   Name = example-dir
  6:   Password = "mypasswordhash"
  7: }
  8:
  9: #
 10: # Restricted Director, used by tray-monitor to get the
 11: #   status of the file daemon
 12: #
 13: Director {
 14:   Name = example-mon
 15:   Password = "mypasswordhash"
 16:   Monitor = yes
 17: }
 18:
 19: #
 20: # "Global" File daemon configuration specifications
 21: #
 22: FileDaemon {                          # this is me
 23:   Name = example-fd
 24:   FDport = 9102
 25:   WorkingDirectory = /mnt/sda4/Backup/work/
 26:   Pid Directory = /var/run
 27:   Maximum Concurrent Jobs = 20
 28: }
 29:
 30: # Send all messages except skipped files back to Director
 31: Messages {
 32:   Name = Standard
 33:   director = example-dir = all, !skipped, !restored
 34: }<?xml:namespace prefix = o />

Now you’re able to make some backups using bconsole, let’s test:

example ~ # bconsole
Connecting to Director example:9101
1000 OK: example-dir Version: 5.0.1 (24 February 2010)
Enter a period to cancel a command.
*help
  Command       Description
  =======       ===========
  add           Add media to a pool
  autodisplay   Autodisplay console messages
  automount     Automount after label
  cancel        Cancel a job
  create        Create DB Pool from resource
  delete        Delete volume, pool or job
  disable       Disable a job
  enable        Enable a job
  estimate      Performs FileSet estimate, listing gives full listing
  exit          Terminate Bconsole session
  gui           Non-interactive gui mode
  help          Print help on specific command
  label         Label a tape
  list          List objects from catalog
  llist         Full or long list like list command
  messages      Display pending messages
  memory        Print current memory usage
  mount         Mount storage
  prune         Prune expired records from catalog
  purge         Purge records from catalog
  python        Python control commands
  quit          Terminate Bconsole session
  query         Query catalog
  restore       Restore files
  relabel       Relabel a tape
  release       Release storage
  reload        Reload conf file
  run           Run a job
  status        Report status
  setdebug      Sets debug level
  setip         Sets new client address -- if authorized
  show          Show resource records
  sqlquery      Use SQL to query catalog
  time          Print current time
  trace         Turn on/off trace to file
  unmount       Unmount storage
  umount        Umount - for old-time Unix guys, see unmount
  update        Update volume, pool or stats
  use           Use catalog xxx
  var           Does variable expansion
  version       Print Director version
  wait          Wait until no jobs are running 


When at a prompt, entering a period cancels the command.

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: Local Server Job
     2: BackupCatalog
     3: RestoreFiles example
     4: Other-Client Backup
Select Job resource (1-4): 1
Run Backup job
JobName:  Local Server Job
Level:    Incremental
Client:   example-fd
FileSet:  Local Server Set
Pool:     File (From Job resource)
Storage:  File (From Job resource)
When:     2010-05-04 19:22:39
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=19
*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 3
The defined Client resources are:
     1: example-fd
     2: other-client-fd
Select Client (File daemon) resource (1-2): 1
Connecting to Client example-fd at 127.0.0.1:9102
 
example-fd Version: 5.0.1 (24 February 2010)  i686-pc-linux-gnu gentoo
Daemon started 28-Apr-10 15:29, 12 Jobs run since started.
Heap: heap=606,208 smbytes=81,435 max_bytes=162,215 bufs=68 max_bufs=115
Sizeof: boffset_t=8 size_t=4 debug=0 trace=0
 
Running Jobs:
Director connected at: 04-May-10 19:22
No Jobs running.
====
 
Terminated Jobs:
JobId  Level    Files      Bytes   Status   Finished        Name
======================================================================
     1  Incr          0         0   OK       04-May-10 19:22 Local_Server_Job
====
*

If everything is ok, you’ll not see any errors in status command, and also you’ll be able to verify what have done.

Now is everything ok, I HIGHLY recommend you to use bacula frontend in webmin to configure clients.

No comments:

Post a Comment