作業系統:centos 6
bacula伺服器:bacula.test.org
bacula用戶端:apache01.test.org
在伺服器注冊bacula用戶端并添加一個任務,
在/etc/bacula/bacula-dir.conf 添加如下内容:
Client {
Name = apache01.test.org
Password = FD_PASSWORD
Address = apache01.test.org
FDPort = 9102
Catalog = MyCatalog
File Retention = 30 days
Job Retention = 6 months
}
Job {
Name = apache01.job
Type = Backup
Level = Incremental
Client = apache01.test.org
FileSet = "Full Set"
Schedule = WeeklyCycle
Storage = File
Pool = File
Messages = Standard
重新載入配置檔案
# service bacula-dir reload
# service bacula-sd reload
OK,恭喜你,大功告成。此時bacula伺服器會定時執行預設的備份,也就是如下值:
預設備份路徑 /usr/sbin ,(或許你想添加另外一個fileset,依葫蘆畫瓢即可)
FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
}
File = /usr/sbin
}
Exclude {
File = /var/spool/bacula
File = /tmp
File = /proc
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
備份到哪裡?,預設是/tmp,也就是/etc/bacula/bacula-sd.conf中的這一段代碼
Device {
Name = FileStorage
Media Type = File
Archive Device = /tmp #請修改這裡
LabelMedia = yes;
Random Access = Yes;
AutomaticMount = yes;
RemovableMedia = no;
AlwaysOpen = no;
注:
1、跟前面文章一樣,必須有内網DNS,否則用戶端必須在hosts檔案裡靜态解析或使用 IP來識别。
2、本文配置檔案若沒有指定,則是/etc/bacula/bacula-dir.conf
3、bacula 用戶端初始化後的密碼是FD_PASSWORD,建議用puppet托管此檔案,以便日後修改密碼。
以下puppet 代碼僅供參考
file {"/etc/bacula/bacula-fd.conf" :
ensure => present,
owner => root,
group => bacula,
mode => 0640,
source => "puppet:///files/bacula-fd.conf",
bacula提供了一個強大的控制台,手動執行備份任務的辦法
[root@bacula]# bconsole
Connecting to Director 192.168.1.251:9101
1000 OK: bacula-dir Version: 5.0.0 (26 January 2010)
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: apache01.test.org
Select Job resource (1-4): 4
Run Backup job
JobName: apache01.job
Level: Incremental
Client: apache01.test.org
FileSet: Full Set
Pool: File (From Job resource)
Storage: File (From Job resource)
When: 2012-08-07 19:32:02
Priority: 10
OK to run? (yes/mod/no): yes
還原備份就沒有自動一說了,這是必須的
*restore
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-fd
2: apache01.test.org
Select the Client (1-2): 2
Automatically selected FileSet: Full Set
+-------+-------+----------+------------+---------------------+------------+
| JobId | Level | JobFiles | JobBytes | StartTime | VolumeName |
| 17 | F | 173 | 10,051,327 | 2012-08-07 18:38:40 | test-0014 |
You have selected the following JobId: 17
Building directory tree for JobId(s) 17 ... +++++++++++++++++++++++++++++++++++++++++++
172 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: /
進入了備份檔案的根目錄,裡面組織的跟原系統一樣,我們備份了/usr/sbin,那麼根目錄下隻有usr子目錄了,其餘類推,可以用常見的幾個基本指令來檢視
$ ls
usr/
$ cd usr
cwd is: /usr/
sbin/
$ cd sbin
cwd is: /usr/sbin/
.sshd.hmac
addgnupghome
adduser
alternatives
anacron
applygnupgdefaults
arpd
arping
authconfig
authconfig-tui
avcstat
bacula
bacula-fd
biosdecode
bsmtp
。。。。。。
我們來還原一個檔案/usr/sbin/adduser
$ mark adduser
1 file marked.
$ done
Bootstrap records written to /var/spool/bacula/bacula-dir.restore.1.bsr
The job will require the following
Volume(s) Storage(s) SD Device(s)
===========================================================================
test-0014 File FileStorage
Volumes marked with "*" are online.
1 file selected to be restored.
Run Restore job
JobName: RestoreFiles
Bootstrap: /var/spool/bacula/bacula-dir.restore.1.bsr
Where: /tmp/bacula-restores
Replace: always
FileSet: Full Set
Backup Client: apache01.test.org
Restore Client: apache01.test.org
Storage: File
When: 2012-08-07 19:43:05
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
可以根據需要來修改這個還原指令,比如apache02的adduser檔案損壞了,我們可以調用apache01的檔案來修複它。
還有就是預設還原的位置在/tmp/bacula-restores,會在該目錄下生成這樣的子目錄結構:/tmp/bacula-restores/usr/sbin/adduser ,這樣便于比較,如果我們把還原的位置改為/ 根目錄,那麼備份檔案則會直接覆寫系統檔案,是以要慎重。
更簡單的操作bacula的辦法是用webmin,全網頁操作,不多講。
總之,bacula 是個非常容易上手的開源的專業網絡備份軟體。在使用之前最好把它的原理弄明白。
本文轉自 紫色葡萄 51CTO部落格,原文連結:http://blog.51cto.com/purplegrape/957651,如需轉載請自行聯系原作者