设为首页 收藏本站
查看: 745|回复: 0

[经验分享] 企业级的开源备份工具Bacula之配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-6-29 10:01:37 | 显示全部楼层 |阅读模式
一、Bacula配置
    Bacula备份的主要配置项目存放在bacula-dir.conf文件中,该文件中的配置项包含以下内容。
Jobdefs:默认执行任务
Job:自定义一个备份或恢复任务
Fileset:定义备份那些数据,不备份那些数据
Schedule:定义备份时间策略
Pool:定义供Job使用的池属性
Client:定义要备份的主机地址
Storange:定义数据的存储方式
Messages:定义发送日子报告和记录日志的位置
QQ截图20160629100031.png

各项目定义的名称会相互关联,如下图所示。
QQ截图20160629100042.png

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一致;
1
vim /etc/bacula/bacula-dir.conf



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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,它主要负责定义备份文件的存放方式和地址,具体的情况如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 备份操作
运行备份操作
[iyunv@bacula-test /tmp]
1
#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.
1
*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.
1
*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
1
*messages



You have no messages.
1
*exit



QQ截图20160629100053.png
4.2 恢复操作
1
#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.
1
*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: /
1
  ls



var/
1
$ mark var



126 files marked.
1
$ lsmark



*var/
  *lib/
    *mysql/
      *aria_log.00000001
      *aria_log_control
      *bacula/
        *BaseFiles.frm
        *CDImages.frm
        *Client.frm
1
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
1
*messages



You have no messages.                 


QQ截图20160629100104.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-236820-1-1.html 上篇帖子: Websphere查看修改节点端口 下篇帖子: linux 6.x network device not active
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表