一、基本拓扑
server端:192.168.232.31 包括:bacula-dirbacula-sd bconsole
client端:192.168.232.32 包括:bacula-fdbconsole
二、安装
1、下载bacula-5.2.13.tar.gz(server和client端),MySQL-community-release-el7-5.noarch.rpm(仅server端)
2、检查系统是否安装mysql相关,若有则删除干净
3、rpm -ivh mysql-community-release-el7-5.noarch.rpm(仅server端)
4、yum installmysql-devel(否则编译安装bacula,./configure提示找不到mysql.h文件)(仅server端)
5、server和client端解压bacula压缩包,cd bacula-5.2.13
server端执行./configure--prefix=/usr/local/bacula --with-mysql
client端执行./configure--prefix=/usr/local/bacula --enable-client-only
6、server端进入/usr/local/bacula/etc目录直接执行以下脚本文件:
./grant_mysql_privileges
./create_mysql_database
./make_mysql_tables
7、执行完成后查看mysql数据库showdatabases能够查看到bacula库
三、配置
提示:除了增加配置文件,还要注意baculadir baculasd baculafd console之间的密码和name相对应。
3.1 server端配置:
3.1.1、配置文件:bconsole.conf
Director {
Name = ctl01-dir
DIRport = 9101
address = 192.168.232.31
Password = "IM/TDS3/k2jrIXneqc67VAX9ag5qgVulqgCfGFDwWA5T"
}
3.1.2、配置文件:bacula-dir.conf
Director { # define myself
Name = ctl01-dir
DIRport = 9101 # where we listen for UAconnections
QueryFile = "/usr/local/bacula/etc/query.sql"
WorkingDirectory = "/usr/local/bacula/opt/bacula/working"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 1
Password = "IM/TDS3/k2jrIXneqc67VAX9ag5qgVulqgCfGFDwWA5T" #Console password
Messages = Daemon
}
JobDefs {
Name = "DefaultJob"
Type = Backup
Level = Incremental
Client = ctl01-fd
FileSet = "Full Set"
Schedule = "WeeklyCycle"
Storage = File
Messages = Standard
Pool = File
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"
RunBeforeJob = "/usr/local/bacula/etc/make_catalog_backup.plMyCatalog"
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=ctl01-fd
FileSet="Full Set"
Storage = File
Pool = Default
Messages = Standard
Where = /tmp/bacula-restores
}
#########################definemyself####################
Job {
Name = "FullBackup-zlj"
Client = client_fd
Level = Full
Type = Backup
FileSet = "Full Set"
Schedule = "WeeklyCycle"
Storage = File
Messages = Standard
Pool = dbpool
Write Bootstrap ="/usr/local/bacula/working/client_fd.bsr"
}
##########################################################
FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
}
File = /aaa/bbb
}
Exclude {
File = /usr/local/bacula/opt/bacula/working
File = /tmp
File = /proc
File = /tmp
File = /.journal
File = /.fsck
}
}
###################definemyself########################(后面暂时没测试到这个)
FileSet {
Name = "Client_epsi"
Include {
Options {
signature = MD5
Compression = GZIP
}
File ="/usr/local/bacula/working/epsi"
}
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 = ctl01-fd
Address = ctl01
FDPort = 9102
Catalog = MyCatalog
Password = "erA2ioVHicekOCo4B3DHJh3e7X6IEFas1UiISRgwqfEg" # password for FileDaemon
File Retention = 30 days # 30 days
JobRetention = 6 months # sixmonths
AutoPrune = yes # Prune expired Jobs/Files
}
#######################definemyself#################
Client {
Name = client_fd
Address = 192.168.232.32
FDPort = 9102
Catalog = MyCatalog
Password ="bG+0H5zyr6rhockPXN00EJbSmODElpVqTz/4GL/cgBbq"
File Retention = 30 days
Job Retention = 6 months
AutoPrune = yes
}
#####################################################
Storage {
Name = File
Address = 192.168.232.31 # N.B. Use a fully qualified name here
SDPort = 9103
Password = "s0/iBw3fzLk4gxBYmhKzpKwgDW700xlEFW++tDDdmmQN"
Device = FileStorage
Media Type = File
}
Catalog {
Name = MyCatalog
dbname = "bacula"; dbuser = "bacula"; dbpassword =""
}
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
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 # 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
}
Pool {
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}"
Maximum Volumes = 7
Recycle Current Volume = yes
Maximum Volume Jobs = 1
}
Console {
Name = ctl01-mon
Password = "nLspgR64RJweyZi6SH5Nba8cAA1SBKIT+rhlxhAXNId6"
CommandACL= status, .status
}
3.1.3、配置文件:bacula-sd.conf
Storage { # definition ofmyself
Name = ctl01-sd
SDPort = 9103 #Director's port
WorkingDirectory = "/usr/local/bacula/opt/bacula/working"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 20
}
Director {
Name = ctl01-dir
Password = "s0/iBw3fzLk4gxBYmhKzpKwgDW700xlEFW++tDDdmmQN"
}
Director {
Name = ctl01-mon
Password = "nLspgR64RJweyZi6SH5Nba8cAA1SBKIT+rhlxhAXNId6"
Monitor = yes
}
Device {
Name = FileStorage
Media Type = File
Archive Device = /tmp
LabelMedia = yes; # lets Bacula label unlabeled media
Random Access = Yes;
AutomaticMount = yes; # when device opened, read it
RemovableMedia = no;
AlwaysOpen = no;
}
Messages {
Name = Standard
director = ctl01-dir = all
}
3.2 Client端配置
3.2.1配置文件:bacula-fd.conf
Director {
Name = ctl01-dir
Password = "bG+0H5zyr6rhockPXN00EJbSmODElpVqTz/4GL/cgBbq"
}
Director {
Name = ctl01-mon
Password = "nLspgR64RJweyZi6SH5Nba8cAA1SBKIT+rhlxhAXNId6"
Monitor = yes
}
FileDaemon { # this is me
Name = ctl02-fd
FDport = 9102 #where we listen for the director
WorkingDirectory = /usr/local/bacula/opt/bacula/working
PidDirectory = /var/run
Maximum Concurrent Jobs = 20
}
Messages {
Name = Standard
director = ctl02-dir = all, !skipped, !restored
}
3.2.2配置文件:bconsole.conf
Director {
Name = ctl01-dir
DIRport = 9101
address = 192.168.232.31
Password = "IM/TDS3/k2jrIXneqc67VAX9ag5qgVulqgCfGFDwWA5T"
}
四、启动
4.1、server端启动:
./bacula start 启动失败提示信息找不到libbacfind-5.2.13.so文件,find查看系统内有该文件
执行:
cd /usr/local/bacula/lib
ln -s/root/bacula-5.2.13/src/findlib/.libs/libbacfind-5.2.13.so./libbacfind-5.2.13.so
./bacula start启动成功
4.2、client端启动:
./bacula start
五、使用测试
5.1server端:
[root@ctl01 etc]# ./bconsole
Connecting to Director 192.168.232.31:9101
1000 OK: ctl01-dir Version: 5.2.13 (19February 2013)
Enter a period to cancel a command.
*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: File
Enter new Volume name: test111
Defined Pools:
1: Default
2: File
3: Scratch
4: dbpool
Select the Pool (1-4): 4
Connecting to Storage daemon File at192.168.232.31:9103 ...
Sending label command for Volume"test111" Slot 0 ...
3000 OK label. VolBytes=192 DVD=0Volume="test111" Device="FileStorage" (/tmp)
Catalog record for Volume"test111", Slot 0 successfullycreated.
Requesting to mount FileStorage ...
3001 OK mount requested.Device="FileStorage" (/tmp)
You have messages.
*exit
5.2 Client端
[root@ctl02 etc]# ./bconsole
Connecting to Director 192.168.232.31:9101
1000 OK: ctl01-dir Version: 5.2.13 (19February 2013)
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: BackupClient1
2: BackupCatalog
3: RestoreFiles
4: FullBackup-zlj
Select Job resource (1-4): 4 //开始一个备份任务
Run Backup job
JobName: FullBackup-zlj
Level: Full
Client: client_fd
FileSet: Full Set
Pool: dbpool (From Job resource)
Storage: File (From Job resource)
When: 2016-11-02 02:04:55
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=11
You have messages.
* 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: ctl01-fd
2: client_fd
Select Client (File daemon) resource (1-2):2
Connecting to Client client_fd at192.168.232.32:9102
ctl02-fd Version: 5.2.13 (19 February2013) x86_64-unknown-Linux-gnu redhat(Core)
Daemon started 01-Nov-16 21:52. Jobs: run=2running=0.
Heap: heap=135,168 smbytes=102,339max_bytes=175,221 bufs=70 max_bufs=99
Sizeof: boffset_t=8 size_t=8 debug=0 trace=0
Running Jobs:
Director connected at: 02-Nov-16 02:05
No Jobs running.
====
Terminated Jobs:
JobId Level Files Bytes Status Finished Name
======================================================================
1 Full 0 0 Error 01-Nov-16 03:05FullBackup-zlj
2 Full 0 0 Cancel 01-Nov-16 03:17FullBackup-zlj
3 Full 0 0 Cancel 01-Nov-16 03:52FullBackup-zlj
4 Full 0 0 Cancel 01-Nov-16 04:56 FullBackup-zlj
5 Full 0 0 Cancel 01-Nov-16 05:14FullBackup-zlj
6 Full 2 42 OK 01-Nov-16 21:52FullBackup-zlj
7 2 42 OK 01-Nov-16 22:34RestoreFiles
====
*exit
!!!!(delete可以删除一个label,cancel可以取消一个job,出现备份任务执行失败的问题,提示新建一个卷,卷不是append的状态,与pool的定义有关)
5.3 测试从备份恢复丢失的文件
5.3.1、首先在客户端删除bacula-dir中的FileSet逻辑段中定义的备份文件(我的测试文件是/aaa/bbb/test1)
5.3.2、恢复操作如下(Client端执行)
[root@ctl02 etc]# ./bconsole
Connecting to Director 192.168.232.31:9101
1000 OK: ctl01-dir Version: 5.2.13 (19February 2013)
Enter a period to cancel a command.
*restore
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
First you select one or more JobIds thatcontain files
to be restored. You will be presentedseveral methods
of specifying the JobIds. Then you will beallowed to
select which files from those JobIds are tobe restored.
To select the JobIds, you have thefollowing 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: client_fd
2: ctl01-fd
Select the Client (1-2): 1
The defined FileSet resources are:
1: Client_epsi
2: Full Set
Select FileSet resource (1-2): 2
+-------+-------+----------+----------+---------------------+-------------+
| JobId | Level | JobFiles | JobBytes |StartTime | VolumeName |
+-------+-------+----------+----------+---------------------+-------------+
| 6 | F | 2 | 42 | 2016-11-01 21:52:28 | backup-test |
+-------+-------+----------+----------+---------------------+-------------+
You have selected the following JobId: 6
Building directory tree for JobId(s) 6...
1 files inserted into the tree.
You are now entering file selection modewhere you add (mark) and
remove (unmark) files to be restored. Nofiles are initially added, unless
you used the "all" keyword on thecommand line.
Enter "done" to leave this mode.
cwd is: /
$ mark *
2 files marked.
$ done
Bootstrap records written to/usr/local/bacula/opt/bacula/working/ctl01-dir.restore.2.bsr
The job will require the following
Volume(s) Storage(s) SDDevice(s)
===========================================================================
backup-test File FileStorage
Volumes marked with "*" areonline.
2 files selected to be restored.
Run Restore job
JobName: RestoreFiles
Bootstrap: /usr/local/bacula/opt/bacula/working/ctl01-dir.restore.2.bsr
Where: /tmp/bacula-restores
Replace: always
FileSet: Full Set
Backup Client: client_fd
Restore Client: client_fd
Storage: File
When: 2016-11-02 02:12:03
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
OK to run? (yes/mod/no): mod
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 the full path prefix forrestore (/ for none): /
Run Restore job
JobName: RestoreFiles
Bootstrap: /usr/local/bacula/opt/bacula/working/ctl01-dir.restore.2.bsr
Where:
Replace: always
FileSet: Full Set
Backup Client: client_fd
Restore Client: client_fd
Storage: File
When: 2016-11-02 02:12:03
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=12
*exit
5.3.3 查看刚才被删除的/aaa/bbb/test1文件已经恢复。
附:bacula基础知识
1.支持多种备份方式
(1)完全备份
完全备份就是完整的备份业务数据。
优点:当数据丢失时,只是需要当时的备份就能还原
缺点:由于每天对整个系统进行完整备份,难免造成备份数据大量重复。不但占用大量空间成本也要增加,备份时间长。
(2)增量备份
增量备份以上次备份为基准的备份方式,只是对每次更新或者修改的时间进行备份。
优点:只是备份每天更新或者增加的数据数据量小节点了空间节省成本。
缺点:恢复过程比较麻烦。
(3)差异备份
差异备份是以完全备份为基准的一种备份方式。
假如星期一至星期五,星期1进行了一次完整备份,星期二会把星期1到星期2期间的数据不同的数据进行备份以此类推星期3会把星期1到星期3的不同的数据进行备份。
优点:避免了上面两种备份的缺陷。同时又具有上面两种方式的所有有点,他无需每天对系统做完全备份,因此备份数据量小,备份时间短,节省空间,灾难恢复简单只需要两个备份就可以将系统回复。