一、Bacula配置
Bacula备份的主要配置项目存放在bacula-dir.conf文件中,该文件中的配置项包含以下内容。
Jobdefs:默认执行任务
Job:自定义一个备份或恢复任务
Fileset:定义备份那些数据,不备份那些数据
Schedule:定义备份时间策略
Pool:定义供Job使用的池属性
Client:定义要备份的主机地址
Storange:定义数据的存储方式
Messages:定义发送日子报告和记录日志的位置
各项目定义的名称会相互关联,如下图所示。
3.1 bacula-dir.conf配置
主控端的Director项:
1、Name和Console端Director项的Name一致;
2、Name要和介质端Director项的Name一致;
3、Name要和客户端Director项的Name一致;
4、Password项要和Console端的Password项的密码一致;
主控端的Storage项:
1、Device要和介质端Device项的Name一致;
2、MediaType要和介质端Device项的MediaType一致;
3、Password要和介质端Director项的Pasword一致;
主控端的Client项:
Password要和客户端Director项的Password一致;
vim /etc/bacula/bacula-dir.conf
Director {#全局设置
Name = bacula-test-dir #名称要和Console端、SD端、FD端一致
DIRport = 9101 #启动的端口
QueryFile = "/usr/libexec/bacula/query.sql"
WorkingDirectory = "/var/spool/bacula/"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 20 #同时执行的最大任务数量
Password = "u3R1MUpLlKodHFr4PiqGQMGJfaNfhiXb14ul6xcpBA8d" #密码和Console端一致
Messages = Daemon
}
JobDefs { #默认的任务设置
Name = "DefaultJob" #任务名称
Type = Backup #任务的类型,有备份、恢复、校验、管理等
Level = Incremental #增量备份,有差异、全备份
Client = bacula-test-fd #备份的客户端
FileSet = "Full Set" #选择客户端需要备份额目录及文件
Schedule = "WeeklyCycle" #备份周期
Storage = File1 #存储的方式
Messages = Standard
Pool = File
SpoolAttributes = yes
Priority = 10
Write Bootstrap = "/var/spool/bacula/%c.bsr" #将作业记录写入文件
}
Job {
Name = "Backup-17.98" #定义一个备份任务
Type = Backup
Level = Incremental
Client = bacula-17-98 #需要备份的客户端
FileSet = "Windows" #需要备份的目录和文件
Schedule = "WeeklyCycle"
Storage = File1
Messages = Standard
Pool = File
SpoolAttributes = yes
Priority = 10
Write Bootstrap = "/var/spool/bacula/windows%c.bsr"
}
Job {
Name = "BackupClient1"
JobDefs = "DefaultJob"
}
Job {
Name = "BackupCatalog" #定义一个元数据备份任务
JobDefs = "DefaultJob"
Level = Full
FileSet="Catalog"
Schedule = "WeeklyCycleAfterBackup"
RunBeforeJob = "/usr/libexec/bacula/make_catalog_backup.pl MyCatalog"
RunAfterJob = "/usr/libexec/bacula/delete_catalog_backup"
Write Bootstrap = "/var/spool/bacula/%n.bsr"
Priority = 11
}
Job {
Name = "RestoreFiles" #定义一个恢复任务
Type = Restore
Client=bacula-test-fd
FileSet="Full Set"
Storage = File1
Pool = File
Messages = Standard
Where = /tmp/bacula-restores
}
FileSet {
Name = "Full Set" #定义需要备份的目录及文件
Include {
Options {
signature = MD5 #采用MD5
Compression = GZIP #启用GZIP压缩
}
File = /var/lib/mysql #需要备份的目录
}
Exclude { #无需备份的目录和文件
File = /var/spool/bacula/
File = /tmp
File = /proc
File = /tmp
File = /sys
File = /.journal
File = /.fsck
}
}
FileSet {
Name = "Windows" #定义一个新的需要备份的设置
Include {
Options {
signature = MD5
compression = GZIP
IgnoreCase = yes
}
File = "D:/msdn"
}
}
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/spool/bacula/bacula.sql"
}
}
Client {
Name = bacula-test-fd #定义需要备份的客户端
Address = 192.168.17.100
FDPort = 9102
Catalog = MyCatalog
Password = "nb5dURhiVT3RPsHkFvXetau9LrnL/FhY/ORWkFOTPamT"#密码要和FD端的一致
File Retention = 30 days #定义文件记录在 Catalog 数据库中的保留时间,不影响已存档的备份文件
Job Retention = 3 months #定义任务记录在 Catalog 数据库中的保留时间,不影响已存档的备份文件
AutoPrune = yes #自动修剪
}
Client {
Name = bacula-17-98
Address = 192.168.17.98
FDPort = 9102
Catalog = MyCatalog
Password = "nb5dURhiVT3RPsHkFvXetau9LrnL/FhY/ORWkFOTPamT"
File Retention = 30 days
Job Retention = 3 months
AutoPrune = yes
}
Storage {
Name = File1
Address = 192.168.17.100 #存储端的地址
SDPort = 9103
Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg"
Device = FileChgr1 #指定存储的设备。引用存储端配置文件的 Device{}的 Name 值
Media Type = File1 #与存储端配置文件的 Device{}的 Media Type 值相同
Maximum Concurrent Jobs = 10 #定义此存储端所允许同时进行的任务最大数量
}
Storage {
Name = File2
Address = 192.168.17.100
SDPort = 9103
Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg"
Device = FileChgr2
Media Type = File2
Maximum Concurrent Jobs = 10
}
Catalog {
Name = MyCatalog #指定 Catalog{}名称
dbname = "bacula"; dbuser = "bacula"; dbpassword = "bacula"
}
Messages {
Name = Standard #定义日志
append = "/var/log/bacula.log" = all, !skipped
append = "/var/log/bacula.err.log" = error,warning,fatal
catalog = all
}
Messages {
Name = Daemon
append = "/var/log/bacula.log" = all, !skipped
append = "/var/log/bacula.err.log" = error,warning,fatal
}
Pool {
Name = Default
Pool Type = Backup
Recycle = yes #是否重复使用 Volumes
AutoPrune = yes #自动清理
Maximum Volume Jobs = 1
Volume Retention = 15 days #卷的保留时间
Maximum Volume Bytes = 5G #Volume容量
Maximum Volumes = 100 #Volumes数量l
Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"#卷命名方式
}
Pool {
Name = File
Pool Type = Backup
Recycle = yes
AutoPrune = yes
Maximum Volume Jobs = 1
Volume Retention = 15 days
Maximum Volume Bytes = 50G
Maximum Volumes = 100
Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"
}
# Scratch pool definition
Pool {
Name = Scratch
Pool Type = Backup
}
Console {
Name = bacula-test-mon
Password = "fX2cKUkN2RSiLTkeQd5LCPDDw61PzGkuit2+7DvWxVG1"
CommandACL = status, .status
}
3.2 bacula-sd.conf配置
存储端的配置文件是bacula-sd.conf,它主要负责定义备份文件的存放方式和地址,具体的情况如下所示:
Storage { #定义存储端名称
Name = bacula-test-sd
SDPort = 9103
WorkingDirectory = "/var/spool/bacula/"
Pid Directory = "/var/run"
Maximum Concurrent Jobs = 20
}
Director {
Name = bacula-test-dir
Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg"
}
Director {
Name = bacula-test-mon
Password = "7zSF0B9viPBuwkKpPC2PoJw1qxOEuvCxbWDxzXc1cHk9"
Monitor = yes
}
Autochanger {#是否自动更换设备
Name = FileChgr1
Device = FileChgr1-Dev1, FileChgr1-Dev2#定义需更换的设备
Changer Command = ""
Changer Device = /dev/null
}
Device {
Name = FileChgr1-Dev1
Media Type = File1#类型是文件(可以是DVD,磁带)
Archive Device = /tmp#存放位置
LabelMedia = yes; #媒体标注
Random Access = Yes;
AutomaticMount = yes; #自动挂载
RemovableMedia = no;
AlwaysOpen = no;
Maximum Concurrent Jobs = 5
}
Device {
Name = FileChgr1-Dev2
Media Type = File1
Archive Device = /tmp
LabelMedia = yes;
Random Access = Yes;
AutomaticMount = yes;
RemovableMedia = no;
AlwaysOpen = no;
Maximum Concurrent Jobs = 5
}
Autochanger {
Name = FileChgr2
Device = FileChgr2-Dev1, FileChgr2-Dev2
Changer Command = ""
Changer Device = /dev/null
}
Device {
Name = FileChgr2-Dev1
Media Type = File2
Archive Device = /tmp
LabelMedia = yes;
Random Access = Yes;
AutomaticMount = yes;
RemovableMedia = no;
AlwaysOpen = no;
Maximum Concurrent Jobs = 5
}
Device {
Name = FileChgr2-Dev2
Media Type = File2
Archive Device = /tmp
LabelMedia = yes;
Random Access = Yes;
AutomaticMount = yes;
RemovableMedia = no;
AlwaysOpen = no;
Maximum Concurrent Jobs = 5
}
Messages {
Name = Standard
director = bacula-test-dir = all
}
二、Bacula备份、恢复测试
2.1 备份操作
运行备份操作
[root@bacula-test /tmp]
#bconsole
Connecting to Director 192.168.17.100:9101
1000 OK: 102 bacula-test-dir Version: 7.4.1 (15 February 2016)
Enter a period to cancel a command.
*label #标签状态
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
1: File1
2: File2
Select Storage resource (1-2): 1 #定义的存储资源
Enter new Volume name: vol-20160601
Defined Pools:
1: Default
2: File
3: Scratch
Select the Pool (1-3): 2 #文件类型
Connecting to Storage daemon File1 at 192.168.17.100:9103 ...
Sending label command for Volume "vol-20160601" Slot 0 ...
3000 OK label. VolBytes=209 VolABytes=0 VolType=1 Volume="vol-20160601" Device="FileChgr1-Dev1" (/tmp)
Catalog record for Volume "vol-20160601", Slot 0 successfully created.
Requesting to mount FileChgr1 ...
3906 File device ""FileChgr1-Dev1" (/tmp)" is always mounted.
*run #执行备份操作
A job name must be specified.
The defined Job resources are:
1: Backup-17.98
2: BackupClient1
3: BackupCatalog
4: RestoreFiles
Select Job resource (1-4): 3 #选择需要备份的客户端
Run Backup job
JobName: BackupCatalog
Level: Full
Client: bacula-test-fd
FileSet: Catalog
Pool: File (From Job resource)
Storage: File1 (From Job resource)
When: 2016-06-01 15:59:49
Priority: 11
OK to run? (yes/mod/no): yes #同意备份
Job queued. JobId=37
*messages
You have no messages.
*exit
4.2 恢复操作
#bconsole
Connecting to Director 192.168.17.100:9101
1000 OK: 102 bacula-test-dir Version: 7.4.1 (15 February 2016)
Enter a period to cancel a command.
*restore
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.
To select the JobIds, you have the following choices:
1: List last 20 Jobs run
2: List Jobs where a given File is saved
3: Enter list of comma separated JobIds to select
4: Enter SQL list command
5: Select the most recent backup for a client
6: Select backup for a client before a specified time
7: Enter a list of files to restore
8: Enter a list of files to restore before a specified time
9: Find the JobIds of the most recent backup for a client
10: Find the JobIds for a backup for a client before a specified time
11: Enter a list of directories to restore for found JobIds
12: Select full restore to a specified Job date
13: Cancel
Select item: (1-13): 5
Defined Clients:
1: bacula-17-98
2: bacula-test-fd
Select the Client (1-2): 2
The defined FileSet resources are:
1: Catalog
2: Full Set
Select FileSet resource (1-2): 2
+-------+-------+----------+-----------+---------------------+--------------------+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+-------+-------+----------+-----------+---------------------+--------------------+
| 1 | F | 126 | 731,496 | 2016-05-18 16:02:32 | linux-file1 |
| 29 | D | 5 | 991,369 | 2016-05-29 23:05:04 | db-2016-05-29-id29 |
| 32 | I | 2 | 1,000,660 | 2016-05-30 23:05:04 | db-2016-05-30-id32 |
| 35 | I | 2 | 1,038,878 | 2016-05-31 23:05:05 | db-2016-05-31-id35 |
+-------+-------+----------+-----------+---------------------+--------------------+
You have selected the following JobIds: 1,29,32,35
Building directory tree for JobId(s) 1,29,32,35 ... ++++++++++++++++++++++++++++++++++++++++
122 files inserted into the tree.
You are now entering file selection mode where you add (mark) and
remove (unmark) files to be restored. No files are initially added, unless
you used the "all" keyword on the command line.
Enter "done" to leave this mode.
cwd is: /
ls
var/
$ mark var
126 files marked.
$ lsmark
*var/
*lib/
*mysql/
*aria_log.00000001
*aria_log_control
*bacula/
*BaseFiles.frm
*CDImages.frm
*Client.frm
done
Bootstrap records written to /var/spool/bacula//bacula-test-dir.restore.1.bsr
Bootstrap records written to /var/spool/bacula//bacula-test-dir.restore.1.bsr
The Job will require the following (*=>InChanger):
Volume(s) Storage(s) SD Device(s)
===========================================================================
linux-file1 File1 FileChgr1
db-2016-05-29-id29 File1 FileChgr1
db-2016-05-31-id35 File1 FileChgr1
Volumes marked with "*" are in the Autochanger.
126 files selected to be restored.
Using Catalog "MyCatalog"
Run Restore job
JobName: RestoreFiles
Bootstrap: /var/spool/bacula//bacula-test-dir.restore.1.bsr
Where: /tmp/bacula-restores
Replace: Always
FileSet: Full Set
Backup Client: bacula-test-fd
Restore Client: bacula-test-fd
Storage: File1
When: 2016-06-01 16:08:14
Catalog: MyCatalog
Priority: 10
Plugin Options:
OK to run? (yes/mod/no): yes
Job queued. JobId=38
*messages
You have no messages.
参考内容:
企业级的开源备份工具Bacula之安装:http://waringid.blog.51cto.com/65148/1792007