关于bacula配置与使用

Bacula结构复杂,采用模块设计,让bacula运行起来需要5个步骤:
(1)安装Bacula所支持的一种数据库以及Bacula的守护进程;
(2)配置Bacula的守护进程;
(3)安装和配置客户机上的文件守护进程;
(4)启动Bacula的守护进程;
(5)用Bacula控制台把介质加入存储池;

客户机只运行一个文件守护进程,其余的4个组件(控制器守护进程bacula-dir.conf,存储守护进程bacula-sd.conf,编目数据库MySql和控制台bconsole.conf)都运行在服务器,存储设备为文件系统!

bacula-dir.conf 是最复杂的一个文件,它一共有 10 个逻辑段:
director (定义全局),
catalog (定义日志),
jobdefs( 定义备份的默认值 )
job (定义特定操作),
fileset (定义备份哪些区域不备份哪些区域),
schedule (定义备份时间),
pool (定义备份介质),
client (定义要备份的主机),
storage (定义如何存储)
messages (定义如何处理消息)

本文是以当前最新的bacula版本做为基础,来安装和编译bacula,如有不足之处希望大家提出建议。
1,由于bacula需要数据库,支持MySql,PostgreSQL,SQLite;这里使用mysql数据库
(1),yum install  mysql mysql-* (关于yum的配置就不在阐述,也可以用rpm的方式安装)
(2),/etc/init.d/mysql start  (查看数据库看是否可以正常启动)
 
2,下载和编译bacula软件
(1),wget https://sourceforge.net/projects/bacula/files/bacula/3.0.3/bacula-3.0.3.tar.gz/download
(2),tar xvf bacula-3.0.3.tar.gz -C /usr/src
(3),cd /usr/src/bacula-3.0.3/
(4),./configure --with-mysql  (由于配置文件默认在/etc/bacula里面,就不指定--prefix)
(5),make && make install
(6),cd /etc/bacula/
(7),./grant_mysql_privileges
(8), ./create_mysql_database
(9),./make_mysql_tables
(10),查看mysql数据库是否建立,
mysql (默认没有密码)
[root@dg1 conf]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.22-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bacula             |
| mysql              |
mysql>use bacula;
mysql>show tables;
---------------------
========

3,设置配置文件
vim /etc/bacula/bacula-dir.conf
Director {                            # define myself
  Name = oracle.mt.com-dir
  DIRport = 9101                # where we listen for UA connections
  QueryFile = "/etc/bacula/query.sql"
  WorkingDirectory = "/var/bacula/working"
  PidDirectory = "/var/run"
  Maximum Concurrent Jobs = 1
  Password = "awqSCSuFrb8vew9qAikVQyI7J1KesQGpG1gMwJVybxME"         # Console password
  Messages = Daemon
}
JobDefs {
  Name = "DefaultJob"
  Type = Backup
  Level = Incremental
  Client = oracle.mt.com-fd
  FileSet = "Full Set"
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = Default
  Priority = 10
}
Job {
  Name = "Backup1"
  JobDefs = "DefaultJob"
  Write Bootstrap = "/var/bacula/working/Client1.bsr"
}

Job {
  Name = "RestoreFiles"
  Type = Restore
  Client=oracle.mt.com-fd
  FileSet="Full Set"
  Storage = File
  Pool = Default
  Messages = Standard
  Where = /tmp/bacula-restores
}
# List of files to be backed up
FileSet {
  Name = "Full Set"
  Include {
    Options {
      signature = MD5
    }
    File = /boot
  }
#
# If you backup the root directory, the following two excluded
#   files can be useful
#
  Exclude {
    File = /var/bacula/working
    File = /tmp
    File = /proc
    File = /tmp
    File = /.journal
    File = /.fsck
  }
}
Schedule {
  Name = "WeeklyCycle"
  Run = Full 1st sun at 14:05
  Run = Differential 2nd-5th sun at 14:05
  Run = Incremental mon-sat at 14:05
}

Schedule {
  Name = "WeeklyCycleAfterBackup"
  Run = Full sun-sat at 14:10
}
# This is the backup of the catalog
FileSet {
  Name = "Catalog"
  Include {
    Options {
      signature = MD5
    }
    File = /var/bacula/working/bacula.sql
  }
}
# Client (File Services) to backup
Client {
  Name = oracle.mt.com-fd
# Address = localhost
  Address = 192.168.0.211
  FDPort = 9102
  Catalog = MyCatalog
  Password = "pl9YHiabos0Cn2ixQzfYQ8BV/vrkUWe2A9oleyxeAfvr"          # password for FileDaemon
  File Retention = 30 days            # 30 days
  Job Retention = 6 months            # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}
Storage {
  Name = File
# Do not use "localhost" here
  Address = localhost                # N.B. Use a fully qualified name here
  SDPort = 9103
  Password = "bVPfyrxzu4P1Vhs11DkF+cAUjPyv7zOabBtqbj7N9GRt"
  Device = FileStorage
  Media Type = File
}


Catalog {
  Name = MyCatalog
# Uncomment the following line if you want the dbi driver
# dbdriver = "dbi:mysql"; dbaddress = 127.0.0.1; dbport =
  dbname = "bacula"; dbuser = "bacula"; dbpassword = ""
}


Messages {
  Name = Standard
 mailcommand = "/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/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 = "/var/bacula/working/log" = all, !skipped
  catalog = all
}
Messages {
  Name = Daemon
  mailcommand = "/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
  mail = root@localhost = all, !skipped
  console = all, !skipped, !saved
  append = "/var/bacula/working/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
}

# Scratch pool definition
Pool {
  Name = Scratch
  Pool Type = Backup
}Console {
  Name = oracle.mt.com-mon
  Password = "vqYgXXWcLrQSYe66BWmaQAXqqVsTEcqCGXjuBwc3Agc8"
  CommandACL = status, .status
}


vim /etc/bacula/bacula-sd.conf
Storage {                             # definition of myself
  Name = oracle.mt.com-sd
  SDPort = 9103                  # Director's port
  WorkingDirectory = "/var/bacula/working"
  Pid Directory = "/var/run"
  Maximum Concurrent Jobs = 20
}

#
# List Directors who are permitted to contact Storage daemon
#
Director {
  Name = oracle.mt.com-dir
  Password = "bVPfyrxzu4P1Vhs11DkF+cAUjPyv7zOabBtqbj7N9GRt"
}
Device {
  Name = FileStorage
  Media Type = File
  Archive Device = /share/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 = oracle.mt.com-dir = all
}


vim /etc/bconsole.conf

Director {
  Name = oracle.mt.com-dir
  DIRport = 9101
  address = 192.168.0.212
  Password = "awqSCSuFrb8vew9qAikVQyI7J1KesQGpG1gMwJVybxME"
}
=======
注意点:当数据库mysql没有启动的时候:
报错如下:
[root@oracle working]# bconsole
Connecting to Director 192.168.0.212:9101
21-11月 02:36 bconsole JobId 0: Fatal error: bsock.c:135 Unable to connect to Director daemon on 192.168.0.212:9101. ERR=拒绝连接
你会发现9101端口也没有启动。
排错的方法:cat /var/bacula/working/log



客户端配置
(1),tar xvf bacula-3.0.3.tar.gz -C /usr/src
(2),cd /usr/src/bacula-3.0.3/
(3),./configure --enable-client-only
(4),make && make install
(5)[root@server bacula]# vim bacula-fd.conf
Director {
  Name = server.mt.com-mon
  Password ="ni17ykBhtll/pqJ+rgvM9M8UrtHWA2MLcTMcLah/d+HZ"
  Monitor = yes
}


# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = server.mt.com-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /var/bacula/working
  Pid Directory = /var/run
  Maximum Concurrent Jobs = 20
}

# Send all messages except skipped files back to Director
Messages {
  Name = Standard
  director = server.mt.com-dir = all, !skipped, !restored
}
=====
这个配置文件由3个部分组成,第一部分由Director资源构成,告诉文件守护进程那个控制器能够从这个客户机的文件守护进程来布置执行备份作业。Password参数,必须和控制机器自己的配置文件中Client资源里列出的口令一样。第二部分FileDaemon资源,它给客户机起名字,并且指定文件守护进程在那个端口上监听从控制器守护进程发来的命令。第三个,Message规定本地的消息如何处理。



........待续

本文出自 “阿狼” 博客,转载请与作者联系!

你可能感兴趣的:(linux,职场,backup,bacula,休闲)