前面的博文里讲到了bacula服务器的快速搭建和客户端的部署(包含在ks部署脚本里),本文讲述bacula的基本操作,适合快速上手。
操作系统: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 = /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
- }
备份到哪里?,默认是/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/
- $ ls
- sbin/
- $ ls
- sbin/
- $ cd sbin
- cwd is: /usr/sbin/
- $ ls
- .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*
- OK to run? (yes/mod/no): yes
可以根据需要来修改这个还原命令,比如apache02的adduser文件损坏了,我们可以调用apache01的文件来修复它。
还有就是默认还原的位置在/tmp/bacula-restores,会在该目录下生成这样的子目录结构:/tmp/bacula-restores/usr/sbin/adduser ,这样便于比较,如果我们把还原的位置改为/ 根目录,那么备份文件则会直接覆盖系统文件,所以要慎重。
更简单的操作bacula的办法是用webmin,全网页操作,不多讲。
总之,bacula 是个非常容易上手的开源的专业网络备份软件。在使用之前最好把它的原理弄明白。