當(dāng)前位置: 首頁(yè)IT技術(shù) → 利用bacula完成數(shù)據(jù)的備份恢復(fù)

利用bacula完成數(shù)據(jù)的備份恢復(fù)

更多

一、bacula概述

1.bacula的組件
  bacula,被譽(yù)為開源軟件中最好的備份還原軟件,它提供了企業(yè)級(jí)的客戶機(jī)/服務(wù)器的備份解決方案,能夠通過(guò)網(wǎng)絡(luò)來(lái)管理文件的備份,恢復(fù)和核實(shí)工作.既有windows版本的,也有Linux,Unix的.
一個(gè)完整的bacula備份系統(tǒng),由以下五個(gè)主要部分或服務(wù)組成:
Directory:  管理所有備份,恢復(fù),驗(yàn)證,和存檔事務(wù),定制備份和恢復(fù)文件的計(jì)劃.
Storge:     指定進(jìn)行存儲(chǔ)和恢復(fù)文件屬性和數(shù)據(jù)的物理備份媒介.
File:       安裝在被備份機(jī)器上的程序,將被directory調(diào)用時(shí)候,它提供關(guān)于自己的操作系統(tǒng)、文件屬性、數(shù)據(jù)等資料.
Console:    管理控制臺(tái),與directory進(jìn)行通訊.
Catalog: 負(fù)責(zé)維護(hù)所有備份文件的索引和數(shù)據(jù)庫(kù).Catalog服務(wù)允許系統(tǒng)管理員或用戶能夠快速地找到并恢復(fù)任何需要的檔案。catalog服務(wù)是Bacula和簡(jiǎn)單的tar,bru備份命令的主要區(qū)別,因?yàn)閏atalog維護(hù)所有Volume使用情況的記錄,所有任務(wù)的運(yùn)行情況,和所有檔案的保存情況,允許有效的恢復(fù)和Volume管理。 Bacula目前支持的三個(gè)數(shù)據(jù)庫(kù)(postgresql、mysql、sqlite),在安裝Bacula時(shí),必須選擇其中之一。
Monitor:   監(jiān)控directory、file、storage的守護(hù)進(jìn)程
 


bacula各個(gè)組成部分的關(guān)聯(lián)性
 
2. 部署結(jié)構(gòu)
主機(jī)名          ip地址          應(yīng)用角色               OS  
baculaserver    192.168.32.30   Director、SD、Console  rhel5.5
baculaclient    192.168.32.31   FD                     rhel5.5
 
二、安裝
1.bacula服務(wù)器端安裝和初始化
1.1. bacula軟件安裝
[root@baculaserver ~]# tar -zxf bacula-5.0.1.tar.gz
[root@baculaserver ~]# cd bacula-5.0.1
[root@baculaserver bacula-5.0.1]# ./configure --prefix=/usr/local/bacula --with-mysql 
#指定安裝路徑和所用數(shù)據(jù)庫(kù)
[root@baculaserver bacula-5.0.1]# make && make install
 
1.2 MySQL數(shù)據(jù)庫(kù)初始化
[root@baculaserver ~]# cd /usr/local/bacula/etc
[root@baculaserver etc]# ./grant_mysql_privileges
[root@baculaserver etc]# ./create_mysql_database
[root@baculaserver etc]# ./make_mysql_tables
#在執(zhí)行上面三行mysql初始化時(shí),默認(rèn)由數(shù)據(jù)庫(kù)管理員root執(zhí)行,因此可能需要輸入root密碼或設(shè)置root密碼為空。
 
2.bacula客戶端安裝
[root@baculaclient ~]# tar -zxf bacula-5.0.1.tar.gz
[root@baculaclient ~]# cd bacula-5.0.1
[root@baculaclient bacula-5.0.1]# ./configure --prefix=/usr/local/bacula --enable-client-only 
#指定安裝路徑,和只安裝客戶端組件
[root@baculaclient bacula-5.0.1]# make && make install
 
三、bacula的配置
1. bacula的console端配置(bconsole.conf)
[root@baculaserver etc]# vim bconsole.conf
# Bacula User Agent (or Console) Configuration File
#
Director {
  Name = 2012-02-15-dir     #主控臺(tái)名稱,自定義,要求與bacula-dir.conf中定義相同
  DIRport = 9101            #控制臺(tái)服務(wù)器端口
  address = 192.168.32.30   #控制臺(tái)服務(wù)器IP,不要用localhost
  Password = "xgjYPXCfgFT6ZS/9tQQTtfrFZ90CFFfIcj+qDKm8FpO0"  #控制臺(tái)密碼
}
 
2. bacula的Director端配置(bacula-dir.conf)
2.1 bacula-dir.conf的組成
bacula-dir.conf是Director端的配置文件,也是bacula的核心配置文件,該文件由以下10個(gè)邏輯端組成:
Director:定義全局設(shè)置
Catalog:定義后臺(tái)數(shù)據(jù)庫(kù)
Jobdefs:定義默認(rèn)執(zhí)行任務(wù)
Job:自定義一個(gè)備份或恢復(fù)任務(wù)
Fileset:定義備份哪些數(shù)據(jù),不備份哪些數(shù)據(jù)
Schedule:定義備份時(shí)間策略
Pool:定義供Job使用的池屬性
Client:定義要備份的客戶端
Storage:定義數(shù)據(jù)的存儲(chǔ)方式
Messages:定義發(fā)送日志報(bào)告和日志的記錄
 
2.2 bacula-dir.conf配置
[root@baculaserver etc]# vim bacula-dir.conf
Director {                            #控制臺(tái)的全局配置
  Name = 2012-02-15-dir               #定義控制臺(tái)名稱,要與sd、fa的Director相同
  DIRport = 9101                      # Director的服務(wù)端口
  QueryFile = "/usr/local/bacula/etc/query.sql"
  WorkingDirectory = "/usr/local/bacula/var/bacula/working"
  PidDirectory = "/var/run"
  Maximum Concurrent Jobs = 1        #一次能處理的最大并發(fā)數(shù)
  Password = "xgjYPXCfgFT6ZS/9tQQTtfrFZ90CFFfIcj+qDKm8FpO0"       #控制臺(tái)密碼,要與bconsole.conf中Director密碼相同
  Messages = Daemon                  #日志輸出方式,“Daemon”在下面Messages邏輯段中定義
}
 
#JobDefs {                           #JobDefs類似一個(gè)模板,并不是真正創(chuàng)建一個(gè)任務(wù),只為Job提供一個(gè)默認(rèn)的配置,當(dāng)前Job明確定義的任何值,將會(huì)覆蓋沖突的JobDefs值.
#  Name = "DefaultJob"          
#  Type = Backup                
#  Level = Incremental          
#  Client = 2012-02-15-fd       
#  FileSet = "Full Set"         
#  Schedule = "WeeklyCycle"     
#  Storage = File
#  Messages = Standard
#  Pool = File
#  Priority = 10
#  Write Bootstrap = "/usr/local/bacula/var/bacula/working/%c.bsr"
#}
 
 
Job {                           #備份任務(wù),注意注釋標(biāo)號(hào),可按照該標(biāo)號(hào)與后面各邏輯端定義相對(duì)應(yīng)
  Name = webjob                 #備份job的名字,這個(gè)可以隨便起,在后面的備份操作的時(shí)候可以看到
  Type= backup                  #可用類型有backup,restore,verify,admin
  Client= 2012-02-15-fd         #1.要備份的客戶端,“2012-02-15-fd”在后面的Client邏輯段定義
  FileSet = dbfs            #2.要備份的客戶端數(shù)據(jù),“dbfs”在后面的FileSet邏輯段定義
  schedule = dbscd              #3.備份任務(wù)的執(zhí)行時(shí)間策略,“dbscd”在后面的Schedule邏輯段定義
  Storage = dbsd            #4.備份數(shù)據(jù)的存儲(chǔ)介質(zhì)和路徑,“dbsd”在后面的Storage邏輯段定義
  Messages = Daemon         
  Pool = dbpool             #5.pool屬性,“dbpool”在后面的Pool邏輯段定義
  Level = Incremental         #備份類型,可用的值是FULL(完全備份),incremental(增量備份),differential(差異備份),如第一次沒(méi)做完全備份,則先進(jìn)行完全備份后再執(zhí)行Incremental
  Priority = 10                #優(yōu)先級(jí)
  Write Bootstrap = "/usr/local/bacula/var/bacula/working/%c.bsr"   #指定備份的引導(dǎo)信息路徑
}
 
#Job {                        #定義一個(gè)Catalog備份任務(wù),確?刂贫藗浞輸(shù)據(jù)庫(kù)的安全
#  Name = "BackupCatalog"        
#  JobDefs = "DefaultJob"
#  Level = Full
#  FileSet="Catalog"
#  Schedule = "WeeklyCycleAfterBackup"
#  # This creates an ASCII copy of the catalog
#  # Arguments to make_catalog_backup.pl are:
#  #  make_catalog_backup.pl <catalog-name>
#  RunBeforeJob = "/usr/local/bacula/etc/make_catalog_backup.pl MyCatalog"
#  # This deletes the copy of the catalog
#  RunAfterJob  = "/usr/local/bacula/etc/delete_catalog_backup"
#  Write Bootstrap = "/usr/local/bacula/var/bacula/working/%n.bsr"
#  Priority = 11                   # run after main backup
#}
 
Job {                         #定義一個(gè)還原任務(wù)
  Name = "Restoreweb"           
  Type = Restore
  Client=2012-02-15-fd                
  FileSet="dbfs"                 
  Storage = dbsd                     
  Pool = dbpool
  Messages = Standard
  Where = /home/bacula      #指定默認(rèn)恢復(fù)數(shù)據(jù)到這個(gè)路徑,注意:還原客戶端數(shù)據(jù)時(shí),默認(rèn)會(huì)將數(shù)據(jù)存放在客戶端/home/bacula下。如不指定,默認(rèn)會(huì)還原的原數(shù)據(jù)所在地
}
 
 
FileSet {                  #2.定義名為dbfs要備份的客戶端數(shù)據(jù),即指定需要備份哪些數(shù)據(jù),需要排除哪些數(shù)據(jù),可指定多個(gè)FileSet
  Name = "dbfs"
  Include {
    Options {
#     Compression=GZIP     #對(duì)備份文件進(jìn)行g(shù)zip的壓縮
      signature = MD5      #驗(yàn)證方式為MD5碼的方式
    }
    File = /var/www       #指定客戶端需要備份的文件或目錄
  }
 
  Exclude {               #排除不需要備份的文件或目錄
    File = /var/www/cgi-bin 
    File = /var/www/error
    File = /var/www/icons
  }
}
 
Schedule {                 #3.備份任務(wù)的執(zhí)行時(shí)間策略,定義名為dbscd的備份任務(wù)調(diào)度策略
    Name = dbscd
    Run = Level=Full mon at 7:00         #在周一7點(diǎn)作一次全備份
    Run = Level=Full fri at 7:00         #在周五7點(diǎn)作一次全備份
    Run = Level=Differential sat at 7:00     #在周六7點(diǎn)作一次差異備份
    Run = Level=Differential sun at 7:00     #在周日7點(diǎn)作一次差異備份
    Run = Level=Differential tue-thu at 7:00     #在周二到周四7點(diǎn)作差異備份
}
 
#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 = "/usr/local/bacula/var/bacula/working/bacula.sql"
  }
}
 
Client {                             #1.要備份的客戶端
  Name = 2012-02-15-fd
  Address = 192.168.32.31
  FDPort = 9102
  Catalog = MyCatalog                 #記錄客戶機(jī)備份情況的日志名,后面Catalog邏輯段定義
  Password = "d1+RTcYIpa7YYB2/SrhRp/BAB7lBSF/Rl7wgrkSb52A2"          # Director與FD的驗(yàn)證密碼,必須與bacula-fd.conf中密碼相同
  File Retention = 30 days            # 指定保存在數(shù)據(jù)庫(kù)中的記錄多久循環(huán)一次,這里30天,只影響數(shù)據(jù)庫(kù)中的記錄,不影響備份的文件
  Job Retention = 6 months            # job的保持周期,應(yīng)大于File Retention的值   
  AutoPrune = yes                     # 當(dāng)達(dá)到指定的保存周期時(shí),是否自動(dòng)刪除數(shù)據(jù)庫(kù)中記錄,yes表自動(dòng)清除過(guò)期的job
}
 
 
 
Storage {                             #4.備份數(shù)據(jù)的存儲(chǔ)介質(zhì)和路徑;Storage用來(lái)指定將客戶端數(shù)據(jù)備份到哪個(gè)存儲(chǔ)設(shè)備上。
  Name = dbsd
  Address = 192.168.32.30             #存儲(chǔ)端SD的IP地址
  SDPort = 9103
  Password = "w6YqAfWkU7NMxRJ8s/8y5kUffGpysot4vt9HVQjE9bQy"  #Director端與SD的通訊密碼,必須與bacula-sd.conf中Director段密碼相同
  Device = dbdev                     #指定數(shù)據(jù)備份介質(zhì),必須與存儲(chǔ)SD端的bacula-sd.conf中Device邏輯端的Name相同
  Media Type = File                  #指定數(shù)據(jù)備份介質(zhì)類別,必須與存儲(chǔ)SD端的bacula-sd.conf中Device邏輯端的Media Type相同
}
 
Catalog {               #Catalog邏輯段用來(lái)定義關(guān)于日志和數(shù)據(jù)庫(kù)的設(shè)定
  Name = MyCatalog
  dbname = "bacula"; dbuser = "bacula"; dbpassword = ""
}
 
Messages {             #Messages邏輯段用來(lái)設(shè)定Director端如何保存日志,日志格式,可以將日志信息發(fā)送給管理員,要求開啟sendmail服務(wù)。
  Name = Standard
 
  mailcommand = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
  mail = root@localhost = all, !skipped           
  operator = root@localhost = mount
  console = all, !skipped, !saved
  append = "/usr/local/bacula/var/bacula/working/log" = all, !skipped
  catalog = all
}
 
 
Messages {
  Name = Daemon
  mailcommand = "/usr/local/bacula/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
  mail = root@localhost = all, !skipped           
  console = all, !skipped, !saved
  append = "/usr/local/bacula/var/bacula/working/log" = all, !skipped
}
 
#Pool {
#  Name = Default
#  Pool Type = Backup
#  Recycle = yes                       # Bacula can automatically recycle Volumes
#  AutoPrune = yes                     # Prune expired volumes
#  Volume Retention = 365 days         # one year
#}
 
Pool {                                #6.定義job任務(wù)使用的池屬性信息,如:設(shè)定文件過(guò)期時(shí)間,是否覆蓋過(guò)去備份數(shù)據(jù),是否自動(dòng)清除過(guò)去備份等。
  Name = dbpool
  Pool Type = Backup
  Recycle = yes                       # 重復(fù)使用
  AutoPrune = yes                     # 自動(dòng)清除過(guò)去備份
  Volume Retention = 365 days         # 備份文件保存時(shí)間
  Maximum Volume Jobs =1              # 每次執(zhí)行備份任務(wù)創(chuàng)建一個(gè)備份文件。
  Maximum Volume Bytes = 50G          # 限制備份文件文件最大值
  Maximum Volumes = 100               # 最多保存多少個(gè)備份文件
  Recycle Current Volume = yes        # 使用最近過(guò)期的文件存儲(chǔ)新備份
  Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"  #設(shè)定備份文件命名格式
}
 
#Pool {
#  Name = Scratch
#  Pool Type = Backup
#}
 
Console {                         #限定console利用tray-monitor獲取diretor的狀態(tài)信息
  Name = 2012-02-15-mon
  Password = "1tcj5GjpmPFP6M46JgjYzhiDsdC3br/4fDzKuH9kQRlz"
  CommandACL = status, .status
}
 
3. bacula的SD配置(bacula-sd.conf)
[root@baculaserver etc]# vim bacula-sd.conf
Storage {                             # 定義存儲(chǔ),本例2012-02-15-sd
  Name = 2012-02-15-sd
  SDPort = 9103                       # 服務(wù)端口   
  WorkingDirectory = "/usr/local/bacula/var/bacula/working"
  Pid Directory = "/var/run"
  Maximum Concurrent Jobs = 20
}
 
Director {                        #定義一個(gè)控制StorageDaemon的控制臺(tái)Director
  Name = 2012-02-15-dir           #該值必須與bacula-dir.conf中Director邏輯段內(nèi)定義相同
  Password = "w6YqAfWkU7NMxRJ8s/8y5kUffGpysot4vt9HVQjE9bQy"   #必須與bacula-dir.conf中Storage邏輯端定義password相同
}
 
Director {                      #定義一個(gè)監(jiān)控端的Director
  Name = 2012-02-15-mon         #必須與bacula-dir.conf中Console邏輯段內(nèi)定義相同
  Password = "1tcj5GjpmPFP6M46JgjYzhiDsdC3br/4fDzKuH9kQRlz"   #必須與bacula-dir.conf中Console邏輯段內(nèi)定義password相同
  Monitor = yes
}
 
Device {
  Name = dbdev                         #定義device,名稱與Director端配置文件bacula-dir.conf中的Storage邏輯端Device相同
  Media Type = File                    #存儲(chǔ)介質(zhì)類型,file表示文件系統(tǒng)存儲(chǔ)
  Archive Device = /home/webbak        #指定存儲(chǔ)介質(zhì),可以使cd、dvd、tap等,這里是將備份文件保存在/home/webak目錄下
  LabelMedia = yes;                    #通過(guò)Label建立卷文件
  Random access = Yes;                 #是否采用隨機(jī)訪問(wèn)存儲(chǔ)介質(zhì),
  AutomaticMount = yes;                # 存儲(chǔ)設(shè)備打開是,是否自動(dòng)使用他
  RemovableMedia = no;                 #是否支持移動(dòng)設(shè)備,如tap,cd等
  AlwaysOpen = no;                     #是否確保tap設(shè)備總是可用
}
 
Messages {                            #為存儲(chǔ)端SD定義一個(gè)日志或消息出來(lái)機(jī)制
  Name = Standard
  director = 2012-02-15-dir = all
}
                                                        
4. bacula的FD端配置(bacula-fd.conf)
[root@balucaclient etc]# vim bacula-fd.conf
Director {
  Name = 2012-02-15-dir         #定義一個(gè)允許連接FD的控制端,必須與bacula-dir.conf中Director邏輯端名稱相同
  Password = "d1+RTcYIpa7YYB2/SrhRp/BAB7lBSF/Rl7wgrkSb52A2"  #必須與bacula-dir.conf中Client邏輯端密碼相同
}
 
#
# Restricted Director, used by tray-monitor to get the
#   status of the file daemon
#
Director {
  Name = 2012-02-15-mon      #定義一個(gè)允許連接FD的監(jiān)控端Console
  Password = "1tcj5GjpmPFP6M46JgjYzhiDsdC3br/4fDzKuH9kQRlz"   #必須與bacula-dir.conf中Console邏輯段內(nèi)定義password相同
  Monitor = yes
}
 
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # 定義一個(gè)FD端
  Name = 2012-02-15-fd
  FDport = 9102                       # 監(jiān)控端口
  WorkingDirectory = /usr/local/bacula/var/bacula/working
  Pid Directory = /var/run
  Maximum Concurrent Jobs = 20
}
 
# Send all messages except skipped files back to Director
Messages {
  Name = Standard
  director = balucaclient-dir = all, !skipped, !restored
}
 
四、 bacula服務(wù)的啟動(dòng) 
1. 在服務(wù)器端啟動(dòng)bacula的Director Daemon和Storage Daemon
1.1 啟動(dòng)方式一
[root@baculaserver etc]#/usr/local/bacula/etc/bacula {start|stop|restart|status}
 
1.2 啟動(dòng)方式二:分別管理各個(gè)配置端的方式,依次啟動(dòng)或關(guān)閉每個(gè)服務(wù)
[root@baculaserver etc]#/usr/local/bacula/etc/bacula-dir {start|stop|restart|status}
[root@baculaserver etc]#/usr/local/bacula/etc/bacula-sd {start|stop|restart|status}
[root@baculaserver etc]#/usr/local/bacula/etc/bacula-fd {start|stop|restart|status}  
#由于fd端在baculaclient上,在此無(wú)需自動(dòng)bacula-fd服務(wù)
[root@baculaserver etc]# netstat -tnpl | grep 910
tcp   0      0 0.0.0.0:9101                0.0.0.0:*                   LISTEN      1507/bacula-dir  
tcp   0      0 0.0.0.0:9102                0.0.0.0:*                   LISTEN      1333/bacula-fd   
tcp    0      0 0.0.0.0:9103                0.0.0.0:*                   LISTEN      1323/bacula-sd 
#在啟動(dòng)bacula的所有服務(wù)前,必須啟動(dòng)MySQL數(shù)據(jù)庫(kù),否則連接bacula的控制端是會(huì)報(bào)錯(cuò)。
 
2. 在客戶端啟動(dòng)bacula的File Daemon
[root@baculaserver etc]#/usr/local/bacula/etc/bacula {start|stop|restart|status}
[root@baculaserver etc]#/usr/local/bacula/etc/bacula-fd {start|stop|restart|status} 
#由于baculaclient只做fd端,在此只需啟動(dòng)bacula-fd服務(wù)即可
 
五、bacula備份文件
1. 創(chuàng)建卷組
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.32.30:9101
1000 OK: 2012-02-15-dir Version: 5.0.1 (24 February 2010)
Enter a period to cancel a command.
*label           #創(chuàng)建一個(gè)卷組
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: dbsd
Enter new Volume name: webbak        #卷組名稱,可隨意指定,指定完畢后,會(huì)在bacula-dir.conf中Device邏輯字段指定的/home/webbak下生成一個(gè)文件
Automatically selected Pool: dbpool
Connecting to Storage daemon dbsd at 192.168.32.30:9103 ...
Sending label command for Volume "webbak" Slot 0 ...
3000 OK label. VolBytes=202 DVD=0 Volume="webbak" Device="dbdev" (/home/webbak)
Catalog record for Volume "webbak", Slot 0  successfully created.
Requesting to mount dbdev ...
3906 File device "dbdev" (/home/webbak) is always mounted.
You have messages.
#只有在使用磁帶卷時(shí)才需要這樣,而像我們剛才使用的磁盤卷,Bacula是可以自動(dòng)進(jìn)行l(wèi)abel的。想要?jiǎng)h除測(cè)試數(shù)據(jù)的話,就將/tmp目錄下的卷直接刪除,再使用drop_mysql_tables和make_mysql_tables腳本  
                                                                                                  
2. 執(zhí)行備份
2.1 第一次增量備份,默認(rèn)會(huì)是一個(gè)完全備份  #備份前fd中文件有index1.html
*run
A job name must be specified.
The defined Job resources are:
     1: webjob
     2: Restoreweb
Select Job resource (1-2): 1        #選擇備份任務(wù)
Run Backup job
JobName:  webjob
Level:    Incremental
Client:   2012-02-15-fd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2012-02-15 23:29:58
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=1          
#到處為止,可以開始備份了,在bacula-dir.conf文件中定義的webjob是一個(gè)增量備份,因此這個(gè)備份只是一個(gè)增量操作,由于是第一個(gè)備份,因此默認(rèn)webjob會(huì)做一個(gè)完全備份,第二次備份時(shí)才執(zhí)行增量備份
 
2.2 第二次增量備份,只做增量操作 #備份前fd中文件有index1.html、index2.html                                                                                                         
*run
A job name must be specified.
The defined Job resources are:
     1: webjob
     2: Restoreweb
Select Job resource (1-2): 1
Run Backup job
JobName:  webjob
Level:    Incremental
Client:   2012-02-15-fd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2012-02-15 23:37:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=2                                                                                                                              
#這是第二備份,只做一個(gè)增量操作
 
2.3 第三次備份,手動(dòng)改為差異備份  #備份前fd中文件有index1.html、index2.html 、index3.html
*run
A job name must be specified.
The defined Job resources are:
     1: webjob
     2: Restoreweb
Select Job resource (1-2): 1
Run Backup job
JobName:  webjob
Level:    Incremental
Client:   2012-02-15-fd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2012-02-15 23:40:15
Priority: 10
OK to run? (yes/mod/no): mod         #mod修改備份任務(wù)參數(shù)
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: When
     7: Priority
     8: Pool
     9: Plugin Options
Select parameter to modify (1-9): 1   #1表示選擇備份類別
Levels:
     1: Full
     2: Incremental
     3: Differential
     4: Since
     5: VirtualFull
Select level (1-5): 3                 #3表示差異備份
Run Backup job
JobName:  webjob
Level:    Differential
Client:   2012-02-15-fd
FileSet:  dbfs
Pool:     dbpool (From Job resource)
Storage:  dbsd (From Job resource)
When:     2012-02-15 23:40:15
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=3
 
3. 查看備份狀態(tài)
*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 1
2012-02-15-dir Version: 5.0.1 (24 February 2010) i686-pc-linux-gnu redhat Enterprise release
Daemon started 15- 212 23:05, 3 Jobs run since started.
 Heap: heap=258,048 smbytes=65,799 max_bytes=113,185 bufs=204 max_bufs=231
 
Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Differential   Backup    10  16- 212 07:00  webjob             *unknown*
====
 
Running Jobs:
Console connected at 15- 212 23:40
No Jobs running.
====
 
Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     1  Full          3         5   OK       15- 212 23:30 webjob
     2  Incr          2         5   OK       15- 212 23:37 webjob
     3  Diff          3         9   OK       15- 212 23:40 webjob
#顯示備份任務(wù)webjob第一次為full完全備份,第二次為增量備份,第三次為差異備份。
 
4.查看備份文件
[root@baculaserver etc]# ls -ls /home/webbak/
總計(jì) 12
4 -rw-r----- 1 root root 825 02-15 23:37 db-2012-02-15-id2
4 -rw-r----- 1 root root 969 02-15 23:40 db-2012-02-15-id3   
4 -rw-r----- 1 root root 900 02-15 23:30 webbak               #label產(chǎn)生的卷組文件
 
六、bacula恢復(fù)文件
1. 利用差異備份進(jìn)行完全恢復(fù)
[root@balucaclient etc]# rm -rf /var/www/html/*   #刪除fd中所有文件
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.32.30:9101
1000 OK: 2012-02-15-dir Version: 5.0.1 (24 February 2010)
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): 3
Enter JobId(s), comma separated, to restore: 1,3
You have selected the following JobIds: 1,3
#從備份狀態(tài)看,JobID為1的為完全備份,JobID為3的為差異備份,因此只需恢復(fù)jobid為1和3的備份即可完全恢復(fù)
Building directory tree for JobId(s) 1,3 ... 
3 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 *                    #指定要恢復(fù)的文件或目錄,* 表所有
5 files marked.
$ done
Storage "" not found, using Storage "dbsd" from MediaType "File".
Bootstrap records written to /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.1.bsr
 
The job will require the following
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
  
    webbak                                                                      
    db-2012-02-15-id3                                                           
 
Volumes marked with "*" are online.
 
5 files selected to be restored.
 
Automatically selected Client: 2012-02-15-fd
Run Restore job
JobName:         Restoreweb
Bootstrap:       /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.1.bsr
Where:           *None*
Replace:         always
FileSet:         dbfs
Backup Client:   2012-02-15-fd
Restore Client:  2012-02-15-fd
Storage:         dbsd
When:            2012-02-15 23:54:12
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=4
 
[root@balucaclient etc]# ls /var/www/html/                     
index1.html  index2.html  index3.html
#查看fd端,顯示已經(jīng)完全恢復(fù)
 
2. 利用恢復(fù)指定的文件
[root@balucaclient etc]# rm -rf /var/www/html/*
[root@baculaserver etc]# ./bconsole
*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): 7     #7表示恢復(fù)指定的文件
Automatically selected Client: 2012-02-15-fd
Enter file names with paths, or < to enter a filename
containing a list of file names with paths, and terminate
them with a blank line.
Enter full filename: /var/www/html/index2.html     #指定恢復(fù)index2.html文件
Enter full filename:
Storage "" not found, using Storage "dbsd" from MediaType "File".
Bootstrap records written to /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.2.bsr
 
The job will require the following
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
  
    db-2012-02-15-id3                                                           
 
Volumes marked with "*" are online.
 
 
1 file selected to be restored.
 
Run Restore job
JobName:         Restoreweb
Bootstrap:       /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.2.bsr
Where:           *None*
Replace:         always
FileSet:         dbfs
Backup Client:   2012-02-15-fd
Restore Client:  2012-02-15-fd
Storage:         dbsd
When:            2012-02-16 00:03:19
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=5
 
[root@balucaclient etc]# ls /var/www/html/    
index2.html
#顯示fd上index2.html成功恢復(fù)
 
3. 增量備份的完全恢復(fù)
[root@balucaclient etc]# rm -rf /var/www/html/*
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.32.30:9101
1000 OK: 2012-02-15-dir Version: 5.0.1 (24 February 2010)
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): 3
Enter JobId(s), comma separated, to restore: 1,2
You have selected the following JobIds: 1,2
#從備份狀態(tài)看,JobID為1的為完全備份,JobID為2的為第一個(gè)增量備份,如果2之前還有其他的增量備份,必須在此指定,才能完全恢復(fù)
2 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 *
4 files marked.
$ done
Storage "" not found, using Storage "dbsd" from MediaType "File".
Bootstrap records written to /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.3.bsr
 
The job will require the following
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
  
    webbak                                                                      
    db-2012-02-15-id2                                                           
 
Volumes marked with "*" are online.
 
 
4 files selected to be restored.
 
Automatically selected Client: 2012-02-15-fd
Run Restore job
JobName:         Restoreweb
Bootstrap:       /usr/local/bacula/var/bacula/working/2012-02-15-dir.restore.3.bsr
Where:           *None*
Replace:         always
FileSet:         dbfs
Backup Client:   2012-02-15-fd
Restore Client:  2012-02-15-fd
Storage:         dbsd
When:            2012-02-16 00:08:05
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=6
 
[root@balucaclient etc]# ls /var/www/html/    
index1.html  index2.html
#顯示fd上已經(jīng)完全恢復(fù)Jobid為2前所有的文件
 
七、bconsole中相關(guān)命名說(shuō)明
1. status  查看director、client、storage 狀態(tài)。
[root@baculaserver etc]# ./bconsole
Connecting to Director 192.168.32.30:9101
1000 OK: 2012-02-15-dir Version: 5.0.1 (24 February 2010)
Enter a period to cancel a command.
*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: All
Select daemon type for status (1-4): 3
Automatically selected Client: 2012-02-15-fd
Connecting to Client 2012-02-15-fd at 192.168.32.31:9102
 
2012-02-15-fd Version: 5.0.1 (24 February 2010)  i686-pc-linux-gnu redhat Enterprise release
Daemon started 15- 212 23:16, 6 Jobs run since started.
 Heap: heap=516,096 smbytes=81,546 max_bytes=154,559 bufs=68 max_bufs=95
 Sizeof: boffset_t=8 size_t=4 debug=0 trace=0
 
Running Jobs:
Director connected at: 16- 212 00:16
No Jobs running.
====
 
Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
======================================================================
    20                3    314.5 M  OK       15- 212 21:56 Restoreweb
    21  Incr          4    524.2 M  OK       15- 212 22:18 webjob
    22                3    314.5 M  OK       15- 212 22:25 Restoreweb
    23                4    524.2 M  OK       15- 212 22:27 Restoreweb
     1  Full          3         5   OK       15- 212 23:31 webjob
     2  Incr          2         5   OK       15- 212 23:38 webjob
     3  Diff          3         9   OK       15- 212 23:41 webjob
     4                5        14   OK       15- 212 23:55 Restoreweb
     5                1         5   OK       16- 212 00:04 Restoreweb
     6                4        10   OK       16- 212 00:09 Restoreweb
====
 
也可以
  status dir      查看director 的狀態(tài)
  status client   查看 client  的狀態(tài)
  status storage  查看 storage 的狀態(tài) 
 
2. show  查看資源信息。
  pools   filesets  clients storages schedule jobs message
 
3. list llist 
list pools | jobs | jobtotals | media <pool=pool-name> | files <jobid=nn>
 
4. run  手動(dòng)運(yùn)行一次編好的任務(wù)。
 
5. reload    從新載入配置文件(當(dāng)修改配置文件后用這個(gè),不需要停止服務(wù))
 
6. estimate  對(duì)某次任務(wù)進(jìn)行評(píng)估。它會(huì)連接到客戶端,并輸出這次任務(wù)的fileset 中 文件數(shù),和這次備份任務(wù)所占的空間。
 
7. purge prune
  一般不會(huì)用到,我們?cè)O(shè)定的是過(guò)期自動(dòng)清除。
  purge    危險(xiǎn)。。。! 這是一個(gè)危險(xiǎn)命令。他能清除一個(gè)客戶端的所有備份任務(wù),文件,和卷。
  prune    這個(gè)命令和 purge 相似,但安全很多,它只會(huì)清除過(guò)期的文件,任務(wù),和卷。 
8. time    查看時(shí)間。 
9. delete   刪除volume , pool 或某次任務(wù)。
10. disable 和 enable 是一對(duì),它可以禁止和啟用某個(gè)任務(wù)。
11 cancel   取消一次正在運(yùn)行的任務(wù)。例如:某次任務(wù)由于設(shè)置不當(dāng),卡住不動(dòng)了,我們就可以使用這條命令,去取消這次任務(wù)。
   cancel 20   取消任務(wù)ID=20 的任務(wù)。 
12 update   修改 volumes ,pool 參數(shù)。

熱門評(píng)論
最新評(píng)論
發(fā)表評(píng)論 查看所有評(píng)論(0)
昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過(guò)審核才能顯示)