您的位置:首页 > 理论基础 > 计算机网络

bacula 网络备份

2012-03-24 17:28 190 查看
bacula 的工作原理

一个完整的bacula备份系统由5个部分组成

Director Daemon

负责监听所有备份,恢复,验证,存档事务,以及定制备份和恢复文件计划等,并将整个系统运行状态,记录在一个数据库中,

storage Daemon

在备份数据时用来指定备份和恢复数据的存储介质

file Daemon

一个安装在需要备份数据的机器上的守护进程,在备份数据时候她负责把文件传出,在恢复数据时,她负责接手数据并且恢复操作,配置文件为bacula-fd.conf

console

一个管理控制台,用户可以通过这个控制台连接到director daemon上进行管理备份,与恢复操作,有3种管理方式基于文本的控制台界面,gnome的界面和wxwidgets的图形界面,其配置文件是bconsole.conf

Monitor

一个进程监控端,负责监控director daemon ,storage daemon 和file Daemon 的守护进程

bacula的几种网络拓扑

1:director与SD以及console在一台机器上,客户端fd在另外一台机器上,或者多台机器上

2:director与console在一台机器上,sd在一台机器上,客户端fd在另外一台机器上或者多台机器上

3:diretcor fd ,sd ,console都在一台机器上,相当于自己备份自己的数据

编译安装bacula

环境

baculaserver 192.168.3.128

baculaclient 192.168.3.129

1)

在128上安装baculaserver

wget http://sourceforge.net/projects/bacula/files/bacula/5.0.2/bacula-5.0.2.tar.gz/download
tar -xf bacula-5.0.2.tar.gz

cd bacula-5.0.2

./configure --prefix=/opt/ --with-mysql

如果提示找不到mysql.h安装mysqldevel包

make

make install

2)

在129上安装baculaclient

6 tar -xf bacula-5.0.2.tar.gz

7 cd bacula-5.0.2

8 ls

9 ./configure --prefix=/opt/ --enable-client-only

10 make

11 make install

3)

初始化mysql数据库,穿件bacula对应的mysql数据库以及访问数据库权限,bacula准备了相应的脚本

./grant_mysql_privileges

./create_mysql_database

./make_mysql_tables

!!!!!!!

默认mysql的root密码为空,请确保

mysql上验证

use bacula;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables

-> ;

+------------------+

| Tables_in_bacula |

+------------------+

| BaseFiles |

| CDImages |

| Client |

| Counters |

| Device |

| File |

| FileSet |

| Filename |

| Job |

| JobHisto |

| JobMedia |

| Location |

| LocationLog |

| Log |

| Media |

| MediaType |

| Path |

| PathHierarchy |

| PathVisibility |

| Pool |

| Status |

| Storage |

| UnsavedFiles |

| Version |

+------------------+

4)

配置一个bacula备份系统

4.1)

配置bacula的console端

[root@128 etc]# cat bconsole.conf

#
# Bacula User Agent (or Console) Configuration File
#

Director {
Name = 128-dir #控制端名字,会被bacula-dir.conf and bacula-sd.conf会被引用到
DIRport = 9101 #控制端服务器的端口
address = 192.168.3.128 控制端服务器的ip地址
Password = "e64OrwNyOBFzyPtQd6fBzPQJtM4Uz6a4whX6irzmQUlO" #控制端密码文件
}
4.2)
配置bacula的dirctor端
[root@128 etc]# cat bacula-dir.conf

Director {         #定义bacula的全局配置                   # define myself
Name = 128-dir
DIRport = 9101                # where we listen for UA connections
QueryFile = "/opt//etc/query.sql"
WorkingDirectory = "/opt//var/bacula/working"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 1 #定义一次能处理的最大并发数
Password = "e64OrwNyOBFzyPtQd6fBzPQJtM4Uz6a4whX6irzmQUlO"         # Console password
Messages = Daemon
}
########################################################################################################
Job { #定义增量备份的任务
Name = "client1"
Type = Backup
Level = Incremental #定义备份级别为增量备份,levle的取值范围为 Incremental,Full完全,Differential差异备份
Client = testfd #指定备份的客户端主机,在后面client逻辑段中进行定义
FileSet = testfs #要指定备份的客户端数据在后面的FileSet逻辑段中进行定义
Schedule = testscd #指定这个备份任务的执行时间策略,在后面的schendule逻辑段中进行定义
Storage = testsd #指定备份数据的存储路径与介质,在后面的storage逻辑端中进行定义
Messages = Standard
Pool = testpool  #指定备份使用的pool属性,在后面的pool中指定
Priority = 10
Write Bootstrap = "/opt//var/bacula/working/client1.bsr" #指定备份引导信息路径
}

##########################################################################################################
Job {           #差异备份
Name = "client"
Type = Backup
FileSet = testfs
Schedule = testscd
Storage = testsd
Messages = Standard
Pool = testpool
Client = testfd
Level = Differential
Write Bootstrap = "/opt//var/bacula/working/client.bsr"

}

##########################################################################################################
Job {           #完全备份
Name = "full"
Type = Backup
Client = testfd
Level = Full
FileSet="testfs"
Schedule = "testscd"
Pool = testpool
Storage = testsd
Messages = Standard
RunBeforeJob = "/opt//etc/make_catalog_backup bacula bacula"
RunAfterJob  = "/opt//etc/delete_catalog_backup"
Write Bootstrap = "/opt//var/bacula/working/full.bsr"
}

##########################################################################################################
Job {           #还原任务
Name = "RestoreFiles"
Type = Restore
Client= testfd
FileSet=testfs
Storage = testsd
Pool = testpool
Messages = Standard
Where = /tmp/bacula-restores #指定默认恢复数据到这个路径
}

##########################################################################################################
FileSet {  #定义一个为testfs的备份资源,指定需要备份哪些数据,需要排除哪些数据,可以指定多个fileset
Name = "testfs"
Include {
Options {
signature = MD5; Compression=GZIP;
}
File = /mnt
}

Exclude {  #通过exclude排除不需要备份的文件或者目录,可根据具体情况修改
File = /opt//var/bacula/working
File = /tmp
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}

##########################################################################################################
Schedule { #定义一个名为testscd的任务调度策略
Name = "testscd"
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 = "/opt//var/bacula/working/bacula.sql"
}
}
##########################################################################################################
Client {        #client段用来定义哪个客户端fd的数据
Name = testfd
Address = 192.168.3.129
FDPort = 9102
Catalog = MyCatalog #使用哪个数据库存储信息,mycatalog在后面的mycatalog逻辑段中进行定义
Password = "LFsHH7nr8h2w0NCaRls8D9VAwKNxhY9++/VO5JgMT8mN"          #director段与客户端的FD验证密码,这个值必须与客户端FD配置文件bacula-fd.conf中密码相同
File Retention = 30 days            # 30 days
Job Retention = 6 months            # six months
AutoPrune = yes                     # Prune expired Jobs/Files
}

##################################################################################

Storage {               #用来定义将客户端的数据备份到哪个存储设备上
Name = testsd
Address = 192.168.3.128
SDPort = 9103
Password = "2gBQMeX33WVnxRnlapcVV775lmiBrAe6LEr+/3o+BKg/"
Device = testdev
Media Type = File
}
###################################################################################
Catalog {
Name = MyCatalog
dbname = "bacula"; dbuser = "bacula"; dbpassword = ""
}

Messages {
Name = Standard
mailcommand = "/opt//sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
operatorcommand = "/opt//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 = "/opt//var/bacula/working/log" = all, !skipped
catalog = all
}

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

#####################################################################################
Pool {          #定义供job任务使用的池属性信息,例如设定备份文件过期时间,是否覆盖过期的备份数据,是否自动清除过期备份等
Name = testpool
Pool Type = Backup
Recycle = yes                       # Bacula can automatically recycle Volumes
AutoPrune = yes                     # Prune expired volumes
Volume Retention = 7 days
Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"
Maximum Volumes = 7
Recycle Current Volume = yes
Maximum Volume Jobs = 1

}
#################################################################################
Console {
Name = 128-mon
Password = "VwKvb8Up/nOIpWjHkCDuiRi8vyd+Jf/kZi9bl1oxxw+O"
CommandACL = status, .status
}


[root@128 etc]#

4.3)

配置bacula的SD

[root@128 etc]# cat bacula-sd.conf

Storage {                             # definition of myself
Name = 128-sd
SDPort = 9103                  # Director's port
WorkingDirectory = "/opt//var/bacula/working"
Pid Directory = "/var/run"
Maximum Concurrent Jobs = 20
}

Director {
Name = 128-dir
Password = "2gBQMeX33WVnxRnlapcVV775lmiBrAe6LEr+/3o+BKg/"
}

Director {
Name = 128-mon
Password = "VwKvb8Up/nOIpWjHkCDuiRi8vyd+Jf/kZi9bl1oxxw+O"
Monitor = yes
}

Device {
Name = testdev
Media Type = File
Archive Device = /mnt
LabelMedia = yes;                   #通过label命令来建立卷文件
Random Access = Yes;
AutomaticMount = yes;               # when device opened, read it
RemovableMedia = no;
AlwaysOpen = no;
}

Messages {
Name = Standard
director = 128-dir = all
}


[root@128 etc]#

4.4)

配置bacula的fd段

[root@129 etc]# cat bacula-fd.conf

Director {
Name = 128-dir
Password = "LFsHH7nr8h2w0NCaRls8D9VAwKNxhY9++/VO5JgMT8mN"
}
Director {
Name = 128-mon
Password = "VwKvb8Up/nOIpWjHkCDuiRi8vyd+Jf/kZi9bl1oxxw+O"
Monitor = yes
}
FileDaemon {                          # this is me
Name = localhost.localdomain-fd
FDport = 9102                  # where we listen for the director
WorkingDirectory = /opt//var/bacula/working
Pid Directory = /var/run
Maximum Concurrent Jobs = 20
}
Messages {
Name = Standard
director = 129-dir = all, !skipped, !restored
}


[root@129 etc]#

启动和关闭bacula[root@128 etc]# /opt/sbin/bacula stop

Stopping the Bacula File daemon

Stopping the Bacula Storage daemon

Stopping the Bacula Director daemon

[root@128 etc]# /opt/sbin/bacula start

Starting the Bacula Storage daemon

Starting the Bacula File daemon

Starting the Bacula Director daemon

[root@128 etc]#

或者[root@128 etc]# /opt/etc/bacula-ctl-

bacula-ctl-dir bacula-ctl-fd bacula-ctl-sd

{start|stop|restart}依次启动或者关闭服务

查看端口监听

[root@128 etc]# netstat -lantp | grep bacula

tcp 0 0 0.0.0.0:9101 0.0.0.0:* LISTEN 15105/bacula-dir

tcp 0 0 0.0.0.0:9102 0.0.0.0:* LISTEN 15097/bacula-fd

tcp 0 0 0.0.0.0:9103 0.0.0.0:* LISTEN 15087/bacula-sd

[root@128 etc]# /opt/sbin/bconsole

Connecting to Director 192.168.3.128:9101

1000 OK: 128-dir Version: 5.0.2 (28 April 2010)

Enter a period to cancel a command.

客户端上启动file daemon

[root@129 etc]# /opt/sbin/bacula start

Starting the Bacula File daemon

[root@129 etc]# netstat -lantp | grep bacula

tcp 0 0 0.0.0.0:9102 0.0.0.0:* LISTEN 27904/bacula-fd

本文出自 “风光坏家伙” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: