1.Baculaとは
■Baculaとは
Bacula(バキュラ)はLinuxで利用できるメジャーなバックアップソフトウェア。よく一緒に名前の挙がるFreeのLinuxバックアップソフトウェアにAmandaがあるが、Amandaよりもバックアップシステムを構成するアーキテクチャ・役割が細分化されており、エンタープライズ向けの設計。公式サイトの説明には「非常に使い勝手がいい」とか記載されているが概念をちゃんと理解しないと爆死する危険あり。
■baculaのデーモン
下記の3つのデーモンが独立して動作します。Bacula-dirではDBサーバにバックアップ情報を格納するので、DBサーバを別で用意する選択肢もあり。大規模な環境であれば各デーモンごとにサーバを構築して稼働させても良いですが、小規模であればbacula-dirとbacula-sdは同一のサーバで良いと思います。
bacula-dir | バキュラ全体の管理役。バックアップジョブ管理も行う |
bacula-sd | バキュラのバックアップデータ書き込み先のストレージの管理 |
bacula-fd |
バキュラのバックアップを実際に実行するクライアント
|
■カタログ(Catalog)
Baculaのバックアップに必要な情報を格納するデータベースを指す。カタログ=データベースと読み替えても問題ないようです。ちなみにカタログが消失するとバックアップデータそのものが残っていてもリストアできなくなります。定期的にカタログはダンプして別サーバに保管するなどの対策が必要です。
2.Baculaサーバ側の構築
■構成
■ソフトウェアインストール
1 2 3 4 5 6 7 8 9 10 11 |
//yumでinstall yum -y install bacula-director bacula-client bacula-storage bacula-console mysql-server //install確認 [root@lab-backup01 ~]# rpm -qa | grep bacula bacula-storage-mysql-5.0.0-13.el6.x86_64 bacula-director-common-5.0.0-13.el6.x86_64 bacula-client-5.0.0-13.el6.x86_64 bacula-common-5.0.0-13.el6.x86_64 bacula-storage-common-5.0.0-13.el6.x86_64 bacula-director-mysql-5.0.0-13.el6.x86_64 bacula-console-5.0.0-13.el6.x86_64 |
■データベース設定
Baculaはバックアップファイルの保管情報をデータベースに「カタログ」として保管する。カタログとは、Baculaが利用するデータベースのことを指す。
BaculaユーザとBacula用のデータベースを作成する。/usr/libexec/bacula/配下のスクリプトでも代用可能。今回はコマンドで作ります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@lab-backup01 ~]# /etc/init.d/mysqld start [root@lab-backup01 ~]# /usr/bin/mysqladmin -u root password ‘YourPassword' mysql> create database bacula; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on *.* to bacula@localhost identified by 'YourPassword'; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bacula | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> quit Bye |
テーブルは付属のツールを実行して作成します。下記のShellスクリプトを実行すると必要なテーブルが作成されます。。
1 |
/usr/libexec/bacula/make_mysql_tables -u root -p |
実行したらそれらしきテーブルができているか確認しておきましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
[root@backup ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bacula | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> use bacula Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> mysql> mysql> show tables ; +------------------+ | Tables_in_bacula | +------------------+ | BaseFiles | | CDImages | | Client | | Counters | | Device | | File | | FileSet | | Filename | | Job | | JobHisto | | JobMedia | | Location | | LocationLog | | Log | | Media | | MediaType | | Path | | PathHierarchy | | PathVisibility | | Pool | | Status | | Storage | | UnsavedFiles | | Version | +------------------+ 24 rows in set (0.00 sec) |
■設定ファイル編集
Baculaサーバ(dirデーモン、sdデーモン)の動作設定を行います。fdデーモン(クライアントデーモン)も設定しているのは、Baculaサーバ自身のバックアップも行わせるためとなります。
まずバックアップを作成しておきます。設定ファイルに記載されているパスワードを書き換えます。今回はbaculaで使用する全てのパスワードを統一して設定します。
1 2 3 4 5 6 7 8 9 10 |
//Config Backup cp -a /etc/bacula/bacula-dir.conf /etc/bacula/bacula-dir.conf.default cp -a /etc/bacula/bacula-sd.conf /etc/bacula/bacula-sd.conf.default cp -a /etc/bacula/bacula-fd.conf /etc/bacula/bacula-fd.conf.default cp -a /etc/bacula/bconsole.conf /etc/bacula/bconsole.conf.default //パスワードの箇所を書き換えます。 sed -i -e "s/@@.*_PASSWORD@@/パスワード/g" /etc/bacula/bacula-dir.conf sed -i -e "s/@@.*_PASSWORD@@/パスワード/g" /etc/bacula/bacula-sd.conf sed -i -e "s/@@.*_PASSWORD@@/パスワード/g" /etc/bacula/bacula-fd.conf sed -i -e "s/@@.*_PASSWORD@@/パスワード/g" /etc/bacula/bconsole.conf |
■Baculaデーモン起動
まとめて起動します。
1 2 3 |
/etc/init.d/bacula-fd start /etc/init.d/bacula-sd start /etc/init.d/bacula-dir start |
■設定ファイルのインクルード設定
動作には影響ありませんが、設定ファイルがデフォルトで非常にごっちゃごちゃしているので、管理しやすいよう別ファイルで設定できるようにしておきます。
まずbacula-dirの共有設定を記載するファイルをcommon.confという名前で作成します。
まずbacula-dirの共有設定を記載するファイルをcommon.confという名前で作成します。
1 2 3 4 |
[root@lab-backup01 ~]# mkdir /etc/bacula/lab-servers.d [root@lab-backup01 ~]# touch /etc/bacula/lab-servers.d/common.conf [root@lab-backup01 ~]# chown root:bacula /etc/bacula/lab-servers.d/common.conf [root@lab-backup01 ~]# chmod 640 /etc/bacula/lab-servers.d/common.conf |
上で作成したcommon.confをインクルードさせるパラメータをメインのコンフィグ末尾に追記します。
1 2 3 4 |
vi /etc/bacula/bacula-dir.conf //末尾に追記 #Share config Include @/etc/bacula/lab-servers.d/common.conf |
共通設定ファイル&テンプレートファイルの作成
今回は以下のように役割を分けています。
common.conf
|
各サーバで共通設定とするバックアップ設定をまとめて記載。メインコンフィグでインクルード。
|
template.conf
|
新しくバックアップ対象を追加するときにコピーして利用するテンプレ的なファイル。
IPアドレスとホスト名をダミーの値にしておく。(xx.xx.xx.xx, template.com) テンプレート
なのでIncludeはしない。
|
■共通設定ファイル
[root@backup ~]# cat /etc/bacula/lab-servers.d/common.conf
Schedule {
Name = “lab-schedule01”
Run = Full mon at 04:05
Run = Incremental tue-sun at 04:05
}
FileSet {
Name = “server all data”
Include {
Options {
signature = MD5
}
File = /
}
Exclude {
File = /var/spool/bacula
File = /tmp
File = /proc
File = /.journal
File = /.fsck
}
}
Storage {
Name = nas_server
Address = 10.24.96.140
SDPort = 9103
Password = “YourPassword”
Device = FileStorage
Media Type = File
}
Pool {
Name = lab_backup_pool
Pool Type = Backup
Recycle = yes
AutoPrune = yes
Volume Retention = 7 days
}
|
■templateファイル
Job {
Name = “template.com”
Type = Backup
Level = Full
Client = “template.com”
FileSet = “server all data”
Schedule = “lab-schedule01”
Storage = nas_server
Messages = Standard
Pool = lab_backup_pool
Priority = 10
Write Bootstrap = “/var/spool/bacula/%c.bsr”
}
Job {
Name = “template.com_Restore”
Type = Restore
Client=”template.com”
FileSet=”server all data”
Storage = nas_server
Pool = lab_backup_pool
Messages = Standard
Where = /nas/bacula/restores
}
Client {
Name = “template.com”
Address = xx.xx.xx.xx
FDPort = 9102
Catalog = MyCatalog
Password = “YourPassword”
File Retention = 30 days # 30 days
Job Retention = 6 months # six months
AutoPrune = yes # Prune expired Jobs/Files
}
|
3.Bacula-Clientのインストールと初期設定
サーバ側と違い設定はごくシンプルです。Bacula-fdデーモンのパスワード設定を変更し、サーバ側から接続できる状態にしてあげるだけです。
クライアントインストールは下記実行。
1 |
[root@CentOS6-Base-Template01 ~]# yum install bacula-client |
パスワード情報を書き換える。以上
1 |
sed -i -e "s/@@.*_PASSWORD@@/パスワード/g" /etc/bacula/bacula-fd.conf |
4.動作確認
バックアップ
リストア
運用コマンド
■手動バックアップの実行
status
label
list media
run
■baculaリストア方法
bconsole
restoreを選択する。
5: Select the most recent backup for a client
んでlsコマンドを使用してレストアを実行する。
■データベースのバックアップ
■Bacula-Severが死んだ場合のレストア
■通知先変更