Sunday, February 21, 2016

Network Backup Solution using bacula

bacula is a network Client/Server based backup program that permits you (or the system administrator) to manage backup, recovery, and verification of computer data  across  a  network of computers of different kinds.


*** information ***
-client ip: 192.168.202.23,
                mysql password/user/db:mysqlpassword/bacula/bacula (usually
                created during installation both client and server)

-server:  192.168.202.1, fqdn: s1.backup.server
           storage medium: hard disk, backup location: /backup

-password use between server/client:_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f

+ server side
1- install software
$ sudo apt-get install bacula

2- configure storage daemon, by edit file /etc/bacula/bacula-sd.conf with the following content
Storage {                             # definition of myself
  Name = FileStorageRemote
  SDPort = 9103                  # Director's port     
  WorkingDirectory = "/var/lib/bacula"
  Pid Directory = "/var/run/bacula"
  Maximum Concurrent Jobs = 20
  SDAddress = 192.168.202.1
}

Director {
  Name = FileStorageRemoteDir
  Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"
}
Device {
  Name = FileBackup
  Media Type = File
  Archive Device = /backup
  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 = FileStorageRemoteDir = all
}


3- create /backup directory and restart the bacula-sd and it ready to serve
$ sudo mkdir /backup
$ sudo service bacula-sd restart

+ client side
install software:
$ sudo apt-get install bacula
1- configure bconsole, where it list the diretory when you interact with command line. in /etc/bacula/bconsole.conf with content below:
Director {
  Name = FileStorageRemoteDir
  DIRport = 9101
  address = localhost
  Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"
}


2- configure Bacula's File Daemon , file /etc/bacula/bacula-fd.conf
 Director {
 Name = FileStorageRemoteDir
 Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"
}
FileDaemon {                          # this is me
  Name = ubuntu-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /var/lib/bacula
  Pid Directory = /var/run/bacula
  Maximum Concurrent Jobs = 20
  FDAddress = 127.0.0.1
}
Messages {
  Name = Standard
  director = FileStorageRemoteDir = all, !skipped, !restored
}

3- configure backup jobs, restore job and pool(how to store the backup file) in /etc/bacula/bacula-dir.conf
# directory name same as on server
Director {
 Name = FileStorageRemoteDir
 DIRport = 9101
 QueryFile = "/etc/bacula/scripts/query.sql"
 Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"
 WorkingDirectory = "/var/lib/bacula"
 PidDirectory = "/var/run/bacula"
 Messages = Daemon
 DirAddress = 127.0.0.1
}

#backup job
Job {
  Name = "BackupEtc"
  Type = Backup
  Client = ubuntu-fd
  FileSet="Full Set etc"
  Storage = FileStorageRemote
  Messages = Standard
 Level = Incremental
  Schedule = "WeeklyCycle"
  Storage = FileStorageRemote
  Pool = File
}

#restore job
Job {
  Name = "RestoreFiles"
  Type = Restore
  Client=ubuntu-fd
  FileSet="Full Set etc"                 
  Storage = FileStorageRemote                     
  Pool = Default
  Messages = Standard
  Where = /
}
# file set that we define to restore/backup in backup job and restore job
FileSet {
  Name = "Full Set etc"
  Include {
    Options {
      signature = MD5
    }
    File = /
  }
  Exclude {
    File = /var
    File = /usr
    File = /proc
    File = /tmp
    File = /lib
    File = /lib64
    File = /boot
    File = /bin
    File = /sbin
    File = /sys
    File = /dev
    File = /home
    File = /root
  }
}
Schedule {
  Name = "WeeklyCycle"
  Run = Full 1st sun at 23:05
  Run = Differential 2nd-5th sun at 23:05
  Run = Incremental mon-sat at 23:05
}
Schedule {
  Name = "WeeklyCycleAfterBackup"
  Run = Full sun-sat at 23:10
}
FileSet {
  Name = "Catalog"
  Include {
    Options {
      signature = MD5
    }
    File = "/var/lib/bacula/bacula.sql"
  }
}
Client {
  Name = ubuntu-fd
  Address = localhost
  FDPort = 9102
  Catalog = MyCatalog
  Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"          # password for FileDaemon
  File Retention = 30 days            # 30 days
  Job Retention = 6 months            # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}

#connect to our storage server
Storage {
  Name = FileStorageRemote
  Address = s1.backup.server               # N.B. Use a fully qualified name here
  SDPort = 9103
  Password = "_pNUHwX3uJ86q9E4vqUkGMWyfshHe5Y7f"
  Device = FileBackup
  Media Type = File
}
Catalog {
  Name = MyCatalog
  dbname = "bacula"; DB Address = ""; dbuser = "bacula"; dbpassword = "mysqlpassword"
}
Messages {
  Name = Standard
  mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
  mail = root = all, !skipped           
  operator = root = mount
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
  catalog = all
}
Messages {
  Name = Daemon
  mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
  mail = root = all, !skipped           
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
}
Pool {
  Name = Default
  Pool Type = Backup
  Recycle = yes                       # Bacula can automatically recycle Volumes
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 365 days         # one year
}

# pool define the way we storage our backup
Pool {
  Name = File
  Pool Type = Backup
  Recycle = yes                       # Bacula can automatically recycle Volumes
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 365 days         # one year
  Maximum Volume Bytes = 50G          # Limit Volume size to something reasonable
  Maximum Volumes = 100               # Limit number of Volumes in Pool
  Label Format = "File-"
}
Pool {
  Name = Scratch
  Pool Type = Backup
}


4- restart service file daemon and directory when we are ready.
$ sudo service bacula-director restart
$ sudo service bacula-fd restart

+ how to backup and restore
1- usually it will backup automatically with what we define in schedule, but can manually back in command bconsole

$ sudo bconsole
* run
then select the jobs that we want to perfome

2- restore
$ sudo bconsole
* status all (list the jobs with it id needed when restore
* restore all
* 3
* (type your jobs id, if you use full + incremental backup you may type full id + incremtal ids

-image of status all command in bconsole
Network Backup Solution using bacula


*** Tips for jobs related command ***
-Last jobs                                   :  list jobs     …or list jobid=xx’ for a specific job
-Statistics about last lobs          :  list jobtotal
-Which files were backed up?   :  list files jobid=xx




No comments:

Post a Comment