您的位置:首页 > 其它

使用bacula备份与恢复实战 (一)

2012-12-13 15:23 169 查看
一、部署结构 (有错误或不明白处,可加我QQ:761117826,我们一起共同研究,谢谢!)主机名 ip地址 应用角色 OS
baculaserver 192.168.1.10 Director、SD、Console CentOS5.6
baculaclient1 192.168.1.11 FD CentOS5.6baculaclient2 192.168.1.12 FD CentOS5.6
二、安装1.bacula服务器端安装和初始化1.1 bacula软件安装安装bacula之前要安装mysql gcc gcc-c++[root@baculaserver ~]# yum install mysql mysql-devel mysql-server gcc gcc-c++ -y在http://sourceforge.net/projects/bacula/files/bacula/下载bacula,我使用的是bacula-5.2.10版本
[root@baculaserver ~]# tar -zxf bacula-5.2.10.tar.gz -C /usr/src/
[root@baculaserver ~]# cd /usr/src/bacula-5.2.10
[root@baculaserver bacula-5.2.10]# ./configure --prefix=/usr/local/bacula --with-mysql
#指定安装路径和所用数据库
[root@baculaserver bacula-5.0.1]# make && make install && make install-autostart #make install-autostart为开机自启动服务
1.2 MySQL数据库初始化
[root@baculaserver ~]# cd /usr/local/bacula/etc
[root@baculaserver etc]# ./grant_mysql_privileges -u root -p
[root@baculaserver etc]# ./create_mysql_database -u root -p
[root@baculaserver etc]# ./make_mysql_tables -u root -p
#在执行上面三行mysql初始化时,默认由数据库管理员root执行,如果没有密码就不必加后面的-u root -p,如果有密码,则输入密码。

2.bacula客户端安装(使用的与server是一样的安装包)安装bacula之前要安装gcc,gcc-c++[root@baculaclient ~]# yum install gcc gcc-c++ -y[root@baculaclient ~]# tar -zxf bacula-5.2.10.tar.gz -C /usr/src/
[root@baculaclient ~]# cd /usr/src/bacula-5.2.10
[root@baculaclient bacula-5.2.10]# ./configure --prefix=/usr/local/bacula --enable-client-only
#指定安装路径和只安装客户端组件[root@baculaclient bacula-5.0.1]# make && make install && make install-autostart#make install-autostart为开机自启动服务
三、bacula配置1. bacula服务器端配置1.1 bacula的console端配置(bconsole.conf)[root@baculaserver etc]# vim bconsole.conf #当前目录是/usr/local/bacula/etc/## Bacula User Agent (or Console) Configuration File#
Director { Name = baculaserver-dir #主控台名称,可自定义,要求与bacula-dir.conf中定义相同,安装时默认是server的主机名+ -dir,不要更改就好。 DIRport = 9101 #控制台服务器端口 address = 192.168.1.10 #控制台服务器IP,不要用localhost Password = "LiuQingshan-Director" #控制台密码}
1.2. bacula的Director端配置(bacula-dir.conf)1.2.1 bacula-dir.conf的组成
bacula-dir.conf是Director端的配置文件,也是bacula的核心配置文件,该文件由以下10个逻辑端组成:
Director:定义全局设置
Catalog:定义后台数据库
Jobdefs:定义默认执行任务
Job:自定义一个备份或恢复任务
Fileset:定义备份哪些数据,不备份哪些数据
Schedule:定义备份时间策略
Pool:定义供Job使用的池属性
Client:定义要备份的客户端
Storage:定义数据的存储方式
Messages:定义发送日志报告和日志的记录
1.2.2 bacula-dir.conf配置[root@baculaserver etc]# vim bacula-dir.conf #当前目录是/usr/local/bacula/etc/## Default Bacula Director Configuration file## The only thing that MUST be changed is to add one or more# file or directory names in the Include directive of the# FileSet resource.## For Bacula release 5.2.10 (28 June 2012) -- redhat ## You might also want to change the default email address# from root to your address. See the "mail" and "operator"# directives in the Messages resource.#
Director { # define myself #控制台的全局配置 Name = baculaserver-dir #定义控制台名称,要与sd、fd的Director相同 DIRport = 9101 # where we listen for UA connections # Director的服务端口 QueryFile = "/usr/local/bacula/etc/query.sql" WorkingDirectory = "/usr/local/bacula/var/bacula/working" PidDirectory = "/var/run" Maximum Concurrent Jobs = 1 #一次能处理的最大并发数 Heartbeat Interval = 15 seconds #与sd、fd的心跳时间 Password = "LiuQingshan-Director" # Console password #验证密码,这个密码必须与bconsole.conf文件中对应的Director逻辑段密码相同 Messages = Daemon #日志输出方式,“Daemon”在下面Messages逻辑段中定义}
JobDefs { #JobDefs类似一个模板,并不是真正创建一个任务,只为Job提供一个默认的配置,当前Job明确定义的任何值,将会覆盖冲突的JobDefs值,后面的Job会调用这个模板。 Name = "DefaultJob" #JobDefs名字 Type = Backup #可用类型有backup,restore,verify,admin Level = Incremental #备份类型,可用的值是FULL(完全备份),Incremental(增量备份),Differential(差异备份),如第一次没做完全备份,则先进行完全备份后再执行Incremental# Client = janus.mazentop.com-fd # FileSet = "Full Set"# Schedule = "WeeklyCycle"# Storage = File Messages = Standard Pool = File #pool属性,“File”在后面的Pool逻辑段定义# Priority = 10 Write Bootstrap = "/usr/local/bacula/var/bacula/working/%c.bsr" #指定备份的引导信息路径}

## Define the main nightly save backup job# By default, this job will back up to disk in /tmp#Job {# Name = "BackupClient1"# JobDefs = "DefaultJob"#}
#Job {# Name = "BackupClient2"# Client = janus.mazentop.com2-fd# JobDefs = "DefaultJob"#}
# Backup the catalog database (after the nightly save)#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#}
## Standard Restore template, to be changed by Console program# Only one such job is needed for all Jobs/Clients/Storage ...##Job {# Name = "RestoreFiles"# Type = Restore# Client=janus.mazentop.com-fd # FileSet="Full Set" # Storage = File # Pool = Default# Messages = Standard# Where = /tmp/bacula-restores#}

# List of files to be backed up#FileSet {# Name = "Full Set"# Include {# Options {# signature = MD5# }# # Put your list of files here, preceded by 'File =', one per line# or include an external list with:## File = <file-name## Note: / backs up everything on the root partition.# if you have other partitions such as /usr or /home# you will probably want to add them too.## By default this is defined to point to the Bacula binary# directory to give a reasonable FileSet to backup to# disk storage during initial testing.## File = /usr/local/bacula/sbin# }
## If you backup the root directory, the following two excluded# files can be useful## Exclude {# File = /usr/local/bacula/var/bacula/working # File = /tmp# File = /proc# File = /tmp# File = /.journal# File = /.fsck# }#}
## When to do the backups, full backup on first sunday of the month,# differential (i.e. incremental since full) every other sunday,# and incremental backups other days#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#}
# This schedule does the catalog. It starts after the WeeklyCycle#Schedule {# Name = "WeeklyCycleAfterBackup"# Run = Full sun-sat at 23:10#}
# This is the backup of the catalog#FileSet {# Name = "Catalog"# Include {# Options {# signature = MD5# }# File = "/usr/local/bacula/var/bacula/working/bacula.sql"# }#}
## Client (File Services) to backup#Client {# Name = baculaserver-fd# Address = baculaserver# FDPort = 9102# Catalog = MyCatalog# Password = "jQP9VBIG2fsRD1L8zZFTCZHSErPMxbxPQ5N32dstkEDQ" # password for FileDaemon# File Retention = 30 days # 30 days# Job Retention = 6 months # six months# AutoPrune = yes # Prune expired Jobs/Files#}
## Second Client (File Services) to backup# You should change Name, Address, and Password before using##Client {# Name = baculaserver2-fd # Address = baculaserver2# FDPort = 9102# Catalog = MyCatalog# Password = "jQP9VBIG2fsRD1L8zZFTCZHSErPMxbxPQ5N32dstkEDQ2" # password for FileDaemon 2# File Retention = 30 days # 30 days# Job Retention = 6 months # six months# AutoPrune = yes # Prune expired Jobs/Files#}

# Definition of file storage device#Storage {# Name = File# Do not use "localhost" here # Address = baculaserver # N.B. Use a fully qualified name here# SDPort = 9103# Password = "EjNboSvTNCUxSs1WiABKAdaJ1PGW704lV/DleGnls8QJ"# Device = FileStorage# Media Type = File#}

# Definition of DDS tape storage device#Storage {# Name = DDS-4 # Do not use "localhost" here# Address = baculaserver # N.B. Use a fully qualified name here# SDPort = 9103# Password = "EjNboSvTNCUxSs1WiABKAdaJ1PGW704lV/DleGnls8QJ" # password for Storage daemon# Device = DDS-4 # must be same as Device in Storage daemon# Media Type = DDS-4 # must be same as MediaType in Storage daemon# Autochanger = yes # enable for autochanger device#}
# Definition of 8mm tape storage device#Storage {# Name = "8mmDrive"# Do not use "localhost" here# Address = baculaserver # N.B. Use a fully qualified name here# SDPort = 9103# Password = "EjNboSvTNCUxSs1WiABKAdaJ1PGW704lV/DleGnls8QJ"# Device = "Exabyte 8mm"# MediaType = "8mm"#}
# Definition of DVD storage device#Storage {# Name = "DVD"# Do not use "localhost" here# Address = baculaserver # N.B. Use a fully qualified name here# SDPort = 9103# Password = "EjNboSvTNCUxSs1WiABKAdaJ1PGW704lV/DleGnls8QJ"# Device = "DVD Writer"# MediaType = "DVD"#}

# Generic catalog serviceCatalog { #Catalog逻辑段用来定义关于日志和数据库的设定 Name = MyCatalog# Uncomment the following line if you want the dbi driver# dbdriver = "dbi:mysql"; dbaddress = 127.0.0.1; dbport = dbname = "bacula"; dbuser = "bacula"; dbpassword = "" #指定库名、用户名和密码 }
# Reasonable message delivery -- send most everything to email address# and to the consoleMessages { #Messages逻辑段用来设定Director端如何保存日志,日志格式,可以将日志信息发送给管理员,要求开启sendmail服务。 Name = Standard## NOTE! If you send to two email or more email addresses, you will need# to replace the %r in the from field (-f part) with a single valid# email address in both the mailcommand and the operatorcommand.# What this does is, it sets the email address that emails would display# in the FROM field, which is by default the same email as they're being# sent to. However, if you send email to more than one address, then# you'll have to set the FROM address manually, to a single address. # for example, a 'no-reply@mydomain.com', is better since that tends to# tell (most) people that its coming from an automated source.
# 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## WARNING! the following will create a file that you must cycle from# time to time as it will grow indefinitely. However, it will# also keep all your messages if they scroll off the console.# append = "/usr/local/bacula/var/bacula/working/log" = all, !skipped catalog = all}

## Message delivery for daemon messages (no job).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}
# Default pool definitionPool { #定义job任务使用的池属性信息,如:设定文件过期时间,是否覆盖过去备份数据,是否自动清除过去备份等。 Name = Default Pool Type = Backup Recycle = yes # Bacula can automatically recycle Volumes # 重复使用 AutoPrune = yes # Prune expired volumes # 自动清除过去备份 Volume Retention = 62 days # one year # 备份文件保存时间}
# File Pool definitionPool { Name = File Pool Type = Backup Recycle = yes # Bacula can automatically recycle Volumes # 重复使用 AutoPrune = yes # Prune expired volumes # 自动清除过去备份 Volume Retention = 62 days # one year # 备份文件保存时间 Maximum Volume Bytes = 66G # Limit Volume size to something reasonable # 限制备份文件文件最大值 Maximum Volumes = 100000000 # Limit number of Volumes in Pool #设置最多保存多少个备份文件 Maximum Volume Jobs = 1 # 每次执行备份任务创建一个备份文件。 Recycle Current Volume = yes # 使用最近过期的文件存储新备份 Label Format = "${Year}-${Month:p/2/0/r}-${Day:p/2/0/r}-${JobId}" #设定备份文件命名格式,就是备份后的文件名字是当天日期加Job号}

# Scratch pool definitionPool { Name = Scratch Pool Type = Backup}
## Restricted console used by tray-monitor to get the status of the director#Console { #限定console利用tray-monitor获取diretor的状态信息 Name = baculaserver-mon Password = "6svlrkgboyB/Tqt0b0AvqKk7l/1nIlbwbAbYEOL8tQBV" CommandACL = status, .status}

#############################################FileSet
FileSet { #定义要备份的客户端网站数据,即指定需要备份哪些数据,需要排除哪些数据,可指定多个FileSet Name = web_fileset Include { Options { signature = MD5 #验证方式为MD5码的方式 Compression = GZIP2 #对备份文件进行gzip的压缩 } File = /home #指定客户端需要备份的文件或目录,公司网站的目录就在这个下面 } Exclude { #排除不需要备份的文件或目录 File = /home/*/public_html/cache/* File = /home/*/public_html/bmz_cach/* File = /home/localbackup File = /home/restored_home File = /home/Jack File = /home/install File = /home/bak File = *.tar File = *.zip File = *.7z File = *.gz File = *.bz2 File = *.sql File = *.rar File = *.bak }}
FileSet { #定义要备份的客户端数据库数据,我使用的是将数据库导出到/localdatabasebackup下,然后再对这个目录进行备份,导出可以用mysqldump写脚本导出,也可以其它的方法导出为.sql的文件。 Name = database_fileset Include { Options { signature = MD5 Compression = GZIP2 } File = /localdatabasebackup }}
###########################################################################################################192.168.1.11Job { #备份任务,注意注释标号,可按照该标号与后面各逻辑端定义相对应 Name = "192.168.1.11_database_job" #备份job的名字,这个可以随便起,在后面的备份操作的时候可以看到 JobDefs = "DefaultJob" #使用上面定义的DefaultJob这个模板 Client = 192.168.1.11-fd #要备份的客户端,“192.168.1.11-fd ”在后面的Client逻辑段定义 Fileset = database_fileset #要备份的客户端数据,“database_fileset”在后面的FileSet逻辑段定义 Schedule = 192.168.1.11_database_schedule #备份任务的执行时间策略,“192.168.1.12_database_schedule”在后面的Schedule逻辑段定义 Storage = 192.168.1.11_database_storage #备份数据的存储介质和路径,“192.168.1.11_database_storage”在后面的Storage逻辑段定义 Priority = 11 #备份优先级,数字越小优先级超高}Schedule { #备份任务的执行时间策略,定义名为192.168.1.11_database_schedule的备份任务调度策略 Name = 192.168.1.11_database_schedule Run = Full on 1 at 00:00 #在每个月的1号零点,进行全备,因为公司服务器较多 Run = Differential on 8 at 00:00 #在每个月的8、15、22、29号零点,进行差异备份 Run = Differential on 15 at 00:00 Run = Differential on 22 at 00:00 Run = Differential on 29 at 00:00 Run = Incremental on 2-7 at 00:00 #剩余的天数进行增量备份 Run = Incremental on 9-14 at 00:00 Run = Incremental on 16-21 at 00:00 Run = Incremental on 23-28 at 00:00 Run = Incremental on 30-31 at 00:00}#还有一种写法就是#Schedule {# Name = 192.168.1.11_web_schedule # Run = Full 1st sun at 00:00 #每个月的第一个星期日进行全备# Run = Differential 2nd-5th sun at 00:00 #每个月的第二个到第五个星期日进行差异备份# Run = Incremental mon-sat at 00:00 #每周的周一至周六进行增量备份 } Storage { #备份数据的存储介质和路径;Storage用来指定将客户端数据备份到哪个存储设备上。 Name = 192.168.1.11_database_storage Address = 192.168.1.10 #存储端SD的地址 SDPort = 9103 #指定存储端SD通信的端口 Password = "6Ua7La41oZ15YwCDj0r3Nfjddm4dLHyOoKSuGfefflIv" #Director端与SD的通讯密码,必须与bacula-sd.conf中Director段密码相同 Device = 192.168.1.11_database_dev #指定数据备份介质,必须与存储SD端的bacula-sd.conf中Device逻辑端的Name相同 Media Type = File #指定数据备份介质类别,必须与存储SD端的bacula-sd.conf中Device逻辑端的Media Type相同}
Client { #要备份的客户端 Name = 192.168.1.11-fd #Clinet的名称,可以在前面的Job中调用 Address = 192.168.1.11 #要备份的客户端FD主机的IP地址 FDPort = 9102 #与客户端FD通信的端口 Catalog = MyCatalog #记录客户机备份情况的日志名,上面Catalog逻辑段定义 Password = "eyBPuJuxa6pVSL9rN6K4KvpSNsR0JeoU/192.168.1.11" # Director端与FD的验证密码,必须与bacula-fd.conf中Director项的密码相同 File Retention = 62 days #指定保存在数据库中的记录多久循环一次,这里30天,只影响数据库中的记录,不影响备份的文件 Job Retention = 6 months #job的保持周期,应大于File Retention的值 AutoPrune = yes # 当达到指定的保存周期时,是否自动删除数据库中记录,yes表自动清除过期的job}Job { Name = "192.168.1.11_web_job" JobDefs = "DefaultJob" Client = 192.168.1.11-fd Fileset = web_fileset Schedule = 192.168.1.11_web_schedule Storage = 192.168.1.11_web_storage Priority = 12}Schedule { Name = 192.168.1.11_web_schedule Run = Full on 1 at 00:03 Run = Differential on 8 at 00:03 Run = Differential on 15 at 00:03 Run = Differential on 22 at 00:03 Run = Differential on 29 at 00:03 Run = Incremental on 2-7 at 00:03 Run = Incremental on 9-14 at 00:03 Run = Incremental on 16-21 at 00:03 Run = Incremental on 23-28 at 00:03 Run = Incremental on 30-31 at 00:03}Storage { Name = 192.168.1.11_web_storage Address = 192.168.1.10 SDPort = 9103 Password = "6Ua7La41oZ15YwCDj0r3Nfjddm4dLHyOoKSuGfefflIv" Device = 192.168.1.11_web_dev Media Type = File}#############################################################################################################192.168.1.12
Job { Name = "192.168.1.12_database_job" JobDefs = "DefaultJob" Client = 192.168.1.12-fd Fileset = database_fileset Schedule = 192.168.1.12_database_schedule Storage = 192.168.1.12_database_storage Priority = 13}
Schedule { Name = 192.168.1.12_database_schedule Run = Full on 2 at 00:20 Run = Differential on 9 at 00:20 Run = Differential on 16 at 00:20 Run = Differential on 23 at 00:20 Run = Differential on 30 at 00:20 Run = Incremental on 1 at 00:20 Run = Incremental on 3-8 at 00:20 Run = Incremental on 10-15 at 00:20 Run = Incremental on 17-22 at 00:20 Run = Incremental on 24-29 at 00:20 Run = Incremental on 31 at 00:20 }
Storage { Name = 192.168.1.12_database_storage Address = 192.168.1.10 SDPort = 9103 Password = "6Ua7La41oZ15YwCDj0r3Nfjddm4dLHyOoKSuGfefflIv" Device = 192.168.1.12_database_dev Media Type = File}
Client { Name = 192.168.1.12-fd Address = 192.168.1.12 FDPort = 9102 Catalog = MyCatalog Password = "eyBPuJuxa6pVSL9rN6K4KvpSNsR0JeoU/192.168.1.12" File Retention = 62 days Job Retention = 6 months AutoPrune = yes}
Job { Name = "192.168.1.12_web_job" JobDefs = "DefaultJob" Client = 192.168.1.12-fd Fileset = web_fileset Schedule = 192.168.1.12_web_schedule Storage = 192.168.1.12_web_storage Priority = 14}
Schedule { Name = 192.168.1.12_web_schedule Run = Full on 2 at 00:25 Run = Differential on 9 at 00:25 Run = Differential on 16 at 00:25 Run = Differential on 23 at 00:25 Run = Differential on 30 at 00:25 Run = Incremental on 1 at 00:25 Run = Incremental on 3-8 at 00:25 Run = Incremental on 10-15 at 00:25 Run = Incremental on 17-22 at 00:25 Run = Incremental on 24-29 at 00:25 Run = Incremental on 31 at 00:23 }
Storage { Name = 192.168.1.12_web_storage Address = 192.168.1.10 SDPort = 9103 Password = "6Ua7La41oZ15YwCDj0r3Nfjddm4dLHyOoKSuGfefflIv" Device = 192.168.1.12_web_dev Media Type = File}
#############################################################
#####################################################Job { #定义对应的还原任务 Name = "Restore_192.168.1.11_web_job" Type = Restore Client = 192.168.1.11-fd FileSet = web_fileset Storage = 192.168.1.11_web_storage Pool = Default Messages = Standard Where = /bacula-restores}Job { Name = "Restore_192.168.1.11_database_job" Type = Restore Client = 192.168.1.11-fd FileSet = database_fileset Storage = 192.168.1.11_database_storage Pool = Default Messages = Standard Where = /bacula-restores}#####################################################Job { Name = "Restore_192.168.1.12_web_job" Type = Restore Client = 192.168.1.12-fd FileSet = web_fileset Storage = 192.168.1.12_web_storage Pool = Default Messages = Standard Where = /bacula-restores}Job { Name = "Restore_192.168.1.12_database_job" Type = Restore Client = 192.168.1.12-fd FileSet = database_fileset Storage = 192.168.1.12_database_storage Pool = Default Messages = Standard Where = /bacula-restores}######################################################你有多少要备份的服务器,就在下面一直添加下去,我们公司有50多台,用了两台bacula备份服务器来备份,因为一台在时间上运转不过来。
1.3. bacula的SD配置(bacula-sd.conf)
SD可以是一台单独的服务器,也可以和Director在一台机器上,本例就将SD和Director端放在一起进行配置,SD的配置文件是bacula-sd.conf。
[root@baculaserver etc]# vim bacula-sd.conf #当前目录是/usr/local/bacula/etc/
# Default Bacula Storage Daemon Configuration file## For Bacula release 5.2.10 (28 June 2012) -- redhat ## You may need to change the name of your tape drive# on the "Archive Device" directive in the Device# resource. If you change the Name and/or the # "Media Type" in the Device resource, please ensure# that dird.conf has corresponding changes.
Storage { # definition of myself # 定义存储 Name = baculaserver-sd SDPort = 9103 # Director's port # 服务端口 WorkingDirectory = "/usr/local/bacula/var/bacula/working" Pid Directory = "/var/run" Maximum Concurrent Jobs = 188 Heartbeat Interval = 30}
## List Directors who are permitted to contact Storage daemon#Director { #定义一个控制StorageDaemon的Director Name = baculaserver-dir #这里的“Name”值必须和Director端配置文件bacula-dir.conf中Director逻辑段名称相同 Password = "6Ua7La41oZ15YwCDj0r3Nfjddm4dLHyOoKSuGfefflIv" #这里的“Password”值必须和Director端配置文件bacula-dir.conf中Storage逻辑段密码相同}
## Restricted Director, used by tray-monitor to get the# status of the storage daemon#Director { #定义一个监控端的Director Name = baculaserver-mon #这里的“Name”值必须和Director端配置文件bacula-dir.conf中Console逻辑段名称相同 Password = "6svlrkgboyB/Tqt0b0AvqKk7l/1nIlbwbAbYEOL8tQBV" #这里的“Password”值必须和Director端配置文件bacula-dir.conf中Console逻辑段密码相同 Monitor = yes}
## Note, for a list of additional Device templates please# see the directory <bacula-source>/examples/devices# Or follow the following link:# http://bacula.svn.sourceforge.net/viewvc/bacula/trunk/bacula/examples/devices/# ## Devices supported by this Storage daemon# To connect, the Director's bacula-dir.conf must have the# same Name and MediaType. #
#Device {# Name = FileStorage# Media Type = File# Archive Device = /tmp# LabelMedia = yes; # lets Bacula label unlabeled media# Random Access = Yes;# AutomaticMount = yes; # when device opened, read it# RemovableMedia = no;# AlwaysOpen = no;#}
## An autochanger device with two drives##Autochanger {# Name = Autochanger# Device = Drive-1# Device = Drive-2# Changer Command = "/usr/local/bacula/etc/mtx-changer %c %o %S %a %d"# Changer Device = /dev/sg0#}
#Device {# Name = Drive-1 ## Drive Index = 0# Media Type = DLT-8000# Archive Device = /dev/nst0# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes;# RemovableMedia = yes;# RandomAccess = no;# AutoChanger = yes# ## # Enable the Alert command only if you have the mtx package loaded# # Note, apparently on some systems, tapeinfo resets the SCSI controller# # thus if you turn this on, make sure it does not reset your SCSI # # controller. I have never had any problems, and smartctl does# # not seem to cause such problems.# ## Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"# If you have smartctl, enable this, it has more info than tapeinfo # Alert Command = "sh -c 'smartctl -H -l error %c'" #}
#Device {# Name = Drive-2 ## Drive Index = 1# Media Type = DLT-8000# Archive Device = /dev/nst1# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes;# RemovableMedia = yes;# RandomAccess = no;# AutoChanger = yes# # Enable the Alert command only if you have the mtx package loaded# Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"# If you have smartctl, enable this, it has more info than tapeinfo # Alert Command = "sh -c 'smartctl -H -l error %c'" #}
## A Linux or Solaris LTO-2 tape drive##Device {# Name = LTO-2# Media Type = LTO-2# Archive Device = /dev/nst0# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes;# RemovableMedia = yes;# RandomAccess = no;# Maximum File Size = 3GB## Changer Command = "/usr/local/bacula/etc/mtx-changer %c %o %S %a %d"## Changer Device = /dev/sg0## AutoChanger = yes# # Enable the Alert command only if you have the mtx package loaded## Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"## If you have smartctl, enable this, it has more info than tapeinfo ## Alert Command = "sh -c 'smartctl -H -l error %c'" #}
## A Linux or Solaris LTO-3 tape drive##Device {# Name = LTO-3# Media Type = LTO-3# Archive Device = /dev/nst0# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes;# RemovableMedia = yes;# RandomAccess = no;# Maximum File Size = 4GB## Changer Command = "/usr/local/bacula/etc/mtx-changer %c %o %S %a %d"## Changer Device = /dev/sg0## AutoChanger = yes# # Enable the Alert command only if you have the mtx package loaded## Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"## If you have smartctl, enable this, it has more info than tapeinfo ## Alert Command = "sh -c 'smartctl -H -l error %c'" #}
## A Linux or Solaris LTO-4 tape drive##Device {# Name = LTO-4# Media Type = LTO-4# Archive Device = /dev/nst0# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes;# RemovableMedia = yes;# RandomAccess = no;# Maximum File Size = 5GB## Changer Command = "/usr/local/bacula/etc/mtx-changer %c %o %S %a %d"## Changer Device = /dev/sg0## AutoChanger = yes# # Enable the Alert command only if you have the mtx package loaded## Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"## If you have smartctl, enable this, it has more info than tapeinfo ## Alert Command = "sh -c 'smartctl -H -l error %c'" #}
## A FreeBSD tape drive##Device {# Name = DDS-4 # Description = "DDS-4 for FreeBSD"# Media Type = DDS-4# Archive Device = /dev/nsa1# AutomaticMount = yes; # when device opened, read it# AlwaysOpen = yes# Offline On Unmount = no# Hardware End of Medium = no# BSF at EOM = yes# Backward Space Record = no# Fast Forward Space File = no# TWO EOF = yes# If you have smartctl, enable this, it has more info than tapeinfo # Alert Command = "sh -c 'smartctl -H -l error %c'" #}# # Send all messages to the Director, # mount messages also are sent to the email address#Messages { #为存储端SD定义一个日志或消息处理机制 Name = Standard director = baculaserver-dir = all}################################################################################## #################################################################192.168.1.11
Device { #定义Device Name = 192.168.1.11_database_dev #定义Device的名称,这个名称在Director端配置文件bacula-dir.conf中的Storage逻辑段Device项中被引用 Media Type = File #指定存储介质的类型,File表示使用文件系统存储 Archive Device = /backup/192.168.1.11/database #Archive Device用来指定备份存储的介质,可以是cd、dvd、tap等,这里是将备份的文件保存的/backup/192.168.1.11/database目录下 LabelMedia = yes; # lets Bacula label unlabeled media #通过Label命令来建立卷文件 Random Access = Yes; #设置是否采用随机访问存储介质,这里选择yes AutomaticMount = yes; # when device opened, read it #表示当存储设备打开时,是否自动使用它,这选择yes RemovableMedia = no; #是否确保tap设备总是可用,这里没有使用tap设备,因此设置为no AlwaysOpen = no; } Device { Name = 192.168.1.11_web_dev Media Type = File Archive Device = /backup/192.168.1.11/web LabelMedia = yes; # lets Bacula label unlabeled media Random Access = Yes; AutomaticMount = yes; # when device opened, read it RemovableMedia = no; AlwaysOpen = no; }
###################################################################################################################################################192.168.1.12
Device { Name = 192.168.1.12_database_dev Media Type = File Archive Device = /backup/5192.168.1.12/database LabelMedia = yes; # lets Bacula label unlabeled media Random Access = Yes; AutomaticMount = yes; # when device opened, read it RemovableMedia = no; AlwaysOpen = no; } Device { Name = 192.168.1.12_web_dev Media Type = File Archive Device = /backup/192.168.1.12/web LabelMedia = yes; # lets Bacula label unlabeled media Random Access = Yes; AutomaticMount = yes; # when device opened, read it RemovableMedia = no; AlwaysOpen = no; }
##################################################################################
2. 配置bacula的FD端 2.1 baculaclient1的配置:[root@balucaclient1 etc]# vim bacula-fd.conf #当前目录为/usr/local/bacula/etc
## Default Bacula File Daemon Configuration file## For Bacula release 5.2.10 (28 June 2012) -- redhat ## There is not much to change here except perhaps the# File daemon Name to#
## List Directors who are permitted to contact this File daemon##Director { #定义一个允许连接FD的控制端 Name = baculaserver-dir #这里的“Name”值必须和Director端配置文件bacula-dir.conf中Director逻辑段名称相同 Password = "eyBPuJuxa6pVSL9rN6K4KvpSNsR0JeoU/192.168.1.11" #这里的“Password”值必须和Director端配置文件bacula-dir.conf中Client逻辑段密码相同}
## Restricted Director, used by tray-monitor to get the# status of the file daemon#Director { #定义一个允许连接FD的监控端 Name = baculaserver-mon #这里的“Name”值必须和Director端配置文件bacula-dir.conf中Console逻辑段名称相同 Password = "6svlrkgboyB/Tqt0b0AvqKk7l/1nIlbwbAbYEOL8tQBV" #这里的“Password”值必须必须与bacula-dir.conf中Console逻辑段内定义password相同 Monitor = yes}## "Global" File daemon configuration specifications#FileDaemon { # this is me #定义一个FD端 Name = baculaclient1-fd FDport = 9102 # where we listen for the director WorkingDirectory = /usr/local/bacula/var/bacula/working Pid Directory = /var/run Maximum Concurrent Jobs = 20}
# Send all messages except skipped files back to DirectorMessages { Name = Standard director = baculaclient1-dir = all, !skipped, !restored}
2.2 baculaclient2的配置:
[root@balucaclient2 etc]# vim bacula-fd.conf #当前目录为/usr/local/bacula/etc
## Default Bacula File Daemon Configuration file## For Bacula release 5.2.10 (28 June 2012) -- redhat ## There is not much to change here except perhaps the# File daemon Name to#
## List Directors who are permitted to contact this File daemon##Director { Name = baculaserver-dir Password = "eyBPuJuxa6pVSL9rN6K4KvpSNsR0JeoU/192.168.1.12"}
## Restricted Director, used by tray-monitor to get the# status of the file daemon#Director { Name = baculaserver-mon Password = "6svlrkgboyB/Tqt0b0AvqKk7l/1nIlbwbAbYEOL8tQBV" Monitor = yes}## "Global" File daemon configuration specifications#FileDaemon { # this is me Name = baculaclient1-fd FDport = 9102 # where we listen for the director WorkingDirectory = /usr/local/bacula/var/bacula/working Pid Directory = /var/run Maximum Concurrent Jobs = 20}
# Send all messages except skipped files back to DirectorMessages { Name = Standard director = baculaclient2-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 1608/bacula-dir
tcp 0 0 0.0.0.0:9102 0.0.0.0:* LISTEN 1643/bacula-fd
tcp 0 0 0.0.0.0:9103 0.0.0.0:* LISTEN 1685/bacula-sd
#在启动bacula的所有服务前,必须启动MySQL数据库,否则连接bacula的控制端是会报错。

2. 在客户端启动bacula的File Daemon
[root@baculaclient etc]#/usr/local/bacula/etc/bacula {start|stop|restart|status}
[root@baculaclient etc]#/usr/local/bacula/etc/bacula-fd {start|stop|restart|status}
#由于baculaclient只做fd端,在此只需启动bacula-fd服务即可
五、bacula备份文件(做备份之前要建立/backup/192.168.1.11/web、/backup/192.168.1.11/database等目录)

1. 执行备份
1.1 第一次增量备份,默认会是一个完全备份 #备份前fd中文件有index1.html
*run
A job name must be specified.
The defined Job resources are:
1: 192.168.1.11_database_job 2: 192.168.1.11_web_job 3: 192.168.1.12_database_job 4: 192.168.1.12_web_job 5: Restore_192.168.1.11_web_job 6: Restore_192.168.1.11_database_job 7: Restore_192.168.1.12_web_job 8: Restore_192.168.1.12_database_jobSelect Job resource (1-8): 2 #选择备份任务
Run Backup job
JobName: 192.168.1.11_web_job
Level: Incremental
Client: 192.168.1.11-fd
FileSet: web_filese
Pool: File (From Job resource)
Storage: 192.168.1.11_web_storage (From Job resource)
When: 2012-12-14 8:56:58
Priority: 12
OK to run? (yes/mod/no): yes
Job queued. JobId=1
#到处为止,可以开始备份了,在bacula-dir.conf文件中定义的192.168.1.11_web_job是一个增量备份,因此这个备份只是一个增量操作,由于是第一个备份,因此默认192.168.1.11_web_job会做一个完全备份,第二次备份时才执行增量备份

1.2
第二次增量备份,只做增量操作
#备份前fd中文件有index1.html、index2.html

*run
A job name must be specified.
The defined Job resources are:
1: 192.168.1.11_database_job 2: 192.168.1.11_web_job 3: 192.168.1.12_database_job 4: 192.168.1.12_web_job 5: Restore_192.168.1.11_web_job 6: Restore_192.168.1.11_database_job 7: Restore_192.168.1.12_web_job 8: Restore_192.168.1.12_database_jobSelect Job resource (1-8): 2 #选择备份任务
Run Backup job
JobName: 192.168.1.11_web_job
Level: Incremental
Client: 192.168.1.11-fd
FileSet: web_filese
Pool: File (From Job resource)
Storage: 192.168.1.11_web_storage (From Job resource)
When: 2012-12-14 8:56:58
Priority: 12
OK to run? (yes/mod/no): yes
Job queued. JobId=2
#这是第二备份,只做一个增量操作

1.3 第三次备份,手动改为差异备份 #备份前fd中文件有index1.html、index2.html 、index3.html
*run
A job name must be specified.
The defined Job resources are:
1: 192.168.1.11_database_job 2: 192.168.1.11_web_job 3: 192.168.1.12_database_job 4: 192.168.1.12_web_job 5: Restore_192.168.1.11_web_job 6: Restore_192.168.1.11_database_job 7: Restore_192.168.1.12_web_job 8: Restore_192.168.1.12_database_jobSelect Job resource (1-8): 2 #选择备份任务
Run Backup job
JobName: 192.168.1.11_web_job
Level: Incremental
Client: 192.168.1.11-fd
FileSet: web_filese
Pool: File (From Job resource)
Storage: 192.168.1.11_web_storage (From Job resource)
When: 2012-12-14 8:58:58
Priority: 12OK 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: 192.168.1.11_web_jobb
Level: Differential
Client: 192.168.1.11-fd
FileSet: 192.168.1.11_web_storage
Pool: File (From Job resource)
Storage: 192.168.1.11_web_storage (From Job resource)
When: 2012-12-14 9:00:15
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=3

2. 查看备份状态
*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.2.10 (14 June 2012) i686-pc-linux-gnu RedHat Enterprise release
Daemon started 14- 1212 09:00, 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
===================================================================================
Full Backup 58 14-Dec-12 00:00 192.168.1.11_database_job 2012-12-14-4Incremental Backup 57 14-Dec-12 02:03 192.168.1.11_web_job 2012-12-14-4Full Backup 58 14-Dec-12 00:20 192.168.1.12_database_job 2012-12-14-4Full Backup 58 14-Dec-12 00:25 192.168.1.12_web_job 2012-12-14-4====

Running Jobs:
Console connected at 14- 1212 09:00
No Jobs running.
====

Terminated Jobs:
JobId Level Files Bytes Status Finished Name
====================================================================
1 Full 2,400 97.14 M OK 14-Dec-12 08:57 192.168.1.11_web_job
2 Incr 88 10 M OK 14-Dec-12 08:58 192.168.1.11_web_job
3 Diff 100 14 M OK 14-Dec-12 08:59 192.168.1.11_web_job
#显示备份任务192.168.1.11_web_job第一次为完全备份,第二次为增量备份,第三次为差异备份。

3.查看备份文件
[root@baculaserver etc]# ls /backup/192.168.1.11/web
2012-12-14-1 2012-12-14-2 2012-12-14-3

本文出自 “别有天地” 博客,请务必保留此出处http://liuqs.blog.51cto.com/4933198/1088035
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: