一、bacula的备份恢复过程之完全备份。
1.创建卷组

连接到bacula的控制端,执行备份恢复操作
[root@baculaserver etc]# /usr/local/bacula/sbin/bconsole
Connecting to Director 192.168.137.194:9101
1000 OK: baculaserver.test.com-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: dbsd
Enter new Volume name: cicro4
Automatically selected Pool: dbpool
Connecting to Storage daemon dbsd at 192.168.137.194:9103 ...
Sending label command for Volume "cicro4" Slot 0 ...
3000 OK label. VolBytes=222 DVD=0 Volume="cicro4" Device="dbdev" (/data/webdata)
Catalog record for Volume "cicro4", Slot 0  successfully created.
Requesting to mount dbdev ...
3906 File device ""dbdev" (/data/webdata)" is always mounted.


2.利用run命令执行备份操作
* run
A job name must be specified.
The defined Job resources are:
     1: Client1
     2: Client
     3: BackupCatalog
     4: RestoreFiles
Select Job resource (1-4): 1
Run Backup job
JobName:  Client1
Level:    Incremental
Client:   dbfd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2013-04-14 14:37:01
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=1

到此为止,可以开始备份,bacula-dir.conf配置文件中定义的Client1是一个增量备份,但是由于是第一次备份所以会做一个完全备份,第二次才会增量备份。

3.查看备份状态
* status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 1
baculaserver.test.com-dir Version: 5.2.6 (21 February 2012) x86_64-unknown-linux-gnu redhat
Daemon started 14-Apr-13 14:33. Jobs: run=1, running=0 mode=0,0
 Heap: heap=278,528 smbytes=77,452 max_bytes=91,121 bufs=251 max_bufs=287

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Differential   Backup    10  14-Apr-13 23:05    Client1            cicro4
Differential   Backup    10  14-Apr-13 23:05    Client             cicro4
Differential   Backup    10  14-Apr-13 23:05    BackupCatalog      cicro4
====

Running Jobs:
Console connected at 14-Apr-13 14:34
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     1  Full          3    4.035 M  OK       14-Apr-13 14:37 Client1

====

由于这里bacula将备份SD和控制端(DIR)在同一台服务器上,因此可以用过选项1来查看SD的状态
如果SD和控制端(DIR)不在同一台服务器上,要使用选项2来查看

到这里可以看出JobId 为1的 备份是一个完全备份,备份的数据文件有3个,大小为4.035M
备份完成时间为14-Apr-13 14:37。还可以通过Scheduled Jobs: 看出会在今天晚上23:05分做一次
增量备份。

如果利用run命令再次运行一次备份的话 我们查看状态,
* status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 1
baculaserver.test.com-dir Version: 5.2.6 (21 February 2012) x86_64-unknown-linux-gnu redhat
Daemon started 14-Apr-13 14:33. Jobs: run=2, running=0 mode=0,0
 Heap: heap=278,528 smbytes=79,966 max_bytes=93,635 bufs=252 max_bufs=288

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Differential   Backup    10  14-Apr-13 23:05    Client1            cicro4
Differential   Backup    10  14-Apr-13 23:05    Client             cicro4
Differential   Backup    10  14-Apr-13 23:05    BackupCatalog      cicro4
====

Running Jobs:
Console connected at 14-Apr-13 14:34
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     1  Full          3    4.035 M  OK       14-Apr-13 14:37 Client1
     2  Incr      1,882    7.625 M  OK       14-Apr-13 14:49 Client1

====

我们发现JobId为2的备份为一次增量备份。

4.差异备份功能
 执行备份,Client为我们在bucala-dir.conf中定义的。
* run
A job name must be specified.
The defined Job resources are:
     1: Client1
     2: Client
     3: BackupCatalog
     4: RestoreFiles
Select Job resource (1-4): 2
Run Backup job
JobName:  Client
Level:    Differential
Client:   dbfd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2013-04-14 14:55:48
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=3
You have messages.

查看备份状态。
* status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 1
baculaserver.test.com-dir Version: 5.2.6 (21 February 2012) x86_64-unknown-linux-gnu                                                                                    redhat
Daemon started 14-Apr-13 14:33. Jobs: run=3, running=0 mode=0,0
 Heap: heap=278,528 smbytes=87,502 max_bytes=96,019 bufs=264 max_bufs=289

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Differential   Backup    10  14-Apr-13 23:05    Client1            cicro4
Differential   Backup    10  14-Apr-13 23:05    Client             cicro4
Differential   Backup    10  14-Apr-13 23:05    BackupCatalog      cicro4
====

Running Jobs:
Console connected at 14-Apr-13 14:34
Console connected at 14-Apr-13 14:56
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     1  Full          3    4.035 M  OK       14-Apr-13 14:37 Client1
     2  Incr      1,882    7.625 M  OK       14-Apr-13 14:49 Client1
     3  Full      1,885    15.69 M  OK       14-Apr-13 14:55 Client

====
可以看到JobId为3的备份任务名字为Client,是一个完全备份。

在执行以下操作前我们在FD客户端需要备份的目录下增加一个文件。

再次运行备份

* run
A job name must be specified.
The defined Job resources are:
     1: Client1
     2: Client
     3: BackupCatalog
     4: RestoreFiles
Select Job resource (1-4): 2
Run Backup job
JobName:  Client
Level:    Differential
Client:   dbfd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2013-04-14 14:58:43
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=4
You have messages.

查看状态

*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 1
baculaserver.test.com-dir Version: 5.2.6 (21 February 2012) x86_64-unknown-linux-gnu redhat
Daemon started 14-Apr-13 14:33. Jobs: run=4, running=0 mode=0,0
 Heap: heap=278,528 smbytes=100,173 max_bytes=113,842 bufs=277 max_bufs=313

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Differential   Backup    10  14-Apr-13 23:05    Client1            cicro4
Differential   Backup    10  14-Apr-13 23:05    Client             cicro4
Differential   Backup    10  14-Apr-13 23:05    BackupCatalog      cicro4
====

Running Jobs:
Console connected at 14-Apr-13 14:34
Console connected at 14-Apr-13 14:56
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     1  Full          3    4.035 M  OK       14-Apr-13 14:37 Client1
     2  Incr      1,882    7.625 M  OK       14-Apr-13 14:49 Client1
     3  Full      1,885    15.69 M  OK       14-Apr-13 14:55 Client
     4  Diff          2    4.035 M  OK       14-Apr-13 14:58 Client

====

可以看到JobId为4,名字为Client的任务是一个差异备份。


5.bacula的完全备份数据恢复

我们通过上面的状态可以知道JobId为3的任务是一个完全备份
*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): 3
Enter JobId(s), comma separated, to restore: 3,4
You have selected the following JobIds: 3,4
#这里仅仅指定 差异备份的一个完全备份和差异备份的JobId就可以恢复数据
Building directory tree for JobId(s) 3,4 ...  +++++++++++++++++++++++++++++++++++++++++++++
1,745 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 *
1,886 files marked.
$ done
Bootstrap records written to /usr/local/bacula/var/bacula/working/baculaserver.test.com-dir.restore.1.bsr

The job will require the following
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================

    cicro4                    dbsd                      dbdev

Volumes marked with "*" are online.


1,886 files selected to be restored.

Defined Clients:  #指定恢复到那个FD上去
     1: dbfd
     2: dbfs1
Select the Client (1-2): 1
Run Restore job
JobName:         RestoreFiles
Bootstrap:       /usr/local/bacula/var/bacula/working/baculaserver.test.com-dir.restore.1.bsr
Where:           /data/bacula-Restores
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd
Restore Client:  dbfd
Storage:         dbsd
When:            2013-04-14 15:10:41
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): mod
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/var/bacula/working/baculaserver.test.com-dir.restore.1.bsr
Where:
Replace:         always
FileSet:         dbfs
Backup Client:   dbfd
Restore Client:  dbfd
Storage:         dbsd
When:            2013-04-14 15:10:41
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=5
*

6.增量备份恢复,增量备份的恢复我们只需要在Enter JobId(s), comma separated, to restore: 这一行
填入我们第一次完全备份的JobId号后后面每次增量备份的JobId号即可。