1、Bacula配置mysql
Bacula備份的主要配置項目存放在bacula-dir.conf文件中,該文件中的配置項包含如下內容。linux
Jobdefs:默認執行任務sql
Job:自定義一個備份或恢復任務數據庫
Fileset:定義備份那些數據,不備份那些數據vim
Schedule:定義備份時間策略windows
Pool:定義供Job使用的池屬性bash
Client:定義要備份的主機地址app
Storange:定義數據的存儲方式less
Messages:定義發送日子報告和記錄日誌的位置dom
各項目定義的名稱會相互關聯,以下圖所示。
3.1 bacula-dir.conf配置
主控端的Director項:
一、Name和Console端Director項的Name一致;
二、Name要和介質端Director項的Name一致;
三、Name要和客戶端Director項的Name一致;
四、Password項要和Console端的Password項的密碼一致;
主控端的Storage項:
一、Device要和介質端Device項的Name一致;
二、MediaType要和介質端Device項的MediaType一致;
三、Password要和介質端Director項的Pasword一致;
主控端的Client項:
Password要和客戶端Director項的Password一致;
vim /etc/bacula/bacula-dir.conf
Director {#全局設置 Name = bacula-test-dir #名稱要和Console端、SD端、FD端一致 DIRport = 9101 #啓動的端口 QueryFile = "/usr/libexec/bacula/query.sql" WorkingDirectory = "/var/spool/bacula/" PidDirectory = "/var/run" Maximum Concurrent Jobs = 20 #同時執行的最大任務數量 Password = "u3R1MUpLlKodHFr4PiqGQMGJfaNfhiXb14ul6xcpBA8d" #密碼和Console端一致 Messages = Daemon } JobDefs { #默認的任務設置 Name = "DefaultJob" #任務名稱 Type = Backup #任務的類型,有備份、恢復、校驗、管理等 Level = Incremental #增量備份,有差別、全備份 Client = bacula-test-fd #備份的客戶端 FileSet = "Full Set" #選擇客戶端須要備份額目錄及文件 Schedule = "WeeklyCycle" #備份週期 Storage = File1 #存儲的方式 Messages = Standard Pool = File SpoolAttributes = yes Priority = 10 Write Bootstrap = "/var/spool/bacula/%c.bsr" #將做業記錄寫入文件 } Job { Name = "Backup-17.98" #定義一個備份任務 Type = Backup Level = Incremental Client = bacula-17-98 #須要備份的客戶端 FileSet = "Windows" #須要備份的目錄和文件 Schedule = "WeeklyCycle" Storage = File1 Messages = Standard Pool = File SpoolAttributes = yes Priority = 10 Write Bootstrap = "/var/spool/bacula/windows%c.bsr" } Job { Name = "BackupClient1" JobDefs = "DefaultJob" } Job { Name = "BackupCatalog" #定義一個元數據備份任務 JobDefs = "DefaultJob" Level = Full FileSet="Catalog" Schedule = "WeeklyCycleAfterBackup" RunBeforeJob = "/usr/libexec/bacula/make_catalog_backup.pl MyCatalog" RunAfterJob = "/usr/libexec/bacula/delete_catalog_backup" Write Bootstrap = "/var/spool/bacula/%n.bsr" Priority = 11 } Job { Name = "RestoreFiles" #定義一個恢復任務 Type = Restore Client=bacula-test-fd FileSet="Full Set" Storage = File1 Pool = File Messages = Standard Where = /tmp/bacula-restores } FileSet { Name = "Full Set" #定義須要備份的目錄及文件 Include { Options { signature = MD5 #採用MD5 Compression = GZIP #啓用GZIP壓縮 } File = /var/lib/mysql #須要備份的目錄 } Exclude { #無需備份的目錄和文件 File = /var/spool/bacula/ File = /tmp File = /proc File = /tmp File = /sys File = /.journal File = /.fsck } } FileSet { Name = "Windows" #定義一個新的須要備份的設置 Include { Options { signature = MD5 compression = GZIP IgnoreCase = yes } File = "D:/msdn" } } 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 = "/var/spool/bacula/bacula.sql" } } Client { Name = bacula-test-fd #定義須要備份的客戶端 Address = 192.168.17.100 FDPort = 9102 Catalog = MyCatalog Password = "nb5dURhiVT3RPsHkFvXetau9LrnL/FhY/ORWkFOTPamT"#密碼要和FD端的一致 File Retention = 30 days #定義文件記錄在 Catalog 數據庫中的保留時間,不影響已存檔的備份文件 Job Retention = 3 months #定義任務記錄在 Catalog 數據庫中的保留時間,不影響已存檔的備份文件 AutoPrune = yes #自動修剪 } Client { Name = bacula-17-98 Address = 192.168.17.98 FDPort = 9102 Catalog = MyCatalog Password = "nb5dURhiVT3RPsHkFvXetau9LrnL/FhY/ORWkFOTPamT" File Retention = 30 days Job Retention = 3 months AutoPrune = yes } Storage { Name = File1 Address = 192.168.17.100 #存儲端的地址 SDPort = 9103 Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg" Device = FileChgr1 #指定存儲的設備。引用存儲端配置文件的 Device{}的 Name 值 Media Type = File1 #與存儲端配置文件的 Device{}的 Media Type 值相同 Maximum Concurrent Jobs = 10 #定義此存儲端所容許同時進行的任務最大數量 } Storage { Name = File2 Address = 192.168.17.100 SDPort = 9103 Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg" Device = FileChgr2 Media Type = File2 Maximum Concurrent Jobs = 10 } Catalog { Name = MyCatalog #指定 Catalog{}名稱 dbname = "bacula"; dbuser = "bacula"; dbpassword = "bacula" } Messages { Name = Standard #定義日誌 append = "/var/log/bacula.log" = all, !skipped append = "/var/log/bacula.err.log" = error,warning,fatal catalog = all } Messages { Name = Daemon append = "/var/log/bacula.log" = all, !skipped append = "/var/log/bacula.err.log" = error,warning,fatal } Pool { Name = Default Pool Type = Backup Recycle = yes #是否重複使用 Volumes AutoPrune = yes #自動清理 Maximum Volume Jobs = 1 Volume Retention = 15 days #卷的保留時間 Maximum Volume Bytes = 5G #Volume容量 Maximum Volumes = 100 #Volumes數量l Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"#卷命名方式 } Pool { Name = File Pool Type = Backup Recycle = yes AutoPrune = yes Maximum Volume Jobs = 1 Volume Retention = 15 days Maximum Volume Bytes = 50G Maximum Volumes = 100 Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}" } # Scratch pool definition Pool { Name = Scratch Pool Type = Backup } Console { Name = bacula-test-mon Password = "fX2cKUkN2RSiLTkeQd5LCPDDw61PzGkuit2+7DvWxVG1" CommandACL = status, .status }
3.2 bacula-sd.conf配置
存儲端的配置文件是bacula-sd.conf,它主要負責定義備份文件的存放方式和地址,具體的狀況以下所示:
Storage { #定義存儲端名稱 Name = bacula-test-sd SDPort = 9103 WorkingDirectory = "/var/spool/bacula/" Pid Directory = "/var/run" Maximum Concurrent Jobs = 20 } Director { Name = bacula-test-dir Password = "qy5ILHHJNXLCUWGudeC1ke1hPioBo+ye2bUBU5ncxADg" } Director { Name = bacula-test-mon Password = "7zSF0B9viPBuwkKpPC2PoJw1qxOEuvCxbWDxzXc1cHk9" Monitor = yes } Autochanger {#是否自動更換設備 Name = FileChgr1 Device = FileChgr1-Dev1, FileChgr1-Dev2#定義需更換的設備 Changer Command = "" Changer Device = /dev/null } Device { Name = FileChgr1-Dev1 Media Type = File1#類型是文件(能夠是DVD,磁帶) Archive Device = /tmp#存放位置 LabelMedia = yes; #媒體標註 Random Access = Yes; AutomaticMount = yes; #自動掛載 RemovableMedia = no; AlwaysOpen = no; Maximum Concurrent Jobs = 5 } Device { Name = FileChgr1-Dev2 Media Type = File1 Archive Device = /tmp LabelMedia = yes; Random Access = Yes; AutomaticMount = yes; RemovableMedia = no; AlwaysOpen = no; Maximum Concurrent Jobs = 5 } Autochanger { Name = FileChgr2 Device = FileChgr2-Dev1, FileChgr2-Dev2 Changer Command = "" Changer Device = /dev/null } Device { Name = FileChgr2-Dev1 Media Type = File2 Archive Device = /tmp LabelMedia = yes; Random Access = Yes; AutomaticMount = yes; RemovableMedia = no; AlwaysOpen = no; Maximum Concurrent Jobs = 5 } Device { Name = FileChgr2-Dev2 Media Type = File2 Archive Device = /tmp LabelMedia = yes; Random Access = Yes; AutomaticMount = yes; RemovableMedia = no; AlwaysOpen = no; Maximum Concurrent Jobs = 5 } Messages { Name = Standard director = bacula-test-dir = all }
2、Bacula備份、恢復測試
2.1 備份操做
運行備份操做
[root@bacula-test /tmp]
#bconsole
Connecting to Director 192.168.17.100:9101
1000 OK: 102 bacula-test-dir Version: 7.4.1 (15 February 2016)
Enter a period to cancel a command.
*label #標籤狀態
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
1: File1
2: File2
Select Storage resource (1-2): 1 #定義的存儲資源
Enter new Volume name: vol-20160601
Defined Pools:
1: Default
2: File
3: Scratch
Select the Pool (1-3): 2 #文件類型
Connecting to Storage daemon File1 at 192.168.17.100:9103 ...
Sending label command for Volume "vol-20160601" Slot 0 ...
3000 OK label. VolBytes=209 VolABytes=0 VolType=1 Volume="vol-20160601" Device="FileChgr1-Dev1" (/tmp)
Catalog record for Volume "vol-20160601", Slot 0 successfully created.
Requesting to mount FileChgr1 ...
3906 File device ""FileChgr1-Dev1" (/tmp)" is always mounted.
*run #執行備份操做
A job name must be specified.
The defined Job resources are:
1: Backup-17.98
2: BackupClient1
3: BackupCatalog
4: RestoreFiles
Select Job resource (1-4): 3 #選擇須要備份的客戶端
Run Backup job
JobName: BackupCatalog
Level: Full
Client: bacula-test-fd
FileSet: Catalog
Pool: File (From Job resource)
Storage: File1 (From Job resource)
When: 2016-06-01 15:59:49
Priority: 11
OK to run? (yes/mod/no): yes #贊成備份
Job queued. JobId=37
*messages
You have no messages.
*exit
4.2 恢復操做
#bconsole
Connecting to Director 192.168.17.100:9101
1000 OK: 102 bacula-test-dir Version: 7.4.1 (15 February 2016)
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: bacula-17-98
2: bacula-test-fd
Select the Client (1-2): 2
The defined FileSet resources are:
1: Catalog
2: Full Set
Select FileSet resource (1-2): 2
+-------+-------+----------+-----------+---------------------+--------------------+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
+-------+-------+----------+-----------+---------------------+--------------------+
| 1 | F | 126 | 731,496 | 2016-05-18 16:02:32 | linux-file1 |
| 29 | D | 5 | 991,369 | 2016-05-29 23:05:04 | db-2016-05-29-id29 |
| 32 | I | 2 | 1,000,660 | 2016-05-30 23:05:04 | db-2016-05-30-id32 |
| 35 | I | 2 | 1,038,878 | 2016-05-31 23:05:05 | db-2016-05-31-id35 |
+-------+-------+----------+-----------+---------------------+--------------------+
You have selected the following JobIds: 1,29,32,35
Building directory tree for JobId(s) 1,29,32,35 ... ++++++++++++++++++++++++++++++++++++++++
122 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: /
ls
var/
$ mark var
126 files marked.
$ lsmark
*var/
*lib/
*mysql/
*aria_log.00000001
*aria_log_control
*bacula/
*BaseFiles.frm
*CDImages.frm
*Client.frm
done
Bootstrap records written to /var/spool/bacula//bacula-test-dir.restore.1.bsr
Bootstrap records written to /var/spool/bacula//bacula-test-dir.restore.1.bsr
The Job will require the following (*=>InChanger):
Volume(s) Storage(s) SD Device(s)
===========================================================================
linux-file1 File1 FileChgr1
db-2016-05-29-id29 File1 FileChgr1
db-2016-05-31-id35 File1 FileChgr1
Volumes marked with "*" are in the Autochanger.
126 files selected to be restored.
Using Catalog "MyCatalog"
Run Restore job
JobName: RestoreFiles
Bootstrap: /var/spool/bacula//bacula-test-dir.restore.1.bsr
Where: /tmp/bacula-restores
Replace: Always
FileSet: Full Set
Backup Client: bacula-test-fd
Restore Client: bacula-test-fd
Storage: File1
When: 2016-06-01 16:08:14
Catalog: MyCatalog
Priority: 10
Plugin Options:
OK to run? (yes/mod/no): yes
Job queued. JobId=38
*messages
You have no messages.
參考內容:
企業級的開源備份工具Bacula之安裝:http://waringid.blog.51cto.com/65148/1792007