一、例項演示bacula的完全備份功能

1.建立卷組
執行如下命令,連線到bacula控制端,執行備份恢復操作:
 

  1. [root@baculaserver opt]#/opt/bacula/sbin/bconsole  
  2. Connecting to Director 192.168.12.188:9101  
  3. 1000 OK: f10-64-build-dir Version: 3.0.2 (18 July 2009)  
  4. Enter a period to cancel a command  
  5. *label  
  6. Automatically selected Storage: dbsd  
  7.  
  8. Enter new Volume name: cicro4   #卷組名稱,可隨意指定,指定完畢後會在  
  9. #bacula-dir.conf檔案的指定位置生成一個cicro4檔案  
  10. Defined Pools:  
  11.      1: dbpool  
  12.      2: Scratch  
  13. Select the Pool (1-2): 1  #指定卷組的放置位置,即為SD名稱。  
  14. #Dbpool在bacula-dir.conf中定義  
  15. Connecting to Storage daemon dbsd at 192.168.12.188:9103 ...  #由於指定SD在  
  16. #192.168.12.188主機上,因此將卷cicro4建立到了此主機上  
  17. Sending label command for Volume "cicro4" Slot 0 ...  
  18. 3000 OK label. VolBytes=191 DVD=0 Volume="cicro4" Device="dbdev" (/cicro/backup2)  
  19. Catalog record for Volume "cicro4", Slot 0  successfully created.  
  20. Requesting to mount dbdev ...  
  21. 3906 File device "dbdev" (/cicro/backup2) is always mounted.  

2.利用run命令執行備份操作
下面繼續在bacula控制端執行備份操作:
 

  1. *run  
  2. A job name must be specified.  
  3. The defined Job resources are:   
  4.      1: Client1  #這裡的Client1 是在bacula-dir.conf中定義的一個Job執行任務  
  5.      2: Client   #這裡的Client 也是在bacula-dir.conf中定義的一個Job執行任務  
  6.      3: BackupCatalog  
  7.      4: RestoreFiles  
  8. Select Job resource (1-2): 1  
  9. Run Backup job  
  10. JobName:  Client1  
  11. Level:    Incremental  
  12. Client:   dbfd  
  13. FileSet:  dbfs  
  14. Pool:     dbpool (From Job resource)  
  15. Storage:  dbsd (From Job resource)  
  16. When:     2009-08-21 13:40:13  
  17. Priority: 10  
  18. OK to run? (yes/mod/no): yes  
  19. Job queued. JobId=67 

到此為止,可以開始執行備份,在bacula-dir.conf檔案中定義的Client1是一個增量備份,因此這個備份只是個增量操作。由於這是第一個備份,因此預設Client1會做一個完全備,第二次備份時,才執行增量備份。
 

3.檢視備份狀態
在bacula控制端利用“status”可以檢視bacula的各種狀態,這裡檢視備份時Director端的一個狀態資訊。
 

  1. *status  
  2. Status available for:  
  3.      1: Director  
  4.      2: Storage  
  5.      3: Client  
  6.      4: All  
  7. Select daemon type for status (1-4): 1  
  8. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  9. Daemon started 21-Aug-09 13:22, 0 Jobs run since started.  
  10.  Heap: heap=241,664 smbytes=82,242 max_bytes=82,498 bufs=245 max_bufs=250 
  11.  
  12. Scheduled Jobs:  
  13. Level          Type     Pri  Scheduled          Name               Volume 
  14. ===============================================================================  
  15. Incremental    Backup    10  21-Aug-09 23:05    Client1                cicro4  
  16. Running Jobs:  
  17. Console connected at 21-Aug-09 13:37  
  18.  JobId Level   Name                       Status 
  19. ======================================================================  
  20. 67 Full    Client1.2009-08-21_13.40.16_07 is running  
  21. 由此可知,備份正在進行,備份完成再次檢視備份資訊,輸出如下:  
  22. *status  
  23. Status available for:  
  24.      1: Director  
  25.      2: Storage  
  26.      3: Client  
  27.      4: All  
  28. Select daemon type for status (1-4): 1    
  29. 由於這裡bacula將備份的儲存端(SD)和控制端(DIR)設定在一臺伺服器上,因此可以通過選項1“Director”來檢視SD的狀態,如果SD端和DIR端不在一臺伺服器上,要檢視選項2,即“Storage”。這裡選擇選項1r後輸出內容如下:  
  30. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  31. Daemon started 21-Aug-09 13:22, 1 Job run since started.  
  32.  Heap: heap=241,664 smbytes=73,891 max_bytes=84,825 bufs=212 max_bufs=250 
  33.  
  34. Scheduled Jobs:  
  35. Level          Type     Pri  Scheduled          Name               Volume 
  36. ===============================================================================  
  37. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  38.  
  39. Running Jobs:  
  40. Console connected at 21-Aug-09 13:42  
  41. No Jobs running.  
  42. Terminated Jobs:  
  43.  JobId  Level    Files      Bytes   Status   Finished        Name   
  44. ====================================================================  
  45.     58  Incr          2    46.85 M  OK       19-Aug-09 16:51 Client1  
  46.     59  Incr          2    3.908 M  OK       19-Aug-09 16:51 Client1  
  47.     60  Incr          2    8.377 K   OK       19-Aug-09 16:52 Client1  
  48.     61  Incr          1         0   OK       19-Aug-09 16:53 Client1  
  49.     62  Incr          2    8.344 K   OK       19-Aug-09 16:53 Client1  
  50.     63  Incr          2    8.377 K   OK       19-Aug-09 16:54 Client1  
  51.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  52.     65                1         0  OK       19-Aug-09 16:58 RestoreFiles  
  53.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  54. 67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  55.  

這裡可以看到,JobId為67的備份是一個完全備份,備份資料的檔案數為25個,備份壓縮後的大小為145.5MB,備份完成在“21-Aug-09 13:41”,最後的Client1是備份資源的名稱。

二、例項演示bacula的增量備份功能

在上面的操作中,設定的備份資源Job本身就是一個增量備份,下面執行的備份操作與上面完全相同,不同的是,這裡是第二次備份,bacula會按照設定執行增量備份,操作如下程式碼清單如下所示。
 執行增量備份

  1. * run  
  2. Automatically selected Catalog: MyCatalog  
  3. Using Catalog "MyCatalog"  
  4. A job name must be specified.  
  5. The defined Job resources are:  
  6.      1: Client1  
  7.      2: Client  
  8.      3: BackupCatalog  
  9.      4: RestoreFiles   
  10. Select Job resource (1-2): 1  
  11. Run Backup job  
  12. JobName:  Client1  
  13. Level:    Incremental  
  14. Client:   dbfd  
  15. FileSet:  dbfs  
  16. Pool:     dbpool (From Job resource)  
  17. Storage:  dbsd (From Job resource)  
  18. When:     2009-08-21 14:20:24  
  19. Priority: 10  
  20. OK to run? (yes/mod/no): yes  
  21. Job queued. JobId=68 
  22. *status  
  23. Status available for:  
  24.      1: Director  
  25.      2: Storage  
  26.      3: Client  
  27.      4: All  
  28. Select daemon type for status (1-4): 1  
  29. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  30. Daemon started 21-Aug-09 13:22, 2 Jobs run since started.  
  31.  Heap: heap=241,664 smbytes=84,576 max_bytes=97,749 bufs=218 max_bufs=252 
  32.  
  33. Scheduled Jobs:  
  34. Level          Type     Pri  Scheduled          Name               Volume 
  35. ===============================================================================  
  36. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  37.  
  38. Running Jobs:  
  39. Console connected at 21-Aug-09 14:19  
  40. No Jobs running.  
  41.  
  42. Terminated Jobs:  
  43.  JobId  Level    Files      Bytes   Status   Finished        Name   
  44. ====================================================================  
  45.     59  Incr          2    3.908 M  OK       19-Aug-09 16:51 Client1  
  46.     60  Incr          2    8.377 K  OK       19-Aug-09 16:52 Client1  
  47.     61  Incr          1         0   OK       19-Aug-09 16:53 Client1  
  48.     62  Incr          2    8.344 K  OK       19-Aug-09 16:53 Client1  
  49.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  50.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  51.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  52.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  53.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  54. 68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  55.  

從最後的備份列表可以看出,系統進行了增量備份,“3.908 M”就是上次備份與這次備份之間的資料增加量。而JobId =68這個備份的Level級別為Incr也說明了此次備份為增量備份。

三、例項演示bacula的差異備份功能

差異備份與增量備份的原理,前面已經介紹過了,這裡只給出具體的操作步驟。
 

1.開始執行備份
 

  1. *run  
  2. Automatically selected Catalog: MyCatalog  
  3. Using Catalog "MyCatalog"  
  4. A job name must be specified.  
  5. The defined Job resources are:  
  6.      1: Client1  
  7.      2: Client  
  8.      3: BackupCatalog  
  9.      4: RestoreFiles  
  10. Select Job resource (1-4): 2   #這裡有兩個Job任務可選,名為Client1的為增量  
  11. #備份操作,名為Client的為差異備份操作  
  12. Run Backup job  
  13. JobName:  Client  
  14. Level:    Differential  
  15. Client:   dbfd  
  16. FileSet:  dbfs  
  17. Pool:     dbpool (From Job resource)  
  18. Storage:  dbsd (From Job resource)  
  19. When:     2009-08-21 14:31:04  
  20. Priority: 10  
  21. OK to run? (yes/mod/no): yes  
  22. Job queued. JobId=69 
  23. You have messages.  
  24. 至此,開始執行差異備份,如果備份的資料量較大,可能需要一段時間才能完成備份。下面可以用“status”指令檢視備份的狀態。  
  25. 2.檢視備份狀態  
  26. *status  
  27. Status available for:  
  28.      1: Director  
  29.      2: Storage  
  30.      3: Client  
  31.      4: All  
  32. Select daemon type for status (1-4): 1  
  33. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  34. Daemon started 21-Aug-09 14:30, 0 Jobs run since started.  
  35.  Heap: heap=253,952 smbytes=67,810 max_bytes=68,066 bufs=267 max_bufs=272 
  36.  
  37. Scheduled Jobs:  
  38. Level          Type     Pri  Scheduled          Name               Volume 
  39. ===========================================================================  
  40. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  41. Incremental    Backup    10  21-Aug-09 23:05    Client             cicro4  
  42. Incremental    Backup    10  21-Aug-09 23:05    BackupCatalog      cicro4  
  43.  
  44. Running Jobs:  
  45. Console connected at 21-Aug-09 14:30  
  46.  JobId Level   Name                       Status 
  47. ======================================================================  
  48.     69 Full    Client.2009-08-21_14.31.10_03 is running  
  49. Terminated Jobs:  
  50.  JobId  Level    Files      Bytes   Status   Finished        Name   
  51. ====================================================================  
  52.     59  Incr          2    3.908 M  OK       19-Aug-09 16:51 Client1  
  53.     60  Incr          2    8.377 K  OK       19-Aug-09 16:52 Client1  
  54.     61  Incr          1         0   OK       19-Aug-09 16:53 Client1  
  55.     62  Incr          2    8.344 K  OK       19-Aug-09 16:53 Client1  
  56.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  57.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  58.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  59.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  60.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  61.     68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  62. 從上面可以看到,備份還沒有完成,備份狀態為running。  
  63. 等待幾分鐘,再次檢視備份狀態如下:  
  64. * status  
  65. Status available for:  
  66.      1: Director  
  67.      2: Storage  
  68.      3: Client  
  69.      4: All  
  70. Select daemon type for status (1-4): 1  
  71. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  72. Daemon started 21-Aug-09 14:30, 1 Job run since started.  
  73.  Heap: heap=253,952 smbytes=65,680 max_bytes=78,853 bufs=240 max_bufs=274 
  74.  
  75. Scheduled Jobs:  
  76. Level          Type     Pri  Scheduled          Name               Volume 
  77. ==========================================================================   
  78. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  79. Incremental    Backup    10  21-Aug-09 23:05    Client             cicro4  
  80. Incremental    Backup    10  21-Aug-09 23:05    BackupCatalog      cicro4  
  81.  
  82. Running Jobs:  
  83. Console connected at 21-Aug-09 14:30  
  84. No Jobs running.  
  85.  
  86. Terminated Jobs:  
  87.  JobId  Level    Files      Bytes   Status   Finished        Name   
  88. ====================================================================  
  89.     60  Incr          2    8.377 K  OK       19-Aug-09 16:52 Client1  
  90.     61  Incr          1         0   OK       19-Aug-09 16:53 Client1  
  91.     62  Incr          2    8.344 K  OK       19-Aug-09 16:53 Client1  
  92.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  93.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  94.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  95.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  96.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  97.     68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  98.     69  Full         26    149.4 M  OK       21-Aug-09 14:32 Client  
  99. 從這裡可以看到,JobId為69的備份已經完成,並且是一個完全備份,備份檔案大小為149.4MB,而完成此差異備份的Job任務名稱是Client。  
  100. 3.繼續執行備份操作  
  101. 在執行下面的操作前,首先在客戶端FD需要備份的資料夾下(根據前面的配置可知,應該是/cws3)增加一個大小為3.8MB左右的檔案。  
  102. * run     
  103. A job name must be specified.  
  104. The defined Job resources are:  
  105.      1: Client1  
  106.      2: Client  
  107.      3: BackupCatalog  
  108.      4: RestoreFiles  
  109. Select Job resource (1-4): 2  
  110. Run Backup job  
  111. JobName:  Client  
  112. Level:    Differential  
  113. Client:   dbfd  
  114. FileSet:  dbfs  
  115. Pool:     dbpool (From Job resource)  
  116. Storage:  dbsd (From Job resource)  
  117. When:     2009-08-21 14:34:25  
  118. Priority: 10  
  119. OK to run? (yes/mod/no): yes  
  120. Job queued. JobId=70 
  121. *status  
  122. Status available for:  
  123.      1: Director  
  124.      2: Storage  
  125.      3: Client  
  126.      4: All  
  127. Select daemon type for status (1-4): 1  
  128. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  129. Daemon started 21-Aug-09 14:30, 2 Jobs run since started.  
  130.  Heap: heap=253,952 smbytes=67,989 max_bytes=81,162 bufs=240 max_bufs=274 
  131.  
  132. Scheduled Jobs:  
  133. Level          Type     Pri  Scheduled          Name               Volume 
  134. ===========================================================================  
  135. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  136. Incremental    Backup    10  21-Aug-09 23:05    Client             cicro4  
  137. Incremental    Backup    10  21-Aug-09 23:05    BackupCatalog      cicro4  
  138.  
  139. Running Jobs:  
  140. Console connected at 21-Aug-09 14:30  
  141. No Jobs running.  
  142.  
  143. Terminated Jobs:  
  144.  JobId  Level    Files      Bytes   Status   Finished        Name   
  145. ====================================================================  
  146.     61  Incr          1         0   OK       19-Aug-09 16:53 Client1  
  147.     62  Incr          2    8.344 K  OK       19-Aug-09 16:53 Client1  
  148.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  149.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  150.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  151.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  152.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  153.     68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  154.     69  Full         26    149.4 M  OK       21-Aug-09 14:32 Client  
  155.     70  Diff          2    3.908 M  OK       21-Aug-09 14:34 Client  
  156.  

從JobId為70的備份資訊可以看出,此備份為差異增量備份,此次進行差異備份的資料量大小剛好為3.908 MB,與前面增加的檔案大小基本相同。
為了證明是前面執行的是差異增量備份,在FD端需要備份的資料夾下再次增加一個大小為3.8MB左右的一個檔案,繼續執行以下備份操作:
 

  1. *run  
  2. A job name must be specified.  
  3. The defined Job resources are:  
  4.      1: Client1  
  5.      2: Client  
  6.      3: BackupCatalog  
  7.      4: RestoreFiles  
  8. Select Job resource (1-4): 2  
  9. Run Backup job  
  10. JobName:  Client  
  11. Level:    Differential  
  12. Client:   dbfd  
  13. FileSet:  dbfs  
  14. Pool:     dbpool (From Job resource)  
  15. Storage:  dbsd (From Job resource)  
  16. When:     2009-08-21 14:34:59  
  17. Priority: 10  
  18. OK to run? (yes/mod/no): yes  
  19. Job queued. JobId=71 
  20. *status  
  21. Status available for:  
  22.      1: Director  
  23.      2: Storage  
  24.      3: Client  
  25.      4: All  
  26. Select daemon type for status (1-4): 1  
  27. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  28. Daemon started 21-Aug-09 14:30, 3 Jobs run since started.  
  29.  Heap: heap=253,952 smbytes=69,087 max_bytes=82,260 bufs=240 max_bufs=274 
  30.  
  31. Scheduled Jobs:  
  32. Level          Type     Pri  Scheduled          Name               Volume 
  33. ===========================================================================  
  34. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  35. Incremental    Backup    10  21-Aug-09 23:05    Client             cicro4  
  36. Incremental    Backup    10  21-Aug-09 23:05    BackupCatalog      cicro4  
  37.  
  38. Running Jobs:  
  39. Console connected at 21-Aug-09 14:30  
  40. No Jobs running.  
  41.  
  42. Terminated Jobs:  
  43.  JobId  Level    Files      Bytes   Status   Finished        Name   
  44. ====================================================================  
  45.     62  Incr          2    8.344 K  OK       19-Aug-09 16:53 Client1  
  46.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  47.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  48.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  49.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  50.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  51.     68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  52.     69  Full         26    149.4 M  OK       21-Aug-09 14:32 Client  
  53.     70  Diff          2    3.908 M  OK       21-Aug-09 14:34 Client  
  54.     71  Diff          3    7.817 M  OK       21-Aug-09 14:35 Client  
  55.  

由JobId為71的備份可以看出,此次備份的大小為7.817 M,剛好是上次差異增量備份的大小與此次增加檔案的大小之和,由此證明確實為差異備份。
第三次在FD端需要備份的資料夾下增加一個大小為3.8M左右的一個檔案,繼續執行備份操作:
 

  1. *run  
  2. A job name must be specified.  
  3. The defined Job resources are:  
  4.      1: Client1  
  5.      2: Client  
  6.      3: BackupCatalog  
  7.      4: RestoreFiles  
  8. Select Job resource (1-4): 2  
  9. Run Backup job  
  10. JobName:  Client  
  11. Level:    Differential  
  12. Client:   dbfd  
  13. FileSet:  dbfs  
  14. Pool:     dbpool (From Job resource)  
  15. Storage:  dbsd (From Job resource)  
  16. When:     2009-08-21 14:35:32  
  17. Priority: 10  
  18. OK to run? (yes/mod/no): yes  
  19. Job queued. JobId=72 
  20. *status  
  21. Status available for:  
  22.      1: Director  
  23.      2: Storage  
  24.      3: Client  
  25.      4: All  
  26. Select daemon type for status (1-4): 1  
  27. f10-64-build-dir Version: 3.0.2 (18 July 2009) x86_64-unknown-linux-gnu redhat   
  28. Daemon started 21-Aug-09 14:30, 4 Jobs run since started.  
  29.  Heap: heap=253,952 smbytes=69,087 max_bytes=82,260 bufs=240 max_bufs=274 
  30.  
  31. Scheduled Jobs:  
  32. Level          Type     Pri  Scheduled          Name               Volume 
  33. ===========================================================================  
  34. Incremental    Backup    10  21-Aug-09 23:05    Client1            cicro4  
  35. Incremental    Backup    10  21-Aug-09 23:05    Client             cicro4  
  36. Incremental    Backup    10  21-Aug-09 23:05    BackupCatalog      cicro4  
  37.  
  38. Running Jobs:  
  39. Console connected at 21-Aug-09 14:30  
  40. No Jobs running.  
  41.  
  42. Terminated Jobs:  
  43.  JobId  Level    Files      Bytes   Status   Finished        Name   
  44. ====================================================================  
  45.     63  Incr          2    8.377 K  OK       19-Aug-09 16:54 Client1  
  46.     64                3    77.44 K  OK       19-Aug-09 16:57 RestoreFiles  
  47.     65                1         0   OK       19-Aug-09 16:58 RestoreFiles  
  48.     66                2    38.77 K  OK       19-Aug-09 16:59 RestoreFiles  
  49.     67  Full         25    145.5 M  OK       21-Aug-09 13:41 Client1  
  50.     68  Incr          2    3.908 M  OK       21-Aug-09 14:20 Client1  
  51.     69  Full         26    149.4 M  OK       21-Aug-09 14:32 Client  
  52.     70  Diff          2    3.908 M  OK       21-Aug-09 14:34 Client  
  53.     71  Diff          3    7.817 M  OK       21-Aug-09 14:35 Client  
  54.     72  Diff          4    11.72 M  OK       21-Aug-09 14:35 Client  
  55.  

第三次執行備份,從JobId為72的備份可以很清楚地看出差異備份與增量備份的差別。