Centos 6.3 x86_64安装与配置bacula

Centos 6.3 x86_64安装与配置bacula

一,简介
   Bacula是一款开源的跨平台的网络备份工具,基于c/s架构,通过它,管理员可以对数据进行备份,恢复,以及完整性验证等操作。
适合业务系统数据量巨大,每天都在迅速增长,还需要用以tar打包进行低级备份,并且没有相应的异地容灾策略,应该考虑bacula,bacula支持多种备份方式,还支持远程容灾备份。通过bacula,可以将数据备份到任意一个远程主机。用户只需要对bacula进行简单的设置即可自动完成数据备份。
二,工作原理
Bacula由下面5个部分组成
1,director daemon:负责监听所有的备份,恢复,验证,存档事务,以及定制备份和恢复文件计划等,将整个系统运行状况记录在一个数据库,支持mysql,postgresql,sqlite。配置文件bacula-dir.conf。监听端口9101
2,storage daemon (sd):在备份数据时,用来指定备份和恢复数据的存储介质,可以是本地磁盘,光纤磁盘阵列,磁带或dvd,恢复数据时将数据从存储介质中传送出去。配置文件:bacula-sd.conf 监听端口9103
3,file daemon(fd):是一个安装在需要备份数据的机器的上的守护进程,在备份数据时,它负责把文件传出,在恢复数据时,它负责接收数据并执行恢复操作。配置文件bacula-fd.conf
4,console:是一个管理控制台,用户可以通过这个控制台连接到director daemon进行管理备份与恢复操作。有三种方式,文本,gnone界面,wxwidgets界面。配置文件bconsole.conf
5,monitor:是一个进程监控端,负责监控director daemon,storage daemon和file daemon的守护进程。
三,工作流程

Centos 6.3 x86_64安装与配置bacula

1、通过console连接到Director端,备份恢复操作开始。
2、Director端从自己的数据库中调出记录信息,对存储端SD与客户端FD的任务进行协调。
3、客户端FD负责验证Director的操作许可,如果验证通过,则允许连接到存储端SD
4、客户端FD根据Director发出的请求去连接SD,将FD端的数据备份到存SD指定的存储介质上,或者将SD端存储介质中的数据传回到客户端FD指定的位置上,完成备份恢复过程。
5,各个组件配置文件之间的关联,在下面配置时可以对照此图配置。

Centos 6.3 x86_64安装与配置bacula

四,编译与安装bacula,在实际应用中并不会将五个部分分开安装。此次实验将dirctor ,sd,console安装在同一台机器,而客户端fd安装在另外一台机器,客户端可以有多台。

Centos 6.3 x86_64安装与配置bacula

1,在服务端
#yum -y install mysql mysql-server mysql-devel (mysql可以选择编译,这里采用yum安装)
#wget http://jaist.dl.sourceforge.net/project/bacula/bacula/5.2.13/bacula-5.2.13.tar.gz
#tar xf bacula-5.2.13.tar.gz
#cd bacula-5.2.13
#./configure --prefix=/usr/local/bacula --with-mysql (如果mysql是编译的则需要指定mysql安装的路径)
#make && make install
安装完了之后,需要创建bacula对应的mysql数据库心及访问数据库的授权。
#cd /usr/local/bacula
#./grant_mysql_privileges
#./create_mysql_database
#./make_mysql_tables
可以登录到mysql中查看bacula库的中表是否已经建立,上面三个脚本默认由空密码的root用户执行,因此需要确保mysql root的密码为空。
2,客户端
只是需要备份的客户端,因此只需要安装相应的客户端组件即可。
#cd bacula-5.2.13
#./configure --prefix=/usr/local/bacula --enable-client-only
#make && make install
五,配置服务器端
1,配置console端
#cd /usr/local/bacula
#vim etc/bconsole.conf
Director {
 Name = server-dir   控制端名称,在bacula-dir.conf和bacula-sd.conf文件中的director段都会被用到
 DIRport = 9101
 address = 192.168.1.28
 Password = "ZvLDkAPgWfJnre3+YDSDq6CAqyncBlTUklYspHtVAM/y"  控制端密码文件与bacula-dir中的director中的password要相同
}
2,配置director端
在bacula-dir.conf*有10个逻辑段
Director 定义全局设置
Jobdefs 定义执行任务的一些共同属性,可以让任务继承,如果有冲突则以job中的为准。
job 自定义一个备份或恢复的任务
Fileset 定义备份哪些数据,不备份哪些数据
Sehedule 定义备份时间策略
Client 定义需要被备份的主机地址,也就是客户端地址
Storage 定义数据的存储方式
Catalog 定义后台数据库
Message 定义发送日志报告和记录日志的位置
Pool 定义供job使用的池属性
下面是一个已经配置好的文件
Director {                            # define myself
 Name = server-dir
 DIRport = 9101                # where we listen for UA connections
 QueryFile = "/usr/local/bacula/etc/query.sql"
 WorkingDirectory = "/usr/local/bacula/opt/bacula/working"
 PidDirectory = "/var/run"
 Maximum Concurrent Jobs = 1
# Console password 控制密码,与bconsole.conf中的对应的director.conf的password相同
 Password = "ZvLDkAPgWfJnre3+YDSDq6CAqyncBlTUklYspHtVAM/y"        
 Messages = Daemon
}
#定义执行任务的一些默认属性,后面定义的job可以继承,但是如果有冲突以job中为准
JobDefs {
 Name = "DefaultJob"
 Type = Backup   #类型备份,还有restore,verify等值
 Level = Incremental  #备份级别,增量
 Client = server-fd  
 FileSet = "Full Set"
 Schedule = "WeeklyCycle" #备份策略,后面schedule有定义
 Storage = File  #备份数据的存储类型,
 Messages = Standard
 Pool = File   #指定备份使用的pool属性,file在后面的pool逻辑段中有定义
 Priority = 10
 Write Bootstrap = "/usr/local/bacula/opt/bacula/working/%c.bsr"  #指定备份的引导信息路径
}
#定义一个名为backupclient1的增量备份的任务,defaultJob中定义的是incremental
Job {
 Name = "BackupClient1"
 JobDefs = "DefaultJob"
}
#这个任务是新增的,后面实验需要有,不同的是级别为差异备份。
Job {
 Name = "BackupClient2"
# Client = server2-fd
 JobDefs = "DefaultJob"
 Level = Differential
}
Job {
 Name = "BackupCatalog"
 JobDefs = "DefaultJob"
 Level = Full
 FileSet="Catalog"
 Schedule = "WeeklyCycleAfterBackup"
 # 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.pl MyCatalog"
 # This deletes the copy of the catalog
 RunAfterJob  = "/usr/local/bacula/etc/delete_catalog_backup"
 Write Bootstrap = "/usr/local/bacula/opt/bacula/working/%n.bsr"
 Priority = 11                   # run after main backup
}
Job {
 Name = "RestoreFiles"
 Type = Restore
 Client=server-fd                
 FileSet="Full Set"                  
 Storage = File                      
 Pool = Default
 Messages = Standard
 Where = /tmp/bacula-restores #指定默认恢复数据到这个路径
}
FileSet {
 Name = "Full Set" #定义一个名为full set的备份资源,指定需要备份哪些数据。
 Include {
   Options {
     signature = MD5
   }
  # File = /usr/local/bacula/sbin
   File=/data  #指定需要备份的数据
 }
 Exclude {
#排除不需要备份的文件或者目录,可根据具体情况修改。
   File = /usr/local/bacula/opt/bacula/working
   File = /tmp
   File = /proc
   File = /tmp
   File = /.journal
   File = /.fsck
 }
}
Schedule {
 Name = "WeeklyCycle"  #定义一个名为weeklyclycle的备份策略
 Run = Full 1st sun at 23:05 #第一周的星期日晚完全备份
 Run = Differential 2nd-5th sun at 23:05 #第2-5周的星期日晚差异备份
 Run = Incremental mon-sat at 23:05 #所有星期一至星期六晚进行增量备份
}
Schedule {
 Name = "WeeklyCycleAfterBackup"  #定义一个WeeklyCycleAfterBackup备份策略
 Run = Full sun-sat at 23:10
}
FileSet {
 Name = "Catalog"
 Include {
   Options {
     signature = MD5
   }
   File = "/usr/local/bacula/opt/bacula/working/bacula.sql"
 }
}
Client {
 Name = server-fd
 Address = 192.168.1.29  #客户端IP
 FDPort = 9102
 Catalog = MyCatalog
 Password = "LJxLG+wlZoSaVtUoSZ121NhcobsgzZhAQgG5pPYyjqFL"          # password for FileDaemon
 File Retention = 30 days            # 30 days
 Job Retention = 6 months            # six months
 AutoPrune = yes                     # Prune expired Jobs/Files
}
#用来定义将客户端的数据备份到哪个存储设备上
Storage {
 Name = File
 Address = 192.168.1.28                # N.B. Use a fully qualified name here
 SDPort = 9103
#与bacula-sd.conf中director逻辑段密码相同
 Password = "cXEx51B0y1FLklJpvQ52RIi0+5wORQIwQ+6oWsB134RB"
 Device = FileStorage  #与bacula-sd.conf配置文件中的”device”逻辑段的”name”相同
 Media Type = File #指定存储介质的类型,必须与bacula-conf中的device逻辑段的”media type”相同
}
Catalog {
 Name = MyCatalog   #定义关于日志和数据库设定
 dbname = "bacula"; dbuser = "bacula"; dbpassword = ""
}
Messages {   #设置director端如何保存日志,以及日志的格式,可以将日志信息发送到管理员邮箱,前提是必须开启sendmail服务。
 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 = 304749970@qq.com = all, !skipped            
 operator = root@localhost = mount
 console = all, !skipped, !saved
 append = "/usr/local/bacula/opt/bacula/log/bacula.log" = all, !skipped
 catalog = all
}
Messages {
 Name = Daemon
 mailcommand = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
 mail = 304749970@qq.com = all, !skipped            
 console = all, !skipped, !saved
 append = "/usr/local/bacula/opt/bacula/log/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 {
 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 {  #限制console利用tray-monitor获得director的状态信息
 Name = server-mon
 Password = "EIOogja1xSbJxfPhwqUCl3c97HgX9Xzj54Nb1ofL+zH3"
 CommandACL = status, .status
}
3,配置sd,sd可以是一台单独的服务器,在此交实验中跟director在一台机器上。
Vim bacula.conf
Storage {                             # definition of myself
 Name = server-sd  
 SDPort = 9103                  # Director's port      
 WorkingDirectory = "/usr/local/bacula/opt/bacula/working"
 Pid Directory = "/var/run"
 Maximum Concurrent Jobs = 20
}
Director {
 Name = server-dir  #与bacula-dir.conf中的director中name需要相同,密码也需要相同
Password = "cXEx51B0y1FLklJpvQ52RIi0+5wORQIwQ+6oWsB134RB"
}
Director {
 Name = server-mon  #与bacula-dir.conf中的console中name需要相同,密码也是一样
 Password = "EIOogja1xSbJxfPhwqUCl3c97HgX9Xzj54Nb1ofL+zH3"
 Monitor = yes
}
Device {
 Name = FileStorage  #定义device,与bacula-dir.conf中storage段的device需要相同
 Media Type = File
 Archive Device = /tmp    #备份的数据存储的路径
 LabelMedia = yes;                   # lets Bacula label unlabeled media 通过label命令来建立卷文件
 Random Access = Yes;
 AutomaticMount = yes;               # when device opened, read it
 RemovableMedia = no;
 AlwaysOpen = no;
}
Messages {
 Name = Standard
 director = server-dir = all
}
六,配置客户端的fd
Vim bacula.conf
Director {
 Name = server-dir  #与bacula-dir.conf中的director中name需要相同,密码也需要相同
 Password =  "LJxLG+wlZoSaVtUoSZ121NhcobsgzZhAQgG5pPYyjqFL"
}
Director {
 Name = server-mon #与bacula-dir.conf中的console中name需要相同,密码也是一样
 Password = "EIOogja1xSbJxfPhwqUCl3c97HgX9Xzj54Nb1ofL+zH3"
 Monitor = yes
}
FileDaemon {                          # this is me
 Name = client-fd
 FDport = 9102                  # where we listen for the director
 WorkingDirectory = /usr/local/bacula/opt/bacula/working
 Pid Directory = /var/run
 Maximum Concurrent Jobs = 20
}
Messages {
 Name = Standard
 director = client-dir = all, !skipped, !restored
}
七,启动与关闭bacula
1,可用/usr/local/bacula/sbin/bacula start 启动所有服务
2,可以/usr/local/bacula/etc/下的各个组件的单独启动方式
#./bacula-ctl-dir
#./bacula-ctl-sd
./bacula-ctl-fd  由于将fd单独配置,需要可以不需要启动此服务
启动时需要先启动mysql,不然无法启动director daemon。
3,客户端也可以上面两种办法启动。
八,bacula备份过程
#/usr/local/bacula/sbin/bconsole
Connecting to Director 192.168.1.28:9101
1000 OK: server-dir Version: 5.2.13 (19 February 2013)
Enter a period to cancel a command.
*label  (作用其实就是建立备份文件名的作用)
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: File
Enter new Volume name: test
Defined Pools:
    1: Default
    2: File
    3: Scratch
Select the Pool (1-3): 1
Connecting to Storage daemon File at 192.168.1.28:9103 ...
Sending label command for Volume "test" Slot 0 ...
3000 OK label. VolBytes=192 DVD=0 Volume="test" Device="FileStorage" (/tmp)
Catalog record for Volume "test", Slot 0  successfully created.
Requesting to mount FileStorage ...
3906 File device ""FileStorage" (/tmp)" is always mounted.
You have messages.
*run
A job name must be specified.
The defined Job resources are:
    1: BackupClient1
    2: BackupClient2
    3: BackupCatalog
    4: RestoreFiles
Select Job resource (1-4): 1
Run Backup job
JobName:  BackupClient1
Level:    Incremental
Client:   server-fd
FileSet:  Full Set
Pool:     File (From Job resource)
Storage:  File (From Job resource)
When:     2013-04-17 01:07:36
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=17
*status
Status available for:
    1: Director
    2: Storage
    3: Client
    4: All
Select daemon type for status (1-4): 1  查看备份状态
server-dir Version: 5.2.13 (19 February 2013) x86_64-unknown-linux-gnu redhat
Daemon started 16-Apr-13 17:36. Jobs: run=13, running=0 mode=0,0
Heap: heap=278,528 smbytes=96,076 max_bytes=378,820 bufs=267 max_bufs=306
Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Incremental    Backup    10  17-Apr-13 23:05    BackupClient1      test
Incremental    Backup    10  17-Apr-13 23:05    BackupClient2      bingodegn
Full           Backup    11  17-Apr-13 23:10    BackupCatalog      bingodegn









本文转自 deng304749970 51CTO博客,原文链接:http://blog.51cto.com/damondeng/1180044,如需转载请自行联系原作者
上一篇:三十分钟学会AWK


下一篇:bbossgroups 3.1SQLExecutor组件api使用实例