实验环境
服务器列表
服务器用途 | IP地址 | 主机名 |
---|---|---|
备份客户端 | 192.168.3.242 | client.abc.local |
备份服务器 | 192.168.3.241 | mhvtl.abc.local |
部署说明
客户端的bacula-fd是连接到服务器端的bacula-dir进行信令交换,数据还是由客户端的bacula-fd传输到服务器端的bacula-sd,由bacula-sd依据存储配置写入磁盘,或者写入虚拟带库。
安装Bacula
服务器端
安装MySQL数据库
# rpm -ivh mysql-5.1.52-1.el6_0.1.x86_64.rpm
# rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
# rpm -ivh mysql-server-5.1.52-1.el6_0.1.x86_64.rpm
安装MySQL的开发库,Bacula安装依赖这个库
# rpm -ivh mysql-devel-5.1.52-1.el6_0.1.x86_64.rpm
启动MySQL数据库,并设置为自启动
# /etc/init.d/mysqld start
# chkconfig mysqld on
# chkconfig save
Bacula-7.0.5源代码安装
# ./configure --prefix=/opt/bacula --with-mysql
# make -j4 && make install
初始化Bacula的数据库
# cd /opt/bacula/etc
# ./create_mysql_database
# ./grant_mysql_privileges
# ./make_mysql_tables
客户端安装
Bacula-7.0.5源代码安装
# ./configure --prefix=/opt/bacula --enable-client-only
# make -j4 && make install
安装mhVTL
依赖包检测
# rpm -qa | grep gcc
# rpm -qa | grep mtx
# rpm -qa | grep mt-st
# rpm -qa | grep lsscsi
# rpm -qa | grep zlib-devel
# rpm -qa | grep kernel-devel
# rpm -qa | grep kernel-headers
# rpm -qa | grep lzo
安装lzo
# tar xvfz lzo-2.03.tar.gz
# cd lzo-2.03
# ./configure
# make
# make install
mhVTL内核部分安装
# tar xvfz mhvtl-2015-04-14.tgz
# cd mhvtl-1.5/
# cd kernel
# make
# make install
mhVTL用户空间部分安装
创建用户以及组
# groupadd vtl
# useradd -g vtl vtl
mhVTL的目录说明:
/etc/mhvtl 配置文件路径
/opt/mhvtl 虚拟带库存储路径
安装mhVTL
# cd mhvtl-1.5
# make
# make install
# chown -R vtl:vtl /opt/mhvtl
这一步是必需的,要不然,启动mhvtl的时候,会报make_vtl_media failed.的错误
# /etc/init.d/mhvtl start
启动mhVTL的后台进程
查看虚拟带库信息
# lsscsi -g
配置Bacula
配置客户端的bacula-fd
客户端的bacula-fd要连接到服务器端的bacula-dir。
首先要从服务器端的bacula-dir,查到密码,该密码配置到客户端的bacula-fd的配置文件中。
客户端的bacula-fd的配置文件: /opt/bacula/etc/bacula-fd.conf
#
# List Directors who are permitted to contact this File daemon
#
Director {
Name = mhvtl.abc.local-dir
Password = "14lZimZpIxKEojaXLeIP9JErh+TP6X4yj9M0Zm8rElHe"
# 密码取自服务器端的bacula-dir的配置文件
}
#
# Restricted Director, used by tray-monitor to get the
# status of the file daemon
#
Director {
Name = mhvtl.abc.local-mon
Password = "XZWY6ZmuZufnNmepKtD1OrIVjhUG835dUfyumCp6Icb5"
# 密码取自服务器端的bacula-dir的配置文件
Monitor = yes
}
其他配置采用默认配置。
配置服务端的bacula
服务器端的bacula安装完成后,默认配置,bconsole和bacula-sd是直接与的bacula-dir进行信令交互。
配置任务主要分为以下几部分:
- 配置客户端,设置备份数据的来源,主要配置Client,FileSet;
- 配置存储设备,设置备份数据的目的地,主要配置Storage,Device;
- 配置备份任务,完成备份数据的操作,主要配置Job,Pool。
配置客户端
配置客户端是在/opt/bacula/etc/bacula-dir.conf文件中新增配置信息。
# Client (File Services) to backup
Client {
Name = client.abc.local-fd
Address = 192.168.3.242
FDPort = 9102
Catalog = MyCatalog
Password = "14lZimZpIxKEojaXLeIP9JErh+TP6X4yj9M0Zm8rElHe"
# password for FileDaemon
File Retention = 60 days # 60 days
Job Retention = 6 months # six months
AutoPrune = yes # Prune expired Jobs/Files
}
# 设置在该客户端需要备份的数据
FileSet {
Name = "client_file_set"
Include {
Options {
signature = MD5
}
File = "/backup_data"
}
}
配置存储设备
配置存储设备是在/opt/bacula/etc/bacula-dir.conf文件中新增配置信息。
# Definition of LTO-4 tape Autochanger device
Storage {
Name = LTO-4
# Do not use "localhost" here
Address = 192.168.3.241 # N.B. Use a fully qualified name here
# 该地址是备份客户端需要连接的地址,不能设置为localhost,除非fd也是在sd一台机器上。
SDPort = 9103
Password = "36AnQ4edqOhPSO/M/y+zFdxLp00R2Kve6ilSu8Cx270+"
# password for Storage daemon
Device = LTO-4 # must be same as Device in Storage daemon
Media Type = LTO-4 # must be same as MediaType in Storage daemon
Maximum Concurrent Jobs = 10
}
针对设备的配置是在/opt/bacula/etc/bacula-sd.conf文件中新增配置信息。
#
# 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 = "/opt/bacula/etc/mtx-changer %c %o %S %a %d"
Changer Device = /dev/sg10
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'"
}
在这里需要配置mhvtl模拟的机械臂和磁带驱动的设备文件。
Archive Device是设置磁带驱动的设备文件。一般设置为/dev/st*或者/dev/nst*,其中nst*是操作完成后不自动回卷磁带, st*则是自动回卷, 一般常用nst*。
Changer Device是设置机械臂的设备文件。一般设置为/dev/sg*。
配置备份任务
配置备份任务是在/opt/bacula/etc/bacula-dir.conf文件中新增配置信息。
Job {
Name = "ClientBackup-1"
Client = client.abc.local-fd # 设置备份客户端
JobDefs = "DefaultJob"
FileSet = "client_file_set" # 设置备份的数据
Storage = LTO-4 # 设置备份数据的目的地
Pool = Default
Spool Data = yes # Avoid shoe-shine 避免对同一磁带重复写入数据
}
测试
服务器端启动bacula服务
# cd /opt/bacula/etc
# ./bacula start
# 同时启动bacula-dir, bacula-sd, 以及本机的bacula-fd服务。
客户端启动bacula-fd服务
# cd /opt/bacula/etc
# ./bacula-ctl-fd start
# 启动备份客户端上的bacula-fd服务。
在服务器端手工装载磁带
# mtx -f /dev/sg10 load 1 0
在服务器端启动bacula的控制台服务
# cd /opt/bacula/etc
# ./bconsole
Connecting to Director localhost:9101
1000 OK: 1 mhvtl.abc.local-dir Version: 7.0.5 (28 July 2014)
Enter a period to cancel a command.
*label # 先要对存储池进行命名
The defined Storage resources are:
1: File1
2: File2
3: LTO-4
Select Storage resource (1-3): 3
Enter new Volume name: LTO-4
Defined Pools:
1: Default
2: File
3: Scratch
Select the Pool (1-3): 1
Connecting to Storage daemon LTO-4 at 192.168.3.241:9103 ...
Sending label command for Volume "LTO-4" Slot 0 ...
No slot defined in catalog (slot=0) for Volume "" on "LTO-4" (/dev/nst0).
Cartridge change or "update slots" may be required.
3920 Cannot label Volume because it is already labeled: "tape-001"
Label command failed for Volume LTO-4.
Do not forget to mount the drive!!!
*run # 执行备份任务
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
1: BackupClient1
2: ClientBackup-1
3: BackupCatalog
4: RestoreFiles
Select Job resource (1-4): 2
Run Backup job
JobName: ClientBackup-1
Level: Incremental
Client: client.abc.local-fd
FileSet: client_file_set
Pool: Default (From Job resource)
Storage: LTO-4 (From Job resource)
When: 2015-08-07 02:42:58
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=26
You have messages.
通过status命令可以查看备份任务的状态。
问题处理
1. mhVTL的磁带的容量的大小的修改
编辑/etc/mhvtl/mhvtl.conf文件,可以调整磁带的容量大小。
# cat /etc/mhvtl/mhvtl.conf
..........
# Default media capacity (500 M)
CAPACITY=20480 # 调整为20G
..........
但是,重启mhvtl的服务,其实是不会修改磁带的容量,该配置已经写入每个磁带的meta文件。
解决办法, 在/opt/mhvtl目录下,删除所有的子目录,再启动mhvtl的服务,这个时候,/opt/mhvtl目录下的子目录会重建,并且磁带的容量会进行调整。