歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Centos 6.3下用Bacula實現遠程備份還原

Centos 6.3下用Bacula實現遠程備份還原

日期:2017/3/3 16:25:19   编辑:關於Linux

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,方才刪除的文件全部回來了(表示體驗過程中覺得該工具的備份還原速度都很理想)

到這裡,從部署到備份再到還原整個過程就完了~~~~~

Copyright © Linux教程網 All Rights Reserved