BACULA安装
Bacula是一款开源的跨平台网络备份工具,提供基于企业级的CS的备份解决方案。可以对数据进行备份、恢复、以及完整性校验。
功能特点
支持多种恢复方式
支持多种文件系统下的备份恢复(ext3、ext2、reiserfs、xfs、jfs、smbfs、iso9660、ntfs等)
支持各种备份介质
支持多种操作系统
强大的内部功能
组成部分
一个完整的bacula备份系统,由下面5个部分组成
Director Daemon:负责监听所有的备份、恢复、验证、存档事务,以及定制备份和恢复文件计划等,并将整个系统运行状况记录在一个数据库文件中。其配置文件为bacula-dir.conf。
Storage Daemon(SD):主要负责将数据备份到存储介质上,而在数据恢复时,负责将数据从存储介质中传送出去。其配置文件为bacula-sd.conf。
File Daemon(FD):安装在需要备份数据的机器上的守护进程,在备份数据时,它负责把文件传出,在恢复数据时负责接收数据并执行恢复操作。配置文件为bacula-fd.conf。
Console:管理控制台。可以通过这个控制台连接到Director Daemon进行管理备份与恢复操作。
Monitor:进程监控端。
工作流程
1、通过console连接到Director端,备份恢复操作开始。
2、Director端从自己的数据库中调出记录信息,对存储端SD与客户端FD的任务进行协调。
3、客户端FD负责验证Director的操作许可,如果验证通过,则允许连接到存储端SD
4、客户端FD根据Director发出的请求去连接SD,将FD端的数据备份到存SD指定的存储介质上,或者将SD端存储介质中的数据传回到客户端FD指定的位置上,完成备份恢复过程。
以上是bacula简介均属百度百科摘抄。
拓扑流程图:
其实bacula这5个核心组件不必分别装在不同的机器上,笔者这儿就直接使用2台云主机模拟服务流程:
1.京东云主机:server [ console director mysql monitor SD ]
2.阿里云主机:client [ FD ]
[root@JD ~]# uname -r
3.10.0-514.el7.x86_64
需要安装数据库
yum install mariadb* -y
在Client和Server端下载解压预编译包
[root@JD src]# pwd /usr/local/src [root@JD src]# tar -zvxf bacula-5.2.13.tar.gz [root@JD src]# cd bacula-5.2.13
Client主机上:
[root@Aliyun bacula-5.2.13]# ./configure --prefix=/usr/local/bacula --enable-client-only [root@Aliyun bacula-5.2.13]# make [root@Aliyun bacula-5.2.13]# make install [root@Aliyun bacula-5.2.13]# cd /usr/local/bacula/etc/
[root@Aliyun etc]# egrep -v ‘^#|^$‘ bacula-fd.conf Director {##定义连接客户端FD的控制端 Name = JD-dir Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" ##名字和密码是用来验证Server控制端的连接操作是否合法,需要与Server端的bacula-dir.conf中的Director一致. } Director {##定义允许连接客户端FD的监控段 Name = JD-mon Password = "JMRJc5OtI7eqz+Fh3mbe6yQJig6R6wwTftuWX7+bXUAx" ##一样是验证,这是验证server端监控本地进程是否合法 Monitor = yes##开启监控 } FileDaemon { ##定义客户端的FD Name = xad-fd FDport = 9102 #默认监听端口 WorkingDirectory = /usr/local/bacula/opt/bacula/working Pid Directory = /var/run Maximum Concurrent Jobs = 20##一次能处理的并发作业数 } Messages { Name = Standard director = xad-dir = all, !skipped, !restored }
Server主机上:
[root@JD bacula-5.2.13]# ./configure --prefix=/usr/local/bacula --with-mysql #需开启数据库 [root@JD bacula-5.2.13]# make [root@JD bacula-5.2.13]# make install
设置数据库和创建库和表
[root@JD bacula-5.2.13]# cd /usr/local/bacula/etc/ 执行以下三个文件,默认以数据库root用户且密码为空进行,倘若root有密码,则同时修改这三个文件中连接数据库的代码段: ...... if mysql -D ${db_name} $* -u root -p00000000 -f <<END-OF-DATA #添加红色部分,-p后为root密码 ...... [root@JD etc]# ./grant_mysql_privileges ##开启远程连接 [root@JD etc]#./create_mysql_database ##创建数据库 [root@JD etc]#./make_mysql_tables ##创建数据表 进入mysql并查看是否有相关的数据信息 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bacula | | mysql | | performance_schema | | test | | xad | +--------------------+ 6 rows in set (0.00 sec)
Console端配置
[root@JD etc]# egrep -v ‘^#|^$‘ bconsole.conf##编辑console端配置文件 Director { Name = JD-dir##Director端名称 DIRport = 9101##console默认端口 address = Dir-IP##Director端地址 Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" ##与Director端验证是的密码,需与Director端一致 }
控制端配置文件共有10个逻辑段:
Director{...} 定义全局设置
Jobdefs{...} 定义默认执行任务
Job{...} 自定义一个备份或者恢复任务
Client{...} 定义要备份的主机地址
Fileset{...} 定义备份哪些数据,不备份哪些数据
Schedule{...} 定义备份时间策略
Storage{...} 定义数据的存储方式
Pool{...} 定义供Job使用的池属性
Catalog{...} 定义后台数据库
Messages{...} 定义发送日志报告和记录日志的位置
[root@JD etc]# egrep -v ‘^#|^$‘ bacula-dir.conf Director { #定义全局配置 Name = JD-dir DIRport = 9101 # 默认端口 QueryFile = "/usr/local/bacula/etc/query.sql" WorkingDirectory = "/usr/local/bacula/opt/bacula/working" PidDirectory = "/var/run" Maximum Concurrent Jobs = 1##一次能处理的最大并发数 Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" # 与Console验证的验证 password需一致 Messages = Daemon##发送消息通知方式 } JobDefs {##定义默认执行任务 Name = "DefaultJob" Type = Backup##任务类型默认为备份,可选restore和verify Level = Incremental ##备份类型:Full(完全备份)、Incremental(增量备份)和Differential(差异备份) ##如果第一次没做完全备份,则先进行完全备份后再执行Incremental Client = xad-fd##与客户端主机FD配置文件中一致 FileSet = "Full Set"##指定需要备份的数据策略,下文定义 Schedule = "WeeklyCycle"##指定这个备份任务的执行时间策略,下文定义 Storage = File###指定备份数据的存储路径与介质,下文定义 Messages = Standard Pool = File##指定备份使用的pool属性,下文定义 Priority = 10 Write Bootstrap = "/usr/local/bacula/opt/bacula/working/%c.bsr" #指定备份的引导信息 } Job { Name = "BackupClient1" JobDefs = "DefaultJob" } 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=xad-fd FileSet="Full Set" Storage = File Pool = Default Messages = Standard Where = /tmp/bacula-restores } FileSet {##定义需要的备份数据 Name = "Full Set" Include { Options { signature = MD5 } File = /usr/local/src##需要备份的数据的路径 } Exclude { File = /usr/local/bacula/opt/bacula/working File = /tmp File = /proc File = /tmp File = /.journal File = /.fsck } } 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 = "/usr/local/bacula/opt/bacula/working/bacula.sql" } } Client {##定义客户端 Name = xad-fd Address = IP-Client##客户端地址 FDPort = 9102##客户端端口 Catalog = MyCatalog##数据库存储信息方式 Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" ##与客户端一致 File Retention = 30 days # 数据循环时间,非备份文件存储时间 Job Retention = 6 months # 定义任务保持周期 AutoPrune = yes # 任务超过保持周期是否自动删除 } Storage {##定义存储设备 Name = File Address = IP-SD # 存储设备服务SD的地址 SDPort = 9103 # 存储设备通信端口 Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" ##需与SD端配置一致 Device = FileStorage # 定义存储介质类型,需与SD端配置一致 Media Type = File # 介质类别,需与SD端配置一致 } Catalog {##定义日志和数据设定 Name = MyCatalog dbname = "bacula"; dbuser = "root"; dbpassword = "00000000"##库名和密码 } 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/opt/bacula/log/bacula.log" = all, !skipped ##bacual运行日志 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/opt/bacula/log/bacula.log" = all, !skipped } Pool { Name = Default##定义池属性 Pool Type = Backup Recycle = yes #重复使用 AutoPrune = yes #自动清除过期备份文件 Volume Retention = 365 days # 备份文件保留时间 } Pool { Name = File Pool Type = Backup Recycle = yes AutoPrune = yes Volume Retention = 365 days Maximum Volume Bytes = 50G # 最大备份文件的大小限制 Maximum Volumes = 100 # 备份文件个数最大限制 } Pool { Name = Scratch Pool Type = Backup } Console {##定义console Name = JD-mon Password = "JMRJc5OtI7eqz+Fh3mbe6yQJig6R6wwTftuWX7+bXUAx" ##需与console一致 CommandACL = status, .status }
SD配置文件
[root@JD etc]# egrep -v ‘^#|^$‘ bacula-sd.conf Storage { # 定义存储 Name = JD-sd SDPort = 9103 WorkingDirectory = "/usr/local/bacula/opt/bacula/working" Pid Directory = "/var/run" Maximum Concurrent Jobs = 20 } Director {##控制端信息 Name = JD-dir Password = "dc5XEaySjV90PBfM0wCChirlEYkH4feUXjesKNHxdU2X" } Director {##监控端monitor信息 Name = JD-mon Password = "JMRJc5OtI7eqz+Fh3mbe6yQJig6R6wwTftuWX7+bXUAx" Monitor = yes } Device {##定义设备介质 Name = FileStorage Media Type = File Archive Device = /tmp##存储位置 LabelMedia = yes; # 通过label命令建立卷文件 Random Access = Yes;#随机访问 AutomaticMount = yes; #自动挂载使用 RemovableMedia = no;#支持可移动设备 AlwaysOpen = no; } Messages { Name = Standard director = JD-dir = all }
启动方式
Server端:
[root@JD etc]#/usr/local/bacula/etc/bacula-ctl-dir start [root@JD etc]#/usr/local/bacula/etc/bacula-ctl-sd start [root@JD ~]# netstat -tunlp | grep 910 tcp 0 0 0.0.0.0:9101 0.0.0.0:* LISTEN 26967/bacula-dir tcp 0 0 0.0.0.0:9103 0.0.0.0:* LISTEN 27002/bacula-sd
Client端:
[root@Aliyun etc]# /usr/local/bacula/etc/bacula-ctl-fd start [root@Aliyun ~]# netstat -tunlp | grep 910 tcp 0 0 0.0.0.0:9102 0.0.0.0:* LISTEN 22685/bacula-fd
本文出自 “TOP-ONE” 博客,请务必保留此出处http://onenice.blog.51cto.com/13201315/1967735
原文地址:http://onenice.blog.51cto.com/13201315/1967735