一个备份工具,可以在网络上各种不同系统之间,实现文件的备份、恢复和验证等等功能。它是基于传统的客户/服务器模式的网络备份程序,被誉为开源平台下最优秀的网络备份工具之一。
功能强大的它,完全可以和商用备份软件相媲美。
环境设置
试验环境如下:有两台linux主机,
一台主机名为bs(以下简称server),ip为192.168.1.106,系统为RHEL 5.4,角色为备份服务器兼存储服务器(另挂一块磁盘到/tmp/homeback下作为存储)
另一台主机名为client。Ip是192.168.1.107,系统是RHEL5.4,角色为需要备份的主机(这里我们以/home为要备份还原的目录)
1.配置Bacula服务器端
(1)使用如下命令安装相关软件包。
yum install mysql-server.i* mysql-devel.i* -y
(3)启动mysqld服务,并设置为下次启动自动加载。
service mysqld restart
chkconfig mysqld on
(4)使用mysqladmin创建MySQL管理员密码。
mysqladmin -uroot -p password 'redhat'
(5)建立bacula所需数据库,在运行以下脚本时会提示输入MySQL管理员密码,运行完成后在MySQL中建立bacula用户时空密码,在生产环境中推荐为该用户设置一个密码。
cd /etc/bacula
./grant_mysql_privileges -h localhost -p
./create_mysql_database -h localhost -p
./make_mysql_tables -h localhost -p
(6)修改bacula全局配置文件/etc/bacula/bacula-dir.conf,该文件时bacula配置文件中最复杂的一个,因为bacula备份工作调度,数据库配置,file director和storage director协作配置
都集中在该文件中。
Director {
Name = TheMuses
DIRport = 9101
QueryFile = "/etc/bacula/query.sql"
WorkingDirectory = "/var/bacula/working"
PidDirectory = "/var/run"
#定义一次能处理的并发作业数
Maximum Concurrent Jobs = 1
# Console password,该密码与控制台所在主机上的bconsole.conf中password参数所定义的值相同
Password = ""
Messages = Daemon
}
JobDefs {
Name = "DefaultJob"
Type = Backup
Level = Incremental
Client = bs
FileSet = "Full Set"
Schedule = "WeeklyCycle"
Storage = File
Messages = Standard
Pool = Default
Priority = 10
}
Job {
Name = "Client1"
JobDefs = "DefaultJob"
Write Bootstrap = "/var/bacula/working/Client1.bsr"
}
Job {
Name = "BackupCatalog"
JobDefs = "DefaultJob"
Level = Full
FileSet="Catalog"
Schedule = "WeeklyCycleAfterBackup"
# This creates an ASCII copy of the catalog
# WARNING!!! Passing the password via the command line is insecure.
# see comments in make_catalog_backup for details.
# Arguments to make_catalog_backup are:
# make_catalog_backup
RunBeforeJob = "/etc/bacula/make_catalog_backup bacula bacula"
# This deletes the copy of the catalog
RunAfterJob = "/etc/bacula/delete_catalog_backup"
Write Bootstrap = "/var/bacula/working/BackupCatalog.bsr"
Priority = 11 # run after main backup
}
Job {
Name = "RestoreFiles"
Type = Restore
Client=bs
FileSet="Full Set"
Storage = File
Pool = Default
Messages = Standard
Where = /bacula-restores
}
FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
}
File = /root/bacula-3.0.0
Exclude {
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
}
#定义何时调度备份,也可以在不同的job中重用。
#Schedule {
# Name = FullIncremental
#每周日晚上1点做完整备份。
# Run = Full sun at 1:00
#在周一晚上1点做差异备份。
# Run = Incremental mon at 1:00
#在周二晚上1点做差异备份。
# Run = Incremental tue at 1:00
#在周三晚上1点做差异备份。
# Run = Incremental wed at 1:00
#在周四晚上1点做差异备份。
# Run = Incremental thu at 1:00
#在周五晚上1点做差异备份。
# Run = Incremental fri at 1:00
#在周六晚上1点做差异备份。
# Run = Incremental sat at 1:00
# }
#Schedule {
# Name = FullDifferential
#每周日晚上1点做完整备份。
# Run = Full sun at 1:00
#在周一晚上1点做增量备份。
# Run = Differential mon at 1:00
#在周二晚上1点做增量备份。
# Run = Differential tue at 1:00
#在周三晚上1点做增量备份。
# Run = Differential wed at 1:00
#在周四晚上1点做增量备份。
# Run = Differential thu at 1:00
#在周五晚上1点做增量备份。
# Run = Differential fri at 1:00
#在周六晚上1点做增量备份。
# Run = Differential sat at 1:00
# }
#定义需要备份的内容
FileSet {
Name = "backboot"
Include {
Options {
signature = MD5
}
#
# Put your list of files here, preceded by 'File =', one per line
# or include an external list with:
#
# File = #
# Note: / backs up everything on the root partition.
# if you have other partitons such as /usr or /home
# you will probably want to add them too.
#
# By default this is defined to point to the Bacula build
# directory to give a reasonable FileSet to backup to
# disk storage during initial testing.
#
File = /boot
}
#
# If you backup the root directory, the following two excluded
# files can be useful
#
Exclude {
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}
FileSet {
Name = "Catalog"
Include {
Options {
signature = MD5
}
File = /var/bacula/working/bacula.sql
}
}
#定义需要备份的客户端信息,如果有多个客户端可定义多个Client快。
Client {
Name = bs
Address = 192.168.1.106 #指定bs这台主机的地址,如果有DNS可以写FQDN的名字。
FDPort = 9102
Catalog = MyCatalog #定义存储信息的数据库。
Password = "" # 要和RHEL5上bacula-fd.conf的一致
File Retention = 30 days # 30 days
Job Retention = 6 months # six months
AutoPrune = yes # Prune expired Jobs/Files
}
Client {
Name = bc1
Address = 192.168.1.107
FDPort = 9102
Catalog = MyCatalog
Password = ""
File Retention = 30 days
Job Retention = 6 months
AutoPrune = yes
}
#Client {
# Name = bc2
# Address = 192.168.1.108
# FDPort = 9102
# Catalog = MyCatalog
# Password = ""
# File Retention = 30 days
# Job Retention = 6 months
# AutoPrune = yes
#}
#定义一个任务。
Job {
Name = bc1 #任务名称。
Client = bc1 #定义需要执行任务的客户端,指定的名称为Client快中已定义的名称。
JobDefs = DefaultJob ##指定在该任务中未明确定义的参数,根据名为"DefaultJob"任务的定义。
Write Bootstrap = "/var/bacula/working/bc1.bsr" #定义备份引导信息的存放位置,供恢复作业期间使用。
Level = Full #定义默认备份程度的完整,schedule中的配置会覆盖这里的配置。
FileSet = backboot #定义需要备份的内容,指定的名称为FileSet快中已定义的名称。
Schedule = "WeeklyCycleAfterBackup" #备份计划任务按"FullIncremental"定义的执行,如果没有指定schedule,默认不运行,可以通过控制台调度。
}
#Job {
# Name = bc2
# Client = bc2
# JobDefs = DefaultJob
# Write Bootstrap = "/var/bacula/working/bc2.bsr"
# Level = Full
# Schedule = FullIncremental
#}
Storage {
Name = File
Address = 192.168.1.106
SDPort = 9103
Password = ""
Device = FileStorage
Media Type = File
}
#定义bacula所使用的数据库参数。
Catalog {
Name = MyCatalog
dbname = "bacula";dbuser="bacula";dbpassword="";dbaddress=127.0.0.1
}
Messages {
Name = Daemon
mailcommand = "/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
mail = = all, !skipped
console = all, !skipped, !saved
append = "/var/bacula/working/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 = Scratch
Pool Type = Backup
}
Console {
Name = bs-mon
Password = ""
CommandACL = status, .status
}
(7)修改/etc/bacula/bacula-sd.conf.
Storage { # definition of myself
Name = File
SDPort = 9103 # Director's port
WorkingDirectory = "/var/bacula/working"
Pid Directory = "/var/run"
Maximum Concurrent Jobs = 20
}
Director {
Name = TheMuses
Password = ""
}
Director {
Name bs-mon
Password = ""
Monitor = yes
}
#定义存储策略。
Device {
Name = FileStorage
Media Type = File
Archive Device = /tmp/homeback;
LabelMedia = yes; # lets Bacula label unlabeled media
Random Access = Yes;
AutomaticMount = yes; # when device opened, read it
RemovableMedia = no;
AlwaysOpen = no;
}
(8)修改/etc/bacula/bconsole.con。
Director {
Name = TheMuses
DIRport = 9101
address = 192.168.1.106
Password = ""
}
(9)使用如下命令启动bacula进程,并将其加入/etc/rc.d/rc.local文件中。
/sbin/bacula restart
(10)使用如下名利通过bacula控制台添加存储设备
bconsole 如图所示:
>添加存储设备。label
>选择存储池。
>退出。
2.配置bacula客户端
(1)下载bacula
tar xvf bacula-3.0.0.tar.gz
cd bacula-3.0.0
./configure --enable-client-only #只安装bacula客户端。
make
make install
(2)修改/etc/bacula/bacula-fd.conf(以下操作在bc1.example.com、bc2.example.com上都需要执行)。
Director {
#必须与bacula服务器端bacula-dir.conf中Director块中name参数指定相同的值。
Name = TheMuses
#必须与bacula服务器端bacula-dir.conf中对应Client块中Password参数相同的值。
Password = ""
}
Director {
#必须与bacula服务器端bacula-dir.conf中的console块中name参数相同的值。
Name = bs-mon
#必须与bacula服务器端bacula-dir.conf中的console块中password参数指定相同的值。
Password = ""
Monitor = yes
}
FileDaemon {
Name = TheMuses
FDport = 9102
WorkingDirectory = /var/bacula/working
Pid Directory = /var/run
Maximum Concurrent Jobs = 20
}
Messages {
Name = Standard
director = bs-dir = all,!skipped,!restored
}
(3)使用如下命令启动bacula进程,并将其加入/etc/rc.d/rc.local文件中。
/sbin/bacula restart
3.通过bacula备份
(1)在bs.example.com上使用如下命令通过bacula控制台进行备份,如图:
bconsole
(2)在bs.example.com上使用如下命令通过bacula控制台查看备份情况,如图:
bconsole
hehe...此时客户端要备份的目录已备份成功。
4.通过bacula恢复
接下来咱们来做还原,首先咱们把client上的/boot中的文件删除掉
(1)在bs.example.com上使用如下命令通过bacula控制台进行恢复数据的提取,如图所示。
bconsole
这个地方注意一下,如果要还原到client原位置则按以下步骤
接下来我们在Client查看。
恢复成功......