bacula网络备份与恢复

bacula网络备份与恢复

转载于:   http://www.linux8080.com/?p=458

一、bacula介绍

bacula是一款开源的跨平台网络备份工具,它提供了基于企业级的客户端/服务器的备份恢复解决方案,通过它,系统管理人员可以对 数据进行备份、恢复,以及完整性验证等操作,同时,它还提供了许多高级存储管理功能,使系统管理人员能够很容易发现并恢复丢失的或已经损坏的文件。 bacula既有Windows版本的,也有Linux和UNIX版本的。

功能特点:
支持完全备份,增量备份,差异备份。
支持多种恢复方式
支持多种文件系统下的备份恢复(ext3、ext2、reiserfs、xfs、jfs、smbfs、iso9660、ntfs等)
支持各种备份介质
支持多种操作系统
强大的内部功能

一个完整的bacula备份系统由Director Daemon、Storage Daemon(SD)、File Daemon(FD)、Console、Monitor这五部分组成

工作流程:
1、通过console连接到Director端,备份恢复操作开始。
2、Director端从自己的数据库中调出记录信息,对存储端SD与客户端FD的任务进行协调。
3、客户端FD负责验证Director的操作许可,如果验证通过,则允许连接到存储端SD
4、客户端FD根据Director发出的请求去连接SD,将FD端的数据备份到存SD指定的存储介质上,或者将SD端存储介质中的数据传回到客户端FD指定的位置上,完成备份恢复过程。

二、安装bacula

bacula部署环境:

主机名                   IP                             操作系统                     应用角色                        数据库

baculaServer    192.168.1.200          Centos 6.2          Director、SD、Console            Mysql

baculaClient      192.168.1.222          Centos 6.2                        FD

Director Daemon支持的数据库有MySQL、PostgreSQL、SQLite,这里baculaServer用到的是Mysql,对于Mysql的安装这里就不介绍,有什么不懂的请参考前面Mysql安装的文章。

1.在服务端安装bacula

首先在官网http://www.bacula.org下载源代码,这里下载的是bacula-5.2.6.tar.gz,接着进行编译安装。安装过程如下:

tar xvf bacula-5.2.6.tar.gz

cd bacula-5.2.6 && ./configure --prefix=/usr/local/bacula --with-mysql=/usr/local/mysql && make && make install

--with-mysql指的是Mysql的安装路径

2.在客户端安装bacula

由于客户端只是需要备份的客户端,因而只需要安装相应的客户端组件即可。

tar xvf bacula-5.2.6.tar.gz

cd bacula-5.2.6 && ./configure --prefix=/usr/local/bacula --enable-client-only && make && make install

3.在baculaServer上创建bacula对应的Mysql数据库以及访问数据库的授权

cd /usr/local/bacula/etc/
./grant_mysql_privileges
./create_mysql_database
./make_mysql_tables
三、配置bacula备份系统

根据上面的部署,将Director端、SD、Console集中在baculaServer(即192.168.1.200),而客户端FD部署在baculaClient(即192.168.1.222)服务器上。

Director端对应的配置文件为 bacula-dir.conf

SD端对应的配置文件为bacula-sd.conf

Console对应的配置文件为bconsole.conf

客户端FD对应的配置文件为bacula-fd.conf

1.配置baculaServer的Director端

bacula-dir.conf分为10个逻辑段,分别为:

  • Director      定义全局设置
  • Catalog       定义后台数据库
  • Jobdefs       定义默认执行任务
  • Job              自定义一个备份或恢复任务
  • FileSet        定义备份哪些数据,不备份哪些数据
  • Schedule     定义备份时间策略
  • Pool             定义供Job使用的池属性
  • Client          定义要备份的主机地址
  • Storage        定义数据的存储方式
  • Messages     定义发送日子报告和记录日志的位置

下面是已经配置好的bacula-dir.conf文件:

Director {                            # 定义bacula的全局变量
Name = linux8080-dir
DIRport = 9101                # 定义Director的监听端口
QueryFile = "/usr/local/bacula/etc/query.sql"
WorkingDirectory = "/usr/local/bacula/var/bacula/working"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 1        #定义一次能处理的最大并发数
Password = "wxYjKqQt9bhTtz2sAQXDgv/oo5FPlndPOwpABD185oOf"         # 这个密码必须与bconsole.conf文件中对应的Director逻辑端秘密相同
Messages = Daemon      #定义日志的输出方式
}

Job {                                                   #自定义一个备份任务
Name = "Client1"                           #备份任务名称
Client="dbfd"                                 #指定要备份的客户端主机,"dbfd"在后面的Client进行定义,对应name
Level=Incremental                        #增量备份,如果第一次没做完全备份,即先做完全备份再做增量备份
Type=Backup                                  #备份任务
FileSet=dbfs                                    #指定要备份的客户端数据。"dbfs"在后面的FileSet逻辑段进行定义
Schedule=dbscd                             #备份任务执行的时间策略。"dbscd"在后面Schedule逻辑段进行定义
Storage=dbsd                                  #指定备份数据的存储路径与介质,"dbsd"在后面的Storage逻辑段中进行定义
Messages=Standard
Pool=dbpool                                    #指定备份使用pool属性
Write Bootstrap="/usr/local/bacula/var/bacula/working/Client1.bsr"         #指定的备份的引导信息路径
}

Job {
Name = "BackupCatalog"            #定义一个名为BackupCatalog的完全备份任务
Type=Backup
Level = Full                                     #指定备份级别为完全备份
Client=dbfd
FileSet="dbfs"
Schedule = "dbscd"
Pool=dbpool
Storage=dbsd
Messages=Standard
# This creates an ASCII copy of the catalog
# Arguments to make_catalog_backup.pl are:
#  make_catalog_backup.pl <catalog-name>
RunBeforeJob = "/usr/local/bacula/etc/make_catalog_backup bacula bacula"
# This deletes the copy of the catalog
RunAfterJob  = "/usr/local/bacula/etc/delete_catalog_backup"
Write Bootstrap = "/usr/local/bacula/var/bacula/working/BackupCatalog.bsr"
#Priority = 11                   # run after main backup
}

Job {
Name="Client"                        #定义一个名为Client的差异备份任务
Type="Backup"
FileSet=dbfs
Storage=dbsd
Messages=Standard
Pool=dbpool
Client=dbfd
Level=Differential                   #指定备份级别为完全备份
Write Bootstrap = "/usr/local/bacula/var/bacula/working/Client.bsr"
}
Job {
Name = "RestoreFiles"           #定义一个名为RestoreFiles的还原任务
Type = Restore                         #还原
Client=dbfd
FileSet="dbfs"
Storage = dbsd
Pool = dbpool
Messages = Standard
Where = /tmp/bacula-restores
}

FileSet {                                   #定义一个名为"dbfs"的备份资源,指定哪些需要备份,哪些不需要备份
Name = "dbfs"
Include {
Options {
signature = MD5;Compression=GZIP          #表示使用MD5签名并压缩
}

File = /boot                      #指定客户端需要备份的文件目录
}

Exclude {                             #不需要备份的文件目录
File = /usr/local/bacula/var/bacula/working
File = /tmp
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}

Schedule {                              #定义一个名为WeeklyCycle的时间备份策略
Name = "WeeklyCycle"
Run = Full 1st sun at 23:05           #第一周的星期天 23:05分进行完全备份
Run = Differential 2nd-5th sun at 23:05      #第二到第五周23:05进行差异备份
Run = Incremental mon-sat at 23:05            #所有星期一至星期六23:05进行增量备份
}

Schedule {                         #定义一个名为dbscd的时间备份策略
Name = "dbscd"
Run = Full sun-sat at 23:10
}

FileSet {
Name = "Catalog"
Include {
Options {
signature = MD5
}
File = "/usr/local/bacula/var/bacula/working/bacula.sql"
}
}

Client {                                                #用来定义备份哪个客户端FD的数据
Name = dbfd                                   #Client的名称,可以在前面Job中调用
Address = 192.168.1.222               #baculaClient的IP地址
FDPort = 9102                                 #与客户端FD通信的端口
Catalog = MyCatalog                      #使用哪个数据库存储信息,在后面的MyCatalog逻辑段中进行定义
Password = "mLziHv6rYHmoPGKtpngD7zJQCGPOiGkURsPVxmVu6fLd"          # Director与客户端baculaClient中的FD的验证密码,这个值必须与FD端bacula-fd.conf中密码相同
File Retention = 30 days            # 30 days                        #保存在数据库中记录多久循环一次
Job Retention = 6 months            # six months
AutoPrune = yes                     # yes表示自动清除过期的Job
}
Client {
Name=dbfd1
Address=192.168.1.200
FDPort=9102
Catalog = MyCatalog
Password = "mLziHv6rYHmoPGKtpngD7zJQCGPOiGkURsPVxmVu6fLd"
File Retention = 30 days            # 30 days
Job Retention = 6 months            # six months
AutoPrune = yes
}

Storage {                                 #定义客户端的数据备份在哪个存储设备上
Name = dbsd
# Do not use "localhost" here
Address = 192.168.1.200                #指定存储端SD的IP地址
SDPort = 9103                                  #指定与SD的通信端口
Password = "R/8YRwB1/wITzKrSJ+tMZc8k4F2fX4LxxcpiXYq53yXN"          #这个值必须要存储端配置文件bacula-sd.conf中Director逻辑段密码相同
Device = dbdev                  #定义备份的存储介质,必须与bacula-sd.conf中"Device"逻辑段的name项相同
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 = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
operatorcommand = "/usr/local/bacula/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 = "/usr/local/bacula/var/bacula/working/bacula.log" = all, !skipped          #定义bacula的运行日志

append = "/usr/local/bacula/var/bacula/working/bacula.err.log" = error,warning,fatal     #定义bacula的错误日志
catalog = all
}

Messages {
Name = Daemon
mailcommand = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
mail = root@localhost = all, !skipped
console = all, !skipped, !saved
append = "/usr/local/bacula/var/bacula/working/log" = all, !skipped
}

Pool {                         #Job属性使用的池属性信息
Name = dbpool
Pool Type = Backup
Recycle = yes                       # 重复使用
AutoPrune = yes                     # 自动清除过期备份文件
Volume Retention = 365 days         # 备份文件的保留时间
}

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
}

Pool {
Name = Scratch
Pool Type = Backup
}

Console {
Name = linux8080-mon
Password = "g40HwA1uR7OswJt4fhBvrGYK3IvuKXe86kOc8r9/mknt"
CommandACL = status, .status
}

2.配置baculaServer的SD端

下面是一个已经配置好的bacula-sd.conf文件

Storage {                             # 定义存储,本例是linux8080-sd
Name = linux8080-sd
SDPort = 9103                  # Director's port
WorkingDirectory = "/usr/local/bacula/var/bacula/working"
Pid Directory = "/var/run"
Maximum Concurrent Jobs = 20
}

Director {
Name = linux8080-dir        #这里的name必须与Director端的bacula-dir.conf中Director逻辑段名称相同
Password = "R/8YRwB1/wITzKrSJ+tMZc8k4F2fX4LxxcpiXYq53yXN"    #必须与bacula-dir.conf中Storage逻辑段密码相同
}

Director {
Name = linux8080-mon            #定义一个监控端的Director
Password = "g40HwA1uR7OswJt4fhBvrGYK3IvuKXe86kOc8r9/mknt"   #必须与bacula-dir.conf中Console逻辑段密码相同
Monitor = yes
}

Device {             #定义Device
Name = dbdev   #dbdev这个名称在bacula-dir.conf中的Storage逻辑段Device项中被引用
Media Type = File        #使用文件系统存储
Archive Device = /bak_data            #备份的文件存储在/bak_data 目录下
LabelMedia = yes;                   # 通过lable建立卷文件
Random Access = Yes;            #是否随机访问存储介质,这里选择yes
AutomaticMount = yes;               #表示当设备打开时,是否自动使用它
RemovableMedia = no;
AlwaysOpen = no;
}

Messages {                        #为存储端SD定义一个日子或信息处理机制
Name = Standard
director = linux8080-dir = all
}

四、配置baculaClient的FD端

在baculaClient(192.168.1.222)配置FD端 ,下面是配置的bacula-fd.conf

Director {
Name = linux8080-dir            #name的值必须和Director端中bacula-dir.conf中Director逻辑段相同
Password = "mLziHv6rYHmoPGKtpngD7zJQCGPOiGkURsPVxmVu6fLd"   #这里的值必须和Director端bacula-dir.conf中Client逻辑段密码相同
}
Director {                  #定义一个允许连接FD的监控端
Name = linux8080-mon
Password = "g40HwA1uR7OswJt4fhBvrGYK3IvuKXe86kOc8r9/mknt"  这里的值必须和Director端baculir.conf中Console逻辑段密码相同
Monitor = yes
}

FileDaemon {                          # 定义一个FD端
Name = localhost.localdomain-fd
FDport = 9102                  # 监控端口
WorkingDirectory = /usr/local/bacula/var/bacula/working
Pid Directory = /var/run
Maximum Concurrent Jobs = 20
}
Messages {            #定义一个用于FD端的Messages
Name = Standard
director = localhost.localdomain-dir = all, !skipped, !restored
}

五、启动与关闭bacula

启动bacula服务之前要注意,要先启动Mysql,不然启动bacula连接数据库的时候就会报错

/usr/local/bacula/etc/bacula-ctl-dir {start|stop|restart|status}

/usr/local/bacula/etc/bacula-ctl-sd {start|stop|restart|status}

/usr/local/bacula/etc/bacula-ctl-fd {start|stop|restart|status}
①baculaServer启动bacula服务

/usr/local/bacula/etc/bacula-ctl-dir start
/usr/local/bacula/etc/bacula-ctl-sd start

[root@ etc]$ netstat -tunlp | grep 91
tcp        0      0 0.0.0.0:9101                0.0.0.0:*                   LISTEN      2511/bacula-dir
tcp        0      0 0.0.0.0:9103                0.0.0.0:*                   LISTEN      2538/bacula-sd

②baculaClient启动bacula服务

/usr/local/bacula/etc/bacula-ctl-fd start

六、bacula备份恢复过程

1.创建卷组,在baculaServe执行如下命令:

[root@ etc]$ /usr/local/bacula/etc/bconsole
Connecting to Director 192.168.1.200:9101
1000 OK: linux8080-dir Version: 5.2.6 (21 February 2012)
Enter a period to cancel a command.
*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: dbsd
Enter new Volume name: test1234
Defined Pools:
1: dbpool
2: File
3: Scratch
Select the Pool (1-3): 1
Connecting to Storage daemon dbsd at 192.168.1.200:9103 ...
Sending label command for Volume "test1234" Slot 0 ...
3000 OK label. VolBytes=199 DVD=0 Volume="test1234" Device="dbdev" (/bak_data)
Catalog record for Volume "test1234", Slot 0  successfully created.
Requesting to mount dbdev ...
3906 File device ""dbdev" (/bak_data)" is always mounted.

2.利用run执行备份操作

*run
A job name must be specified.
The defined Job resources are:
1: Client1
2: BackupCatalog
3: Client
4: RestoreFiles
Select Job resource (1-4): 1
Run Backup job
JobName:  Client1
Level:    Incremental
Client:   dbfd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2012-11-11 16:11:11
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=4
*status
Status available for:
1: Director
2: Storage
3: Client
4: All
Select daemon type for status (1-4): 1
linux8080-dir Version: 5.2.6 (21 February 2012) x86_64-unknown-linux-gnu redhat
Daemon started 11-Nov-12 00:54. Jobs: run=4, running=0 mode=0,0
Heap: heap=110,592 smbytes=79,187 max_bytes=198,499 bufs=254 max_bufs=287

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Full           Backup    10  11-Nov-12 23:10    Client1            rest
Full           Backup    10  11-Nov-12 23:10    BackupCatalog      rest
====

Running Jobs:
Console connected at 11-Nov-12 16:08
No Jobs running.
====

Terminated Jobs:
JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
1  Full         29    19.78 M  OK       11-Nov-12 00:58 Client1
2  Incr          0         0   OK       11-Nov-12 00:59 Client1
3               29    19.78 M  OK       11-Nov-12 01:14 RestoreFiles
4  Incr         28    19.78 M  OK       11-Nov-12 16:11 Client1

====

bacula的还原

在客户端192.168.1.222删除/boot文件

[root@localhost ~]# cd /boot/
[root@localhost boot]# rm -rf *
[root@localhost boot]# ls

在baculaSever端操作

*restore

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: dbfd
2: dbfd1
Select the Client (1-2): 1
Automatically selected FileSet: dbfs
+-------+-------+----------+------------+---------------------+------------+
| JobId | Level | JobFiles | JobBytes   | StartTime           | VolumeName |
+-------+-------+----------+------------+---------------------+------------+
|     1 | F     |       29 | 19,789,958 | 2012-11-11 00:58:41 | rest       |
|     4 | I     |       28 | 19,789,794 | 2012-11-11 16:11:16 | rest       |
+-------+-------+----------+------------+---------------------+------------+
You have selected the following JobIds: 1,4

Building directory tree for JobId(s) 1,4 ...
24 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: /
mark boot
29 files marked.
done   #确认操作
Bootstrap records written to /usr/local/bacula/var/bacula/working/linux8080-dir.restore.6.bsr

The job will require the following
Volume(s)                 Storage(s)                SD Device(s)
===========================================================================

rest                      dbsd                      dbdev

Volumes marked with "*" are online.

29 files selected to be restored.

Run Restore job
JobName:         RestoreFiles
Bootstrap:       /usr/local/bacula/var/bacula/working/linux8080-dir.restore.6.bsr
Where:           /tmp/bacula-restores
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd
Restore Client:  dbfd
Storage:         dbsd
When:            2012-11-11 16:38:40
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): mod      #默认的恢复路径是/tmp/bacula-restores,所以这里选择mod,把数据之间恢复到/boot下
Parameters to modify:
1: Level
2: Storage
3: Job
4: FileSet
5: Restore Client
6: When
7: Priority
8: Bootstrap
9: Where
10: File Relocation
11: Replace
12: JobId
13: Plugin Options
Select parameter to modify (1-13): 9
Please enter path prefix for restore (/ for none): /  

Run Restore job
JobName:         RestoreFiles
Bootstrap:       /usr/local/bacula/var/bacula/working/linux8080-dir.restore.6.bsr
Where:
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd
Restore Client:  dbfd
Storage:         dbsd
When:            2012-11-11 16:38:40
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=7

到此bacua的全量备份也完全恢复完成了,可以通过status查看还原状态


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值