当前位置: 首页IT技术 → 利用bacula完成数据的备份恢复

利用bacula完成数据的备份恢复

更多

一、bacula概述

1.bacula的组件
  bacula,被誉为开源软件中最好的备份还原软件,它提供了企业级的客户机/服务器的备份解决方案,能够通过网络来管理文件的备份,恢复和核实工作.既有windows版本的,也有Linux,Unix的.
一个完整的bacula备份系统,由以下五个主要部分或服务组成:
Directory:  管理所有备份,恢复,验证,和存档事务,定制备份和恢复文件的计划.
Storge:     指定进行存储和恢复文件属性和数据的物理备份媒介.
File:       安装在被备份机器上的程序,将被directory调用时候,它提供关于自己的操作系统、文件属性、数据等资料.
Console:    管理控制台,与directory进行通讯.
Catalog: 负责维护所有备份文件的索引和数据库.Catalog服务允许系统管理员或用户能够快速地找到并恢复任何需要的档案。catalog服务是Bacula和简单的tar,bru备份命令的主要区别,因为catalog维护所有Volume使用情况的记录,所有任务的运行情况,和所有档案的保存情况,允许有效的恢复和Volume管理。 Bacula目前支持的三个数据库(postgresql、mysql、sqlite),在安装Bacula时,必须选择其中之一。
Monitor:   监控directory、file、storage的守护进程
 


bacula各个组成部分的关联性
 
2. 部署结构
主机名          ip地址          应用角色               OS  
baculaserver    192.168.32.30   Director、SD、Console  rhel5.5
baculaclient    192.168.32.31   FD                     rhel5.5
 
二、安装
1.bacula服务器端安装和初始化
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 
#指定安装路径和所用数据库
[root@baculaserver bacula-5.0.1]# make && make install
 
1.2 MySQL数据库初始化
[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
#在执行上面三行mysql初始化时,默认由数据库管理员root执行,因此可能需要输入root密码或设置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     #主控台名称,自定义,要求与bacula-dir.conf中定义相同
  DIRport = 9101            #控制台服务器端口
  address = 192.168.32.30   #控制台服务器IP,不要用localhost
  Password = "xgjYPXCfgFT6ZS/9tQQTtfrFZ90CFFfIcj+qDKm8FpO0"  #控制台密码
}
 
2. bacula的Director端配置(bacula-dir.conf)
2.1 bacula-dir.conf的组成
bacula-dir.conf是Director端的配置文件,也是bacula的核心配置文件,该文件由以下10个逻辑端组成:
Director:定义全局设置
Catalog:定义后台数据库
Jobdefs:定义默认执行任务
Job:自定义一个备份或恢复任务
Fileset:定义备份哪些数据,不备份哪些数据
Schedule:定义备份时间策略
Pool:定义供Job使用的池属性
Client:定义要备份的客户端
Storage:定义数据的存储方式
Messages:定义发送日志报告和日志的记录
 
2.2 bacula-dir.conf配置
[root@baculaserver etc]# vim bacula-dir.conf
Director {                            #控制台的全局配置
  Name = 2012-02-15-dir               #定义控制台名称,要与sd、fa的Director相同
  DIRport = 9101                      # Director的服务端口
  QueryFile = "/usr/local/bacula/etc/query.sql"
  WorkingDirectory = "/usr/local/bacula/var/bacula/working"
  PidDirectory = "/var/run"
  Maximum Concurrent Jobs = 1        #一次能处理的最大并发数
  Password = "xgjYPXCfgFT6ZS/9tQQTtfrFZ90CFFfIcj+qDKm8FpO0"       #控制台密码,要与bconsole.conf中Director密码相同
  Messages = Daemon                  #日志输出方式,“Daemon”在下面Messages逻辑段中定义
}
 
#JobDefs {                           #JobDefs类似一个模板,并不是真正创建一个任务,只为Job提供一个默认的配置,当前Job明确定义的任何值,将会覆盖冲突的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 {                           #备份任务,注意注释标号,可按照该标号与后面各逻辑端定义相对应
  Name = webjob                 #备份job的名字,这个可以随便起,在后面的备份操作的时候可以看到
  Type= backup                  #可用类型有backup,restore,verify,admin
  Client= 2012-02-15-fd         #1.要备份的客户端,“2012-02-15-fd”在后面的Client逻辑段定义
  FileSet = dbfs            #2.要备份的客户端数据,“dbfs”在后面的FileSet逻辑段定义
  schedule = dbscd              #3.备份任务的执行时间策略,“dbscd”在后面的Schedule逻辑段定义
  Storage = dbsd            #4.备份数据的存储介质和路径,“dbsd”在后面的Storage逻辑段定义
  Messages = Daemon         
  Pool = dbpool             #5.pool属性,“dbpool”在后面的Pool逻辑段定义
  Level = Incremental         #备份类型,可用的值是FULL(完全备份),incremental(增量备份),differential(差异备份),如第一次没做完全备份,则先进行完全备份后再执行Incremental
  Priority = 10                #优先级
  Write Bootstrap = "/usr/local/bacula/var/bacula/working/%c.bsr"   #指定备份的引导信息路径
}
 
#Job {                        #定义一个Catalog备份任务,确保控制端备份数据库的安全
#  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 {                         #定义一个还原任务
  Name = "Restoreweb"           
  Type = Restore
  Client=2012-02-15-fd                
  FileSet="dbfs"                 
  Storage = dbsd                     
  Pool = dbpool
  Messages = Standard
  Where = /home/bacula      #指定默认恢复数据到这个路径,注意:还原客户端数据时,默认会将数据存放在客户端/home/bacula下。如不指定,默认会还原的原数据所在地
}
 
 
FileSet {                  #2.定义名为dbfs要备份的客户端数据,即指定需要备份哪些数据,需要排除哪些数据,可指定多个FileSet
  Name = "dbfs"
  Include {
    Options {
#     Compression=GZIP     #对备份文件进行gzip的压缩
      signature = MD5      #验证方式为MD5码的方式
    }
    File = /var/www       #指定客户端需要备份的文件或目录
  }
 
  Exclude {               #排除不需要备份的文件或目录
    File = /var/www/cgi-bin 
    File = /var/www/error
    File = /var/www/icons
  }
}
 
Schedule {                 #3.备份任务的执行时间策略,定义名为dbscd的备份任务调度策略
    Name = dbscd
    Run = Level=Full mon at 7:00         #在周一7点作一次全备份
    Run = Level=Full fri at 7:00         #在周五7点作一次全备份
    Run = Level=Differential sat at 7:00     #在周六7点作一次差异备份
    Run = Level=Differential sun at 7:00     #在周日7点作一次差异备份
    Run = Level=Differential tue-thu at 7:00     #在周二到周四7点作差异备份
}
 
#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                 #记录客户机备份情况的日志名,后面Catalog逻辑段定义
  Password = "d1+RTcYIpa7YYB2/SrhRp/BAB7lBSF/Rl7wgrkSb52A2"          # Director与FD的验证密码,必须与bacula-fd.conf中密码相同
  File Retention = 30 days            # 指定保存在数据库中的记录多久循环一次,这里30天,只影响数据库中的记录,不影响备份的文件
  Job Retention = 6 months            # job的保持周期,应大于File Retention的值   
  AutoPrune = yes                     # 当达到指定的保存周期时,是否自动删除数据库中记录,yes表自动清除过期的job
}
 
 
 
Storage {                             #4.备份数据的存储介质和路径;Storage用来指定将客户端数据备份到哪个存储设备上。
  Name = dbsd
  Address = 192.168.32.30             #存储端SD的IP地址
  SDPort = 9103
  Password = "w6YqAfWkU7NMxRJ8s/8y5kUffGpysot4vt9HVQjE9bQy"  #Director端与SD的通讯密码,必须与bacula-sd.conf中Director段密码相同
  Device = dbdev                     #指定数据备份介质,必须与存储SD端的bacula-sd.conf中Device逻辑端的Name相同
  Media Type = File                  #指定数据备份介质类别,必须与存储SD端的bacula-sd.conf中Device逻辑端的Media Type相同
}
 
Catalog {               #Catalog逻辑段用来定义关于日志和数据库的设定
  Name = MyCatalog
  dbname = "bacula"; dbuser = "bacula"; dbpassword = ""
}
 
Messages {             #Messages逻辑段用来设定Director端如何保存日志,日志格式,可以将日志信息发送给管理员,要求开启sendmail服务。
  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任务使用的池属性信息,如:设定文件过期时间,是否覆盖过去备份数据,是否自动清除过去备份等。
  Name = dbpool
  Pool Type = Backup
  Recycle = yes                       # 重复使用
  AutoPrune = yes                     # 自动清除过去备份
  Volume Retention = 365 days         # 备份文件保存时间
  Maximum Volume Jobs =1              # 每次执行备份任务创建一个备份文件。
  Maximum Volume Bytes = 50G          # 限制备份文件文件最大值
  Maximum Volumes = 100               # 最多保存多少个备份文件
  Recycle Current Volume = yes        # 使用最近过期的文件存储新备份
  Label Format = "db-${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-id${JobId}"  #设定备份文件命名格式
}
 
#Pool {
#  Name = Scratch
#  Pool Type = Backup
#}
 
Console {                         #限定console利用tray-monitor获取diretor的状态信息
  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 {                             # 定义存储,本例2012-02-15-sd
  Name = 2012-02-15-sd
  SDPort = 9103                       # 服务端口   
  WorkingDirectory = "/usr/local/bacula/var/bacula/working"
  Pid Directory = "/var/run"
  Maximum Concurrent Jobs = 20
}
 
Director {                        #定义一个控制StorageDaemon的控制台Director
  Name = 2012-02-15-dir           #该值必须与bacula-dir.conf中Director逻辑段内定义相同
  Password = "w6YqAfWkU7NMxRJ8s/8y5kUffGpysot4vt9HVQjE9bQy"   #必须与bacula-dir.conf中Storage逻辑端定义password相同
}
 
Director {                      #定义一个监控端的Director
  Name = 2012-02-15-mon         #必须与bacula-dir.conf中Console逻辑段内定义相同
  Password = "1tcj5GjpmPFP6M46JgjYzhiDsdC3br/4fDzKuH9kQRlz"   #必须与bacula-dir.conf中Console逻辑段内定义password相同
  Monitor = yes
}
 
Device {
  Name = dbdev                         #定义device,名称与Director端配置文件bacula-dir.conf中的Storage逻辑端Device相同
  Media Type = File                    #存储介质类型,file表示文件系统存储
  Archive Device = /home/webbak        #指定存储介质,可以使cd、dvd、tap等,这里是将备份文件保存在/home/webak目录下
  LabelMedia = yes;                    #通过Label建立卷文件
  Random access = Yes;                 #是否采用随机访问存储介质,
  AutomaticMount = yes;                # 存储设备打开是,是否自动使用他
  RemovableMedia = no;                 #是否支持移动设备,如tap,cd等
  AlwaysOpen = no;                     #是否确保tap设备总是可用
}
 
Messages {                            #为存储端SD定义一个日志或消息出来机制
  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         #定义一个允许连接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      #定义一个允许连接FD的监控端Console
  Password = "1tcj5GjpmPFP6M46JgjYzhiDsdC3br/4fDzKuH9kQRlz"   #必须与bacula-dir.conf中Console逻辑段内定义password相同
  Monitor = yes
}
 
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # 定义一个FD端
  Name = 2012-02-15-fd
  FDport = 9102                       # 监控端口
  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服务的启动 
1. 在服务器端启动bacula的Director Daemon和Storage Daemon
1.1 启动方式一
[root@baculaserver etc]#/usr/local/bacula/etc/bacula {start|stop|restart|status}
 
1.2 启动方式二:分别管理各个配置端的方式,依次启动或关闭每个服务
[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上,在此无需自动bacula-fd服务
[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 
#在启动bacula的所有服务前,必须启动MySQL数据库,否则连接bacula的控制端是会报错。
 
2. 在客户端启动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端,在此只需启动bacula-fd服务即可
 
五、bacula备份文件
1. 创建卷组
[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           #创建一个卷组
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: dbsd
Enter new Volume name: webbak        #卷组名称,可随意指定,指定完毕后,会在bacula-dir.conf中Device逻辑字段指定的/home/webbak下生成一个文件
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.
#只有在使用磁带卷时才需要这样,而像我们刚才使用的磁盘卷,Bacula是可以自动进行label的。想要删除测试数据的话,就将/tmp目录下的卷直接删除,再使用drop_mysql_tables和make_mysql_tables脚本  
                                                                                                  
2. 执行备份
2.1 第一次增量备份,默认会是一个完全备份  #备份前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        #选择备份任务
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是一个增量备份,因此这个备份只是一个增量操作,由于是第一个备份,因此默认webjob会做一个完全备份,第二次备份时才执行增量备份
 
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                                                                                                                              
#这是第二备份,只做一个增量操作
 
2.3 第三次备份,手动改为差异备份  #备份前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修改备份任务参数
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. 查看备份状态
*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
#显示备份任务webjob第一次为full完全备份,第二次为增量备份,第三次为差异备份。
 
4.查看备份文件
[root@baculaserver etc]# ls -ls /home/webbak/
总计 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产生的卷组文件
 
六、bacula恢复文件
1. 利用差异备份进行完全恢复
[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
#从备份状态看,JobID为1的为完全备份,JobID为3的为差异备份,因此只需恢复jobid为1和3的备份即可完全恢复
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 *                    #指定要恢复的文件或目录,* 表所有
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端,显示已经完全恢复
 
2. 利用恢复指定的文件
[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表示恢复指定的文件
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     #指定恢复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成功恢复
 
3. 增量备份的完全恢复
[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
#从备份状态看,JobID为1的为完全备份,JobID为2的为第一个增量备份,如果2之前还有其他的增量备份,必须在此指定,才能完全恢复
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上已经完全恢复Jobid为2前所有的文件
 
七、bconsole中相关命名说明
1. status  查看director、client、storage 状态。
[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 的状态
  status client   查看 client  的状态
  status storage  查看 storage 的状态 
 
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  手动运行一次编好的任务。
 
5. reload    从新载入配置文件(当修改配置文件后用这个,不需要停止服务)
 
6. estimate  对某次任务进行评估。它会连接到客户端,并输出这次任务的fileset 中 文件数,和这次备份任务所占的空间。
 
7. purge prune
  一般不会用到,我们设定的是过期自动清除。
  purge    危险!!!!! 这是一个危险命令。他能清除一个客户端的所有备份任务,文件,和卷。
  prune    这个命令和 purge 相似,但安全很多,它只会清除过期的文件,任务,和卷。 
8. time    查看时间。 
9. delete   删除volume , pool 或某次任务。
10. disable 和 enable 是一对,它可以禁止和启用某个任务。
11 cancel   取消一次正在运行的任务。例如:某次任务由于设置不当,卡住不动了,我们就可以使用这条命令,去取消这次任务。
   cancel 20   取消任务ID=20 的任务。 
12 update   修改 volumes ,pool 参数。

热门评论
最新评论
昵称:
表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
字数: 0/500 (您的评论需要经过审核才能显示)