Centos 6.3 部署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 或者 研究Bacula的朋友可以联系我,一起来深入了解这款备份工具!
1. Bacula 主控端安装
1.1. 介绍
本文档将介绍基于Centos 6.3系统平台的操作指南,试图让你使用简单指令快速从源程序安装Bacula。
如果你使用系统是Fedroa、Redhat或Centos 的其他Linux发行版,也可参照此文档。命令名、路径等可能因不同的发行包或操作系统而不同,因而这时你可能需要些努力来搞一下安装文档里的东西。
如果你使用的是其他Linux或者其他系统,或者希望了解更详细的说明,可以在官方维基百科( http://wiki.bacula.org)上找到。

注:本过程均架构在Centos6.3 其使用的Bacula版本问5.2.6。在文中深蓝色加粗字体均为注视,斜体为问题解决方式,红色加粗为我在操作中输入的部分。本文章出自www.itchenyi.com,允许转载,但请保留原文连接。
 
1.2. 准备软件包
在做安装之前确认要对该机器拥有root权限。
确认你安装好的系统上已经安装如下软件包再继续。
数据库使用Mysql
Mysql
GCC编译器
验证一下
[root@chenyi ~]# rpm -qa gcc gcc-c++ mysql mysql-devel mysql-server        #由于我用的一个mini版,所以都没有装
这里可以使用yum命令完成安装。
[root@chenyi ~]# mount /dev/cdrom /media          #挂载光盘
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@chenyi ~]# vi /etc/yum.repos.d/CentOS-Media.repo           #配置yum文件
[root@chenyi ~]# yum install gcc gcc-c++                          #安装gcc gcc-c++
[root@chenyi ~]# yum install mysql mysql-devel mysql-server        #安装mysql
 
1.3 现在最新版本 bacula  
可在Bacula站点( http://www.bacula.org/)获取最新版本
1.4.  部署操作过程
1.4.1.  下载源程序包
[chenyi@chenyi ~]$ su -l                           #切换为root用户
建立存储下载文件的目录,下载Bacula源程序,程序版本为5.2.6。
[root@chenyi ~]# mkdir /opt/bacula
[root@chenyi ~]# cd /opt/bacula
[root@chenyibacula]# wget http://nchc.dl.sourceforge.net/project/bacula/bacula/5.2.6/bacula-5.2.6.tar.gz
1.4.2. 编译并安装Bacula
解压缩Bacula源程序包
[root@chenyi bacula]# tar zxf bacula-5.2.6.tar.gz
[root@chenyi bacula]# cd bacula-5.2.6
设置环境变量,将$HOME设置为/usr/local
[root@chenyi bacula-5.2.6]# HOME=/usr/local/
[root@chenyi bacula-5.2.6]# CFLAGS="-g -Wall"
运行Bacula配置脚本,这里介绍下configure的常用参数,更详细的说明可查看官方文档。
-prefix=<patch>              #指定Bacula安装目录;
-sbindir=<binary-path>                  #指定可执行文件存放目录;
-sysconfdir=<config-path>            #指定配置文件存放目录;
-enable-smartalloc                          #强烈建议启用此选项。有助于检测内存泄漏;
-enable-bat                                    # 启用Bacula图形化管理工具BAT(Bacula Admin Tool)。依赖Qt4 >= 4.3.4,在开源站点Sourceforge的Bacula项目中下载此程序安装包(depkgs-qt)。Qt4必须在安装Bacula之前安装完 成。详细说明可查看官方文档Dependency Packages。 Bacua Client for Windows的版本中已包含此程序,安装简单而且很友好,界面及功能和Linux平台下的一样;
-enable-bwx-console              #启用基于wxWidgets的图像界面控制台。详细说明可查看官方文档Dependency Packages;
-enable-tray-monitor               #启用托盘监控工具。它需要不高于2.2版本的GNOME,不低于3.1版本的KDE,或者支持FreeDesktop系统托盘的任何标准窗口管理器;基于GTK >=2.10;
-enable-client-only                   #启用该选项表示只安装Bacula客户端;
with-sqlite3=<sqlite3-path>       #启用该选项表示Bacula使用SQLite3数据库。在开源站点Sourceforge的Bacula项目中可以下载SQLite3数据库安装包(depkgs),需要了解详细操作可查看官方文档Dependency Packages;
-with-mysql=<mysql-path>       #启用该选项表示Bacula使用MySQL数据库;
-with-postgresql=<path>           #启用该选项表示Bacula使用PostgreSQL数据库;
-enable-conio                              #这个地方水平不够,所以没能翻译过来,如有高手还望指点我一番,Tells Bacula to enable building the small, light weight readline replacement routine. It is generally much easier to configure than readline, although, like readline, it needs either the termcap or ncurses library;
-with-working-dir=<working-directory-path>     #此选项是强制的。指定Bacula运行时的文件存储目录;
-with-pid-dir=<PATH>                #指定Bacula进程ID文件存放目录。默认目录为/var/run。此目录必须手工建立;
-with-subsys-dir=<PATH>        指定Bacula运行时subsystem加锁文件存放目录。默认目录为/var/lock/subsys。此目录必须手工建立。
预配置
[root@chenyi bacula-5.2.6]# ./configure \
 --sbindir=$HOME/bacula/bin \
 --sysconfdir=$HOME/bacula/bin \
 --enable-smartalloc \
 --enable-tray-monitor \
 --with-mysql \
 --with-working-dir=$HOME/bacula/bin/working \
 --with-pid-dir=$HOME/bacula/bin/working \
 --with-subsys-dir=$HOME/bacula/bin/working \
 --enable-conio
以下为执行结果
安装Bacula之后相关的文件存储目录会按照此结果保存,可记录下来日后方便查询
Configuration on Thu Dec  6 09:19:24 CST 2012:
   Host:		     i686-pc-linux-gnu -- redhat 
   Bacula version:	     Bacula 5.2.6 (21 February 2012)
   Source code location:     .
   Install binaries:	     /usr/local//bacula/bin
   Install libraries:	     /usr/lib
   Install config files:     /usr/local//bacula/bin
   Scripts directory:	     /usr/local//bacula/bin
   Archive directory:	     /tmp
   Working directory:	     /usr/local//bacula/bin/working
   PID directory:	     /usr/local//bacula/bin/working
   Subsys directory:	     /usr/local//bacula/bin/working
   Man directory:	     ${datarootdir}/man
   Data directory:	     /usr/share
   Plugin directory:	     /usr/lib
   C Compiler:		     gcc 4.4.6
   C++ Compiler:	     /usr/bin/g++ 4.4.6
   Compiler flags:	      -g -O2 -Wall -fno-strict-aliasing -fno-exceptions -fno-rtti
   Linker flags:	      
   Libraries:		     -lpthread -ldl 
   Statically Linked Tools:  no
   Statically Linked FD:     no
   Statically Linked SD:     no
   Statically Linked DIR:    no
   Statically Linked CONS:   no
   Database backends:	     MySQL
   Database port:	      
   Database name:	     bacula
   Database user:	     bacula
   Job Output Email:	     root@localhost
   Traceback Email:	     root@localhost
   SMTP Host Address:	     localhost
   Director Port:	     9101
   File daemon Port:	     9102
   Storage daemon Port:      9103
   Director User:	     
   Director Group:	     
   Storage Daemon User:      
   Storage DaemonGroup:      
   File Daemon User:	     
   File Daemon Group:	     
   Large file support:	     yes
   Bacula conio support:     no 
   readline support:	     no 
   TCP Wrappers support:     no 
   TLS support: 	     yes
   Encryption support:	     yes
   ZLIB support:	     yes
   LZO support: 	     no
   enable-smartalloc:	     yes
   enable-lockmgr:	     no
   bat support: 	     no
   enable-gnome:	     no 
   enable-bwx-console:	     no 
   enable-tray-monitor:      yes
   client-only: 	     no
   build-dird:		     yes
   build-stored:	     yes
   Plugin support:	     yes
   ACL support: 	     no
   XATTR support:	     yes
   Python support:	     no 
   systemd support:	     no 
   Batch insert enabled:     MySQL
编译并安装Bacula
[root@chenyi bacula-5.2.6]# make
[root@chenyi bacula-5.2.6]# make install
[root@chenyi bacula-5.2.6]# make install-autostart     #添加自动启动守护进程
[root@chenyi bacula-5.2.6]# ls /etc/rc.d/init.d/ | grep bacula     #查看是否成功
bacula-dir
bacula-fd
bacula-sd
1.4.3.  建立 Bacula 用的数据库
启动MySQL并添加至随系统自动启动
[root@chenyi bacula-5.2.6]# service mysqld start
[root@chenyi bacula-5.2.6]# chkconfig --level 2345 mysqld on
进入Bacula可执行文件目录并建立数据库Bacula用户权限
[root@chenyi bacula-5.2.6]# cd src/cats/
[root@chenyi cats]# ./grant_mysql_privileges -p
Enter password: 
Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv  省略后面一部分
localhost	root		Y	Y	Y	Y	Y	Y	Y     0
chenyi	root		Y	Y	Y	Y	Y	Y	Y	Y     0
127.0.0.1	root		Y	Y	Y	Y	Y	Y	Y     0
localhost			N	N	N	N	N	N	N     0
chenyi			N	N	N	N	N	N	N	N     0
localhost	bacula		N	N	N	N	N	N	N     0
%	bacula		N	N	N	N	N	N	N	N     0
Privileges for user bacula granted on database bacula.
建立Bacula 数据库
[root@chenyi cats]# ./create_mysql_database -p
Enter password:
Creation of bacula database succeeded.
建立Bacula使用的表
[root@chenyi cats]# ./make_mysql_tables -p
Enter password:
Creation of Bacula MySQL tables succeeded.
到此,Bacula主控端就安装完成了,还需要对Bacula进行配置。
作为存储服务器兼控制台,现在需要依次对 bacula-dir.Conf(全局)  bacula.sd.conf(存储)和 bconsole.conf(控制台)配置文件进行修改。
1 配置 bacula Console
Director {
Name = chenyi-dir             #控制端名称,在下面的bacula-dir.conf和bacula-sd.conf文件中会陆续的被引用
DIRport = 9101                                             #控制端服务器端口
address = 192.168.1.220                          #控制端服务器IP
Password = "kl1h6gcOxkzFAWFUb1bl7bvtyiwW702QsypPHPgcuTdK" #控制端服务器密码文件
}
2 配置 bacula Director
         bacula-dir.conf 是Director 端的配置文件,也是bacula 的核心配置文件,这个文件非常复杂,共分为10 个逻辑段,分别是:
1、Director,定义全局设置
2、Catalog,定义后台数据库
3、Jobdefs,定义默认执行任务
4、Job,自定义一个备份或者恢复任务
5、Fileset,定义备份哪些数据,不备份哪些数据
6、Schedule,定义备份时间策略
7、Pool,定义供Job使用的池属性
8、Client,定义要备份的主机地址
9、Storage,定义数据的存储方式
10、Messages,定义发送日志报告和记录日志的位置
下图为dir的结构图:
下面为一个配置好的文件,其中#号后面的内容为注视。(其中部分地方Bacula有英文注释,恰好我英文也不咋滴)
Director {             #定义Bacula的全局配置       
Name = chenyi-dir
DIRport = 9101
QueryFile = "/usr/local//bacula/bin/query.sql"
WorkingDirectory = "/usr/local//bacula/bin/working"
PidDirectory = "/usr/local//bacula/bin/working"
Maximum Concurrent Jobs = 1         #定义一次能处理的最大并发数
 
         # 验证密码,这个密码必须与bconsole.conf文件中对应的Director逻辑段密码相同
Password = "kl1h6gcOxkzFAWFUb1bl7bvtyiwW702QsypPHPgcuTdK"
 
         #定义日志输出方式,“Daemon”在下面的Messages逻辑段中进行了定义
Messages = Daemon
}
JobDefs {
Name = "Client1"
Type = Backup
Level = Incremental
Client = dbfd                  # 如果本机也需备份就在后面去定义dbfd为本机
FileSet = "dbfs"
Schedule = "dbscd"
Storage = dbsd
Messages = Standard
Pool = dbpool
Priority = 10
Write Bootstrap = "/usr/local//bacula/bin/working/%c.bsr"
}
 
Job {                                               #自定义一个备份任务
Name = "wanquanbeifen"        #备份任务名称
Client = dbfd1                               #指定要备份的客户端主机,“dbfd”在后面Client逻辑段中进行定义
Level = Full                                   #定义备份的级别,Incremental为增量备份。Level的取值#可为Full(完全备份)、Incremental(增量备份)和Differential(差异备份),如果第一#次没做完全备份,则先进>行完全备份后再执行Incremental
Type = Backup                             #定义Job的类型,“backup”为备份任务,可选的类型还有restore和verify
FileSet = "dbfs"                           #指定要备份的客户端数据,“dbfs”在后面FileSet逻辑段中进行定义
Schedule = "dbscd"                     #指定这个备份任务的执行时间策略,“dbscd”在后面的Schedule逻辑段中行了定义
Storage = dbsd                            #指定备份数据的存储路径与介质,“dbsd在后面的Storage逻辑段中进行定
Messages = Standard
Pool = dbpool                     #指定备份使用的pool属性,“dbpool”在后面的Pool逻辑段中进行定义。
Write Bootstrap = "/usr/local//bacula/working/Client2.bsr" #指定备份的引导信息路径
}
Job {
Name = "Client1"
Client = dbfd
Level = Incremental
Type = Backup
FileSet = "dbfs"
Schedule = "dbscd"
Storage = dbsd
Messages = Standard
Pool = dbpool
Write Bootstrap = "/usr/local//bacula/working/Client2.bsr"
}
Job {                           #定义一个名为Client的差异备份的任务
Name = "Client"
Type = Backup
FileSet = "dbfs"
Schedule = "dbscd"
Storage = dbsd
Messages = Standard
Pool = dbpool
Client = dbfd
Level = Differential            #指定备份级别为差异备份
Write Bootstrap = "/usr/local//bacula/working/Client1.bsr"
}
Job {                                      #定义一个还原任务
Name = "RestoreFiles"
Type = Restore                  #定义Job的类型为“Restore ”,即恢复数据
Client=dbfd1
FileSet=dbfs
Storage = dbsd
Pool = dbpool
Messages = Standard
Where = /tmp/bacula-restores         #指定默认恢复数据到这个路径
}
 
FileSet {                                                    #定义一个名为dbfs的备份资源,也就是指定需要备份哪些数据,需要排除哪些数据等,可以指定多个FileSet
Name = "dbfs"
Include {
Options {
signature = MD5; Compression=GZIP; }          #表示使用MD5签名并压缩
File = /boot                                                               #指定客户端FD需要备份的文件目录
}
Exclude {                                                                    #通过Exclude排除不需要备份的文件或者目录,可根据具体情况修改
File = /usr/local//bacula/working
File = /tmp
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}
Schedule {                                                                  #定义一个名为dbscd的备份任务调度策略
Name = dbscd
Run = Full 1st sun at 23:05                                  #第一周的周日晚23:05分进行完全备份
Run = Differential 2nd-5th sun at 23:05          #第2~5周的周日晚23:05进行差异备份
Run = Incremental mon-sat at 23:05                #所有周一至周六晚23:05分进行增量备份
}
 
FileSet {
Name = "Catalog"
Include {
Options {
signature = MD5
}
File = /usr/local//bacula/bin/working/bacula.sql
}
}
 
Client {                                                             #Client用来定义备份哪个客户端FD的数据
Name = dbfd                                                 #Clinet 的名称,可以在前面的Job中调用
Address = 192.168.1.210                             #要备份的客户端FD主机的IP地址
FDPort = 9102                                                #与客户端FD通信的端口
Catalog = MyCatalog                                  #使用哪个数据库存储信息,“MyCatalog”在后面的MyCatalog逻辑段中进定义
Password = "XqJ0aC66ZHt3REH1sFj6wfnTZGdQSd8oqOv+W9cJ+zkh" #Director端与客户端FD的验证密码,这个值必须与客户端FD配置文件bacula-fd.conf中密码相同
File Retention = 30 days                             #指定保存在数据库中的记录多久循环一次,这里是30天,只影响数>据库中的记录不影响备份的文件
Job Retention = 6 months                            #指定Job的保持周期,应该大于File Retention指定的值
AutoPrune = yes                                            #当达到指定的保持周期时,是否自动删除数据库中的记录,yes表示自动清除>过期的Job
}
Client {
Name = dbfd1
Address = 192.168.1.210
FDPort = 9102
Catalog = MyCatalog
Password = "XqJ0aC66ZHt3REH1sFj6wfnTZGdQSd8oqOv+W9cJ+zkh2"
File Retention = 30 days
Job Retention = 6 months
AutoPrune = yes
}
 
Storage {                                                # Storage用来定义将客户端的数据备份到哪个存储设备上
Name = dbsd
Address = 192.168.1.220                  #指定存储端SD的IP地址
SDPort = 9103                                     #指定存储端SD通信的端口
Password = "U1NXyNwriNYIH7SulVmKp/uGTYiy2C5OY7wnSqkz2voU" #Director端与存储端SD的验证密码,这个值必须与存储端SD配置文件bacula-sd.conf中Director逻辑段密码相同
Device = FileStorage                           #指定数据备份的存储介质,必须与存储端(这里是192.168.1.220)的bacula-sd.conf配置文件中的“Device逻辑段的“Name”项名称相同
Media Type = File                                 #指定存储介质的类别,必须与存储端SD(这里是192.168.1.220)的bacula-sd.conf配置文件中的“Device逻辑段的“Media Type”项名称相同
}
Catalog {                                               # Catalog逻辑段用来定义关于日志和数据库设定
Name = MyCatalog
dbname = "bacula"; dbuser = "bacula"; dbpassword = "" #指定库名、用户名和密码
}
 
Messages {                                          # Messages 逻辑段用来设定Director端如何保存日志,以及日志的保存格式,可以将日志信息发送到管理员邮箱,前提是必须开启sendmail服务
Name = Standard
mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
operatorcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
mail = [email protected] = all, !skipped
operator = [email protected] = mount
console = all, !skipped, !saved
append = "/usr/local//bacula/bin/working/log" = all, !skipped #定义bacula的运行日志
append ="/usr/local//bacula/log/bacula.err.log" = error,warning, fatal #定义bacula的>错误日志
catalog = all
}
Messages {                                          #定义了一个名为Daemon的Messages逻辑段,“Daemon”已经在前面进行了引用
Name = Daemon
mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
mail = [email protected] = all, !skipped
console = all, !skipped, !saved
append = "/usr/local//bacula/log/bacula_demo.log" = all, !skipped
}
 
Pool {                                                      #定义供Job任务使用的池属性信息,例如,设定备份文件过期时间、是否覆盖过期的备份数据、是否自动清除过期备份等
Name = dbpool
Pool Type = Backup
Recycle = yes                                       #重复使用
AutoPrune = yes                                    #表示自动清除过期备份文件
Volume Retention = 7 days               #指定备份文件保留的时间
Label Format ="db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}" #设定备份文件的
命名格式,这个设定格式会产生的命名文件为:db-2013-01-27-xxx
Maximum Volumes = 7                      #设置最多保存多少个备份文件
Recycle Current Volume = yes        # 表示可以使用最近过期的备份文件来存储新备份
Maximum Volume Jobs = 1              #表示每次执行备份任务创建一个备份文件
}
 
Console {                                                #限定Console利用tray-monitor获得Director的状态信息
Name = chenyi-mon
Password = "/I9QK/9tvB63eOHT2TGJuO7KMzOkrNGi8UtOMGq9LHga"
CommandACL = status, .status
}
3 配置 bacula SD
         SD可以是一台单独的服务器,也可以和Director在一台机器上,本例就将SD和Director端放在一起进行配置,SD的配置文件是bacula-sd.conf
 
Storage {                         #定义存储,本例中是chenyi-sd
Name = chenyi-sd               #定义存储名称
SDPort = 9103                   #监听端口    
WorkingDirectory = "/usr/local//bacula/bin/working"
Pid Directory = "/usr/local//bacula/bin/working"
Maximum Concurrent Jobs = 20
}
 
Director {                        # 定义一个控制StorageDaemon的Director
Name = chenyi-dir                    #这里的“Name”值必须和Director端配置文件bacula-dironf中Director逻辑段名称相同
Password = "U1NXyNwriNYIH7SulVmKp/uGTYiy2C5OY7wnSqkz2voU"     #这里的“Password”值须和Director端配置文件bacula-dir.conf中Storage逻辑段密码相同
}
 
Director {                         #定义一个监控端的Director
Name = chenyi-mon           #这里的“Name”值必须和Director端配置文件bacula-diconf中Console逻辑段名称相同
Password = "/I9QK/9tvB63eOHT2TGJuO7KMzOkrNGi8UtOMGq9LHga"  #这里的“Password”值必和Director端配置文件bacula-dir.conf中Console逻辑段密码相同
Monitor = yes
}
Device {                               #定义Device
Name = FileStorage                   #定义Device的名称,这个名称在Director端配置文件bacula-dir.conf中的Storage逻辑段Device项中被引用
Media Type = File                   #指定存储介质的类型,File表示使用文件系统存储
Archive Device = /tmp/backup         #Archive Device用来指定备份存储的介质,可以是cd、dvd、tap等,这里是将备份的文件保存的/tmp/backup目录下
LabelMedia = yes;                    #通过Label命令来建立卷文件
Random Access = Yes;                #设置是否采用随机访问存储介质,这里选择yes
AutomaticMount = yes;               #表示当存储设备打开时,是否自动使用它,这选择yes
RemovableMedia = no;                #是否支持可移动的设备,如tap或cd,这里选择no
AlwaysOpen = no;                    #是否确保tap设备总是可用,这里没有使用tap设备,因此设置为no
}
 
Messages {                                                          #为存储端SD定义一个日志或消息处理机制
Name = Standard
director = chenyi-dir = all
}
到这里,Bacula的主控端大致就配置完毕了,接下来就要启动Bacula的进程了[本文出自www.itchenyi.com 允许转载,但你必须保留原文链接]
启动Bacula 进程
[root@chenyi bin]# ./bacula start
Starting the Bacula Storage daemon
Starting the Bacula File daemon
Starting the Bacula Director daemon
终于配置完毕,但还有关键的一步,添加存储介质
[root@chenyi bin]# ./bconsole
Connecting to Director 192.168.1.220:9101
1000 OK: chenyi-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: File
Enter new Volume name: backup
Defined Pools:
1: Default
2: File
3: Scratch
Select the Pool (1-3): 1
Connecting to Storage daemon File at 192.168.1.220:9103 ...
Sending label command for Volume "backup" Slot 0 ...
3000 OK label. VolBytes=193 DVD=0 Volume="backup" Device="FileStorage" (/tmp/backup)
Catalog record for Volume "backup", Slot 0  successfully created.
Requesting to mount FileStorage ...
3906 File device ""FileStorage" (/tmp/backup)" is always mounted.
*
配置客户机(为需要备份的 Client
1. 编译安装 Bacula
设置环境变量,将$HOME设置为/usr/local
[root@chenyi bacula-5.2.6]# HOME=/usr/local/
[root@chenyi bacula-5.2.6]# CFLAGS="-g -Wall"
运行Bacula配置脚本。关于configure选项已经在<安装Bacula主控端>部分做了介绍,这里不再做说明。以下是个范例:
[root@chenyi ~]# tar zxf bacula-5.2.6.tar.gz
[root@chenyi ~]# cd bacula-5.2.6
预配置
[root@chenyi bacula-5.2.6]# ./configure --prefix=/usr/local/bacula/ --enable-client-only
以下是执行结果:
Configuration on Thu Dec  6 10:23:35 CST 2012:
   Host:                     i686-pc-linux-gnu -- redhat
   Bacula version:           Bacula 5.2.6 (21 February 2012)
   Source code location:     .
   Install binaries:         /usr/local/bacula/sbin
   Install libraries:        /usr/local/bacula/lib
   Install config files:     /usr/local/bacula/etc
   Scripts directory:        /usr/local/bacula/etc
   Archive directory:        /tmp
   Working directory:        /usr/local/bacula/var/bacula/working
   PID directory:            /var/run
   Subsys directory:         /var/lock/subsys
   Man directory:            ${datarootdir}/man
   Data directory:           /usr/local/bacula/share
   Plugin directory:         /usr/local/bacula/lib
   C Compiler:               gcc 4.4.6
   C++ Compiler:             /usr/bin/g++ 4.4.6
   Compiler flags:            -g -O2 -Wall -fno-strict-aliasing -fno-exceptions -fno-rtti
   Linker flags:
   Libraries:                -lpthread -ldl
   Statically Linked Tools:  no
   Statically Linked FD:     no
   Statically Linked SD:     no
   Statically Linked DIR:    no
   Statically Linked CONS:   no
   Database backends:        None
   Database port:
   Database name:            bacula
   Database user:            bacula
   Job Output Email:         root@localhost
   Traceback Email:          root@localhost
   SMTP Host Address:        localhost
   Director Port:            9101
   File daemon Port:         9102
   Storage daemon Port:      9103
   Director User:
   Director Group:
   Storage Daemon User:
   Storage DaemonGroup:
   File Daemon User:
   File Daemon Group:
   Large file support:       yes
   Bacula conio support:     no
   readline support:         no
   TCP Wrappers support:     no
   TLS support:              yes
   Encryption support:       yes
   ZLIB support:             yes
   LZO support:              no
   enable-smartalloc:        yes
   enable-lockmgr:           no
   bat support:              no
   enable-gnome:             no
   enable-bwx-console:       no
   enable-tray-monitor:      no
   client-only:              yes
   build-dird:               yes
   build-stored:             yes
   Plugin support:           yes
   ACL support:              no
   XATTR support:            yes
   Python support:           no
   systemd support:          no
   Batch insert enabled:     None
编译并安装Bacula
[root@chenyi bacula-5.2.6]# make
你可能在make的过程中出现 libtool: link: cannot find the library `/lib/libattr.la' or unhandled argument `/lib/libattr.la' 错误,可以可以通过创建/usr/lib/libattr.la的软连接,解决此故障。
ln -s /usr/lib/libattr.la /lib/libattr.la
[root@chenyi bacula-5.2.6]# make install
[root@chenyi bacula-5.2.6]# make install-autostart-fd              #添加自动启动守护进程
[root@chenyi bacula-5.2.6]# ls /etc/rc.d/init.d/ | grep bacula    #验证结果
bacula-fd
到此,Centos系统的客户端就安装完成了,还需要对Bacula-fd进行配置之后再启动Bacula。
Director {               #定义一个允许连接FD的控制端
Name = chenyi-dir     #这里的“Name”值必须和Director端配置文件bacula-dir.conf
Director逻辑段名称相同
Password = "XqJ0aC66ZHt3REH1sFj6wfnTZGdQSd8oqOv+W9cJ+zkh2"    #这里的“Password”值必须和Director端配置文件bacula-dir.conf中Client逻辑段密码相同
}
 
Director {              #定义一个允许连接FD的监控端
Name = chenyi.2-mon   #chenyi.2-mon
Password = "xjcWMuoZPw68Vrs//P9BsbLME6lh4mtOFYwhTxZPmNUe"
Monitor = yes
}
 
FileDaemon {                     #定义一个允许连接FD的监控端
Name = chenyi.2-fd
FDport = 9102                  #监控端口
WorkingDirectory = /usr/local/bacula/var/bacula/working
Pid Directory = /var/run
Maximum Concurrent Jobs = 20   #定义一次能处理的并发作业数
}
 
Messages {                       #定义一个用于FD端的Messages
Name = Standard
director = chenyi.2-dir = all, !skipped, !restored
客户端配置相对来说较简单,只需改这个文件即可
[root@chenyi bin]# ./bacula start      #启动进程
Starting the Bacula File daemon
验证在server上
[root@chenyi bin]# ./bconsole
Connecting to Director 192.168.1.220:9101
1000 OK: chenyi-dir Version: 5.2.6 (21 February 2012)
Enter a period to cancel a command.
* run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
1: wanquanbeifen
2: Client1
3: Client
4: RestoreFiles

Select Job resource (1-4): 1
Run Backup job
JobName:  wanquanbeifen
Level:    Full
Client:   dbfd1
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2013-01-27 19:20:41
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=14
* status
Status available for:
1: Director
2: Storage
3: Client
4: All
Select daemon type for status (1-4): 3
The defined Client resources are:
1: dbfd
2: dbfd1
Select Client (File daemon) resource (1-2): 2
Connecting to Client dbfd1 at 192.168.1.210:9102
 
chenyi.2-fd Version: 5.2.6 (21 February 2012)  i686-pc-linux-gnu redhat
Daemon started 27- 1��013 19:14. Jobs: run=1 running=0.
Heap: heap=0 smbytes=90,848 max_bytes=171,749 bufs=60 max_bufs=109
Sizeof: boffset_t=8 size_t=4 debug=0 trace=0
Running Jobs:
Director connected at: 27- 1��013 19:20
No Jobs running.
====
Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name 
======================================================================
    14  Full         29    19.20 M  OK       27- 1��013 19:20 wanquanbeifen
====
You have messages.
*
此时ls 查看之前定义的备份路径
[root@chenyi bin]# ls -lh /tmp/backup/
总用量 19M
-rw-r-----. 1 root root 193 12月  6 10:08 backup
-rw-r-----. 1 root root 19M 1月  27 19:20 db-2013-01-27-id14
接下来开始尝试还原,首先删除Client上Boot中的所有文件。

此时回到Server上(操作控制台) 下面用红色加粗的命令均为我输入的命令,
[root@chenyi bin]# ./bconsole
Connecting to Director 192.168.1.220:9101
1000 OK: chenyi-dir Version: 5.2.6 (21 February 2012)
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: chenyi-fd
2: dbfd
3: dbfd1
Select the Client (1-3): 3
Automatically selected FileSet: dbfs
+-------+-------+----------+------------+---------------------+--------------------+
| JobId | Level | JobFiles | JobBytes   | StartTime           | VolumeName         |
+-------+-------+----------+------------+---------------------+--------------------+
|    14 | F     |       29 | 19,207,422 | 2013-01-27 19:20:46 | db-2013-01-27-id14 |
+-------+-------+----------+------------+---------------------+--------------------+
 
You have selected the following JobId: 14
 
Building directory tree for JobId(s) 14 ...
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/bin/working/chenyi-dir.restore.1.bsr
 
The job will require the following
Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
db-2013-01-27-id14        dbsd                      FileStorage
 
Volumes marked with "*" are online.
29 files selected to be restored.
 
Run Restore job
JobName:         RestoreFiles
Bootstrap:       /usr/local//bacula/bin/working/chenyi-dir.restore.1.bsr
Where:           /tmp/bacula-restores
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd1
Restore Client:  dbfd1
Storage:         dbsd
When:            2013-01-27 19:31:28
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): mod                 #这个地方注意一下,如果要还原到client原位置则按以下步骤
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/bin/working/chenyi-dir.restore.1.bsr
Where:
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd1
Restore Client:  dbfd1
Storage:         dbsd
When:            2013-01-27 19:31:28
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=15
*
现在再看看咱们client,方才删除的文件全部回来了(表示体验过程中觉得该工具的备份还原速度都很理想)

到这里,从部署到备份再到还原整个过程就完了~~~~~
 

你可能感兴趣的:(centos,bacula,备份还原,IT辰逸)