1. 程式人生 > >centos6.7下的系統備份與恢復(bacula 的安裝、配置和執行)

centos6.7下的系統備份與恢復(bacula 的安裝、配置和執行)

一、安裝bacula

這裡對上一節的第一種bacula部署結構進行介紹。

主機名 IP地址 作業系統 應用角色

baculaServer 10.0.172.185   centos6.7 Director、SD、Console

baculaClient 10.0.172.186   centos6.7 FD

 

1、在baculaSever端安裝bacula-dir   bacula-sd   dconsole

Yum install -y bacula-director-mysql.x86_64 mysql-server

/etc/init.d/mysqld start

Yum install –y bacula-storage-common bacula-console

2、在baculaClient端安裝bacula-fd

Yum install –y bacula-client

3初始化Mysql資料庫

baculaServer上安裝完bacula後,還需要建立bacula對應的Mysql資料庫以及訪問資料庫的授權,好在bacula已經為使用者準備好了這樣的指令碼,接下來只要在bacula伺服器端上執行如下指令碼即可。

cd /usr/libexec/bacula/

./grant_mysql_privileges

./create_mysql_database

./make_mysql_tables

接下來可以登入Mysql資料庫,檢視

bacula的資料庫和資料表是否已經建立。在執行上面三行Mysql初始程式碼時,預設由空密碼的root使用者執行,因此要請確保Mysql資料庫root密碼為空。

使用Show databases檢視資料庫是否存在

二、配置bacula備份系統

其實就是對Director端配置檔案bacula-dir.confSD配置檔案bacula-sd.conf、客戶端FD配置檔案bacula-fd.conf以及Console端配置檔案bconsole.conf進行配置的過程。
根據上面的安裝部署,將Director端、SDConsole端集中在一臺伺服器baculaServer(即10.0.172.185

)上,而將客戶端FD部署在baculaClient(即10.0.172.186)伺服器上,下面詳細講述配置過程。

baculaServer伺服器上進行配置

1 配置baculaConsole

首先進入配置檔案資料夾,如下圖所示:

#參考配置命令,截圖為實際配置命令

Director {

Name = baculaServer-dir #控制端名稱,在下面的bacula-dir.conf和bacula-sd.conf

#檔案中會陸續的被引用

DIRport = 9101 #控制端服務埠

address = 10.0.172.185 #控制端伺服器IP地址

Password = "123456" #初學可以把密碼設定成完全一樣的

#控制端密碼檔案

}

Console端的配置檔案是bconsole.conf,這個配置檔案很簡單,配置完的檔案如下:

2 配置baculaDirector

bacula-dir.confDirector端的配置檔案,也是bacula的核心配置檔案,這個檔案非常複雜,共分為10個邏輯段,分別是:

  • Director,定義全域性設定
  • Catalog,定義後臺資料庫
  • Jobdefs,定義預設執行任務
  • Job,自定義一個備份或者恢復任務
  • Fileset,定義備份哪些資料,不備份哪些資料
  • Schedule,定義備份時間策略
  • Pool,定義供Job使用的池屬性
  • Client,定義要備份的主機地址
  • Storage,定義資料的儲存方式
  • Messages,定義傳送日誌報告和記錄日誌的位置

程式碼清單1是一個已經配置好的檔案,其中,“#”號後面的內容為註釋。

程式碼清單1 已經設定好的Director端的配置檔案

#參考配置命令,截圖為實際配置命令

Director { #定義bacula的全域性配置

Name = baculaServer-dir

DIRport = 9101 #定義Director的監聽埠

QueryFile = "/etc/bacula/query.sql"

WorkingDirectory = "/var/spool/bacula"

PidDirectory = "/var/run"

Maximum Concurrent Jobs = 1 #定義一次能處理的最大併發數



#驗證密碼,這個密碼必須與bconsole.conf檔案中對應的Director邏輯段密碼相同

Password = "123456"



#定義日誌輸出方式,“Daemon”在下面的Messages邏輯段中進行了定義

Messages = Daemon

}

#參考配置命令,截圖為實際配置命令

Job { #自定義一個備份任務

Name = "Client1" #備份任務名稱

Client = dbfd #指定要備份的客戶端主機,“dbfd”在後面Client邏輯段中進行定義

Level = Incremental #定義備份的級別,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 = "/opt/bacula/var/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 = "/opt/bacula/var/bacula/working/Client1.bsr"

}



Job { #定義一個名為BackupCatalog的完全備份任務

Name = "BackupCatalog"

Type = Backup

Level = Full #指定備份級別為完全備份

Client = dbfd

FileSet="dbfs"

Schedule = "dbscd"

Pool = dbpool

Storage = dbsd

Messages = Standard

RunBeforeJob = "/opt/bacula/etc/make_catalog_backup bacula bacula"

RunAfterJob = "/opt/bacula/etc/delete_catalog_backup"

Write Bootstrap = "/opt/var/bacula/working/BackupCatalog.bsr"

}



Job { #定義一個還原任務

Name = "RestoreFiles"

Type = Restore #定義Job的型別為“Restore ”,即恢復資料

Client=dbfd

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 = /cws3 #指定客戶端FD需要備份的檔案目錄

}
Exclude { #通過Exclude排除不需要備份的檔案或者目錄,可根據具體情況修改

File = /opt/bacula/var/bacula/working

File = /tmp

File = /proc

File = /tmp

File = /.journal

File = /.fsck

}

}



FileSet {

Name = "Catalog"

Include {

Options {

signature = MD5

}

File = /opt/bacula/var/bacula/working/bacula.sql

}

}


Schedule { #定義一個名為dbscd的備份任務排程策略

Name = "WeeklyCycle"

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分進行增量備份

}

Client { #Client用來定義備份哪個客戶端FD的資料

Name = baculaSever #Clinet的名稱,可以在前面的Job中呼叫

Address = 10.0.172.186 #要備份的客戶端FD主機的IP地址

FDPort = 9102 #與客戶端FD通訊的埠

Catalog = MyCatalog #使用哪個資料庫儲存資訊,“MyCatalog”在後面的MyCatalog邏輯段中進行定義

Password = "123456" #Director端與客戶端FD的驗證密碼,這個值必須與客戶端FD配置檔案bacula-fd.conf中密碼相同

File Retention = 30 days #指定儲存在資料庫中的記錄多久迴圈一次,這裡是30天,隻影響資料庫中的記錄不影響備份的檔案

Job Retention = 6 months #指定Job的保持週期,應該大於File Retention指定的值

AutoPrune = yes #當達到指定的保持週期時,是否自動刪除資料庫中的記錄,yes表示自動清除過期的Job

}



Client {

Name = baculaClient

Address = 10.0.172.185//伺服器端IP

FDPort = 9102

Catalog = MyCatalog

Password = "123456"

File Retention = 30 days

Job Retention = 6 months

AutoPrune = yes

}

 

Storage { # Storage用來定義將客戶端的資料備份到哪個儲存裝置上

Name = baculaSever-sd

Address = 10.0.172.185 #指定儲存端SD的IP地址

SDPort = 9103 #指定儲存端SD通訊的埠

Password = "123456" #Director端與儲存端SD的驗證密碼,這個值必須與儲存端SD配置檔案bacula-sd.conf中Director邏輯段密碼相同

Device = dbdev #指定資料備份的儲存介質,必須與儲存端(這裡是192.168.12.188)的bacula-sd.conf配置檔案中的“Device” 邏輯段的“Name”項名稱相同

Media Type = File #指定儲存介質的類別,必須與儲存端SD(這裡是192.168.12.188)的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 = "/opt/bacula/log/bacula.log" = all, !skipped #定義bacula的執行日誌

append ="/opt/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 = "/opt/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-2010-04-18-id139

Maximum Volumes = 7 #設定最多儲存多少個備份檔案

Recycle Current Volume = yes #表示可以使用最近過期的備份檔案來儲存新備份

Maximum Volume Jobs = 1 #表示每次執行備份任務建立一個備份檔案

}



Console { #限定Console利用tray-monitor獲得Director的狀態資訊

Name = baculaSever-mon

Password = "123456"

CommandACL = status, .status

}

3 配置baculaSD

SD可以是一臺單獨的伺服器,也可以和Director在一臺機器上,本例就將SDDirector端放在一起進行配置,SD的配置檔案是bacula-sd.conf,程式碼清單2是一個已經配置好的bacula-sd.conf檔案。

程式碼清單2 配置好的bacula-sd.conf檔案

Storage { #定義儲存,本例中是baculaSever

Name = baculaSever-sd #定義儲存名稱

SDPort = 9103 #監聽埠

WorkingDirectory = "/var/spool/bacula"

Pid Directory = "/var/run"

Maximum Concurrent Jobs = 20

}

Director { #定義一個控制StorageDaemon的Director

Name = baculaSever-dir #這裡的“Name”值必須和Director端配置檔案bacula-dir.conf中Director邏輯段名稱相同

Password = "123456" #這裡的“Password”值必須和Director端配置檔案bacula-dir.conf中Storage邏輯段密碼相同

}



Director { #定義一個監控端的Director

Name = baculaSever-mon #這裡的“Name”值必須和Director端配置檔案bacula-dir.conf中Console邏輯段名稱相同

Password = "123456" #這裡的“Password”值必須和Director端配置檔案bacula-dir.conf中Console邏輯段密碼相同

Monitor = yes

}

Device { #定義Device

Name = dbdev #定義Device的名稱,這個名稱在Director端配置檔案bacula-dir.conf中的Storage邏輯段Device項中被引用

Media Type = File #指定儲存介質的型別,File表示使用檔案系統儲存

Archive Device = /webdata #Archive Device用來指定備份儲存的介質,可以是cd、dvd、tap等,這裡是將備份的檔案儲存的/webdata目錄下

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 = baculaSever-dir = all

}

4 配置baculaClient伺服器的FD

客戶端FD執行在一臺獨立的伺服器上,在本例中是baculaclient主機(即192.168.12.189),它的配置檔案是bacula-fd.conf,配置好的檔案如下:

Director { #定義一個允許連線FD的控制端

Name = baculaClient-dir #這裡的“Name”值必須和Director端配置檔案bacula-dir.conf中Director邏輯段名稱相同

Password = "123456" #這裡的“Password”值必須和Director端配置檔案bacula-dir.conf中Client邏輯段密碼相同

}



Director { #定義一個允許連線FD的監控端

Name = baculaClient-mon

Password = "123456"

Monitor = yes

}



FileDaemon { #定義一個FD端

Name = baculaClient-fd

FDport = 9102 #監控埠

WorkingDirectory = /var/spool/bacula
Pid Directory = /var/run

Maximum Concurrent Jobs = 20 #定義一次能處理的併發作業數

}



Messages { #定義一個用於FD端的Messages

Name = Standard

director = baculaClient-dir = all, !skipped, !restored

}

 

三、啟動baculaDirector daemonStorage daemon

完成上面的配置後,就可以啟動或關閉bacula了。在baculaserver上啟動或關閉控制端的所有服務,有如下兩種方式。

可以通過分別管理bacula各個配置端的方式,依次啟動或者關閉每個服務:

[[email protected] ~]# /etc/init.d/bacula-dir {start|stop|restart|status}

[[email protected] ~]# /etc/init.d/bacula-ctl-sd {start|stop|restart|status}

 

由於將客戶端FD配置到了另一個主機baculaclient上,因此無需在baculaserver上啟動File daemon服務。啟動bacula的所有服務後,通過netstat命令,觀察啟動埠情況:

[[email protected] etc]# netstat -antl |grep 91

tcp 0 0 0.0.0.0:9101 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:9103 0.0.0.0:* LISTEN

 

在客戶端FD啟動File daemon

最後 ,在客戶端FD(即baculaclient)上啟動File daemon服務,操作如下:

[[email protected]  ~]# /etc/init.d/bacula-ctl-fd {start|stop|restart|status}

Bacula正常執行結果圖:

四、注意事項

各配置檔案所需要相同的名字,密碼等資訊,如下圖所示: