LoginSignup
13
13

More than 5 years have passed since last update.

Baculaの構築

Last updated at Posted at 2016-07-29

Baculaでバックアップサーバを構築した際の設定です。特にbacula-dirの設定が面倒でした。

概要

Baculaはバックアップサーバを構築するためのソフトウェアです。大規模システムにまで幅広く利用でき、商用のソフトウェアにも匹敵する機能を備えたシステムになることを目指して開発されました。

下図のような構成になっており、各コンポーネントごとに設定が必要で、別々のサーバに構築することも可能です。

Bacula_Main_Components.jpg

概要
サーバ
Director Bacula全体を管理する司令塔的な役割を持っています。データベースと連携して、すべてのクライアントに関するバックアップ、リストア情報を管理し、ジョブの実行を管理します。
Storage バックアップしたデータを管理します。ハードディスク、テープ、さまざまな記録媒体を使用できます。
Catalog Baculaで使用されるデータベースをカタログと呼びます。役割は一般的なデータベースと同様です。
Console Baculaを操作するためのコンソールです。CUIではbconsole、GUIではbatなどがあります。
クライアント
File バックアップ対象のホスト上で動作するエージェントです。役割としてBaculaサーバのDirectorと通信して、バックアップおよびリストアを行います。

サーバの設定

今回は全てのコンポーネントを同一サーバ上に構築した場合の設定になります。別々でも大きくは変わらないと思います。

  • OS : CentOS 7.2

リポジトリの追加

下記リポジトリを追加することで最新バージョンをインストールできます。

# cd /etc/yum.repos.d/
# wget https://repos.fedorapeople.org/repos/slaanesh/bacula7/epel-bacula7.repo

Storage

# yum install bacula-storage
# firewall-cmd --add-service=bacula --permanent
# firewall-cmd --reload

あらかじめ、Archive Deviceに指定したディレクトリを作成しておき、パーミッションも変更しておきます。

# chown -R bacula:bacula /var/bacula/backup/
# chmod -R 700 /var/bacula/backup/
/etc/bacula/bacula-sd.conf
Storage {
  Name = bacula-sd # Storageの名前
  SDPort = 9103
  WorkingDirectory = "/var/spool/bacula"
  Pid Directory = "/var/run"
  Maximum Concurrent Jobs = 20
}

Director {
  Name = bacula-dir #このNameのDirectorからのアクセスを↓
  Password = "baculasd" # 許可するパスワード
}

Director {
  Name = bacula-mon
  Password = "baculamon"
  Monitor = yes # 状態の参照のみ許可
}

Device {
  Name = FileStorage # Deviceの名前
  Media Type = File
  Archive Device = /var/bacula/backup # ここにデータが保管される
  LabelMedia = yes;
  Random Access = Yes;
  AutomaticMount = yes;
  RemovableMedia = no;
  AlwaysOpen = no;
}

Messages {
  Name = Standard
  director = bacula-dir = all
}
# systemctl start bacula-sd
# systemctl enable bacula-sd

Console

GUIを使う際はbacula-console-batも必要です。

# yum install bacula-console bacula-conosole-bat

consoleの設定

/etc/bacula/bconsole.conf
Director {
  Name = bacula-dir # このNameのDirectorからのアクセスを↓
  DIRport = 9101
  address = 192.168.10.10
  Password = "baculadir" # 許可するパスワード
}

batの設定

bconsole.confと同じです。

/etc/bacula/bat.conf
Director {
  Name = bacula-dir
  DIRport = 9101
  address = 192.168.10.10
  Password = "baculadir"
}

アクセス権とかを変えておきます。

# chgrp bacula /etc/bacula/bat.conf
# chmod g+r /etc/bacula/bat.conf
# gpasswd -a bacula bacula

Consoleの操作

  • bconsoleで起動、qで終了
  • statusでステータスの取得
  • runでバックアップを即時実行
  • messageでジョブの実行内容が表示され、メールを設定していればログがメールで送信される

Batの操作

  • 「アプリケーション」 → 「システムツール」 → 「Bacula Bat Console」を起動

Baculum

Baculaの状態が確認できるWebGUIです。

インストール方法はこちら

スクリーンショット 2016-07-29 16.30.24.png

Director

Baculaはここが難関だと思います。

# yum install bacula-director

Catalogの設定

(バックアップファイルのインデックスや媒体を管理するデータの管理)
CentOS 7からデフォルトDBになったMariaDBを想定しています。

MariaDBの設定

# yum install mariadb-server
# systemctl start mariadb
# systemctl enable mariadb
# firewall-cmd --permanent --add-service=mysql
# firewall-cmd --reload
# mysqladmin -u root password 'rootpass'
# mysqladmin -p -u root -h localhost password 'rootpass'

BaculaでのMariaDBの利用設定

# alternatives --set libbaccats.so /usr/lib64/libbaccats-mysql.so
# mysql -u root -p
Enter password: 

DB [(none)]> CREATE DATABASE bacula;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on bacula.* to bacula@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> set password for bacula@localhost=password('baculapass');
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

# /usr/libexec/bacula/make_mysql_tables -u bacula -h localhost -p

Directorのメイン設定

/etc/bacula/bacula-dir.conf
# Default Bacula Director Configuration file
Director {
  Name = bacula-dir # Directorの名前
  DIRport = 9101
  QueryFile = "/etc/bacula/query.sql"
  WorkingDirectory = "/var/spool/bacula"
  PidDirectory = "/var/run"
  Maximum Concurrent Jobs = 20
  Password = "baculadir" # DirectorのPassword
  Messages = Daemon
}

# Default Job
JobDefs {
  Name = "DefaultJob"
  Type = Backup
  Level = Incremental
  Client = bacula-fd
  FileSet = "Full Set"
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = Default
  Full Backup Pool = Full-Pool
  Incremental Backup Pool = Inc-Pool
  SpoolAttributes = yes
  Priority = 10
  Write Bootstrap = "/var/spool/bacula/%c.bsr"
}

###############################################################
##
## Define the main nightly save backup job
##
###############################################################
Job {
  Name = "Backup-client1" 
  JobDefs = "DefaultJob"
}

Job {
  Name = "Backup-client2" 
  JobDefs = "DefaultJob"
  Client=client2-fd
}

###############################################################

# Backup the catalog database (after the nightly save)
Job {
  Name = "BackupCatalog"
  JobDefs = "DefaultJob"
  Level = Full
  FileSet="Catalog"
  Schedule = "WeeklyCycleAfterBackup"
  RunBeforeJob = "/usr/libexec/bacula/make_catalog_backup.pl MyCatalog"
  RunAfterJob  = "/usr/libexec/bacula/delete_catalog_backup"
  Write Bootstrap = "/var/spool/bacula/%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=bacula-fd
  FileSet="Full Set"
  Storage = File
  Pool = Default
  Messages = Standard
  Where = /tmp/bacula-restores
}

###############################################################
# List of files to be backed up
# for linux
FileSet {
  Name = "Full Set"
  Include {
    Options {
      signature = MD5
      Compression = GZIP
    }
    # Backup files
    File = / # フルバックアップ
  }
  # Not backup files
  Exclude {
    File = /proc
    File = /tmp
    File = /.journal
    File = /.fsck
  }
}

# This is the backup of the catalog
FileSet {
  Name = "Catalog"
  Include {
    Options {
      signature = MD5
    }
    File = "/var/spool/bacula/bacula.sql"
  }
}
###############################################################

# When to do the backups
Schedule {
  Name = "WeeklyCycle"
  Run = Full 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:05
}

###############################################################
#
# Client (File Services) to backup
#
###############################################################
Client {
  Name = bacula-fd
  Address = 192.168.10.10
  FDPort = 9102
  Catalog = MyCatalog
  Password = "baculafd" # password for FileDaemon
  File Retention = 7 days 
  Job Retention = 7 days
  AutoPrune = yes
}

Client {
  Name = client2-fd
  Address = 192.168.10.11
  FDPort = 9102
  Catalog = MyCatalog
  Password = "client2fd" # password for FileDaemon
  File Retention = 7 days 
  Job Retention = 7 days
  AutoPrune = yes
}

###############################################################

# Definition of file storage device
Storage {
  Name = File
  # Do not use "localhost"
  Address = 192.168.10.10
  SDPort = 9103
  Password = "baculasd"
  Device = FileStorage
  Media Type = File
}

# Generic catalog service
Catalog {
  Name = MyCatalog
  dbname = "bacula"; dbuser = "bacula"; dbpassword = "baculapass"
}

# Reasonable message delivery -- send most everything to email address
#  and to the console
Messages {
  Name = Standard
  mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: %t %e of %c %l\" %r"
  operatorcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula: Intervention needed for %j\" %r"
  mail = root@localhost = all, !skipped # 設定しておくとJob実行後にメールが来ます。
  operator = root@localhost = mount
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
}

# Message delivery for daemon messages (no job)
Messages {
  Name = Daemon
  mailcommand = "/usr/sbin/bsmtp -h localhost -f \"\(Bacula\) \<%r\>\" -s \"Bacula daemon message\" %r"
  mail = root@localhost = all, !skipped
  console = all, !skipped, !saved
  append = "/var/log/bacula/bacula.log" = all, !skipped
}

###############################################################
# Default pool definition
Pool {
  Name = Default
  Pool Type = Backup
  Recycle = yes                       # Bacula can automatically recycle Volumes
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 7 days
}

# Full backup pool
Pool {
  Name = Full-Pool
  Pool Type = Backup
  Recycle = yes
  AutoPrune = yes
  Volume Retention = 7 days
  Maximum Volume Jobs = 1
  Label Format = Full-
  Maximum Volumes = 10
}

# Incremental backup pool
Pool {
  Name = Inc-Pool
  Pool Type = Backup
  Recycle = yes
  AutoPrune = yes
  Volume Retention = 7 days
  Maximum Volume Jobs = 7
  Label Format = Inc-
  Maximum Volumes = 10
}

# Scratch pool definition
Pool {
  Name = Scratch
  Pool Type = Backup
}

###############################################################

# Restricted console used by tray-monitor to get the status of the director
Console {
  Name = bacula-mon
  Password = "baculaxmon"
  CommandACL = status, .status
}

Storageリソースの設定では、Addressにbacula-sdが動作しているサーバを指定しますが、bacula-fdから問い合わせできるようにしないといけないので、localhostにしてはいけません。また、まれに名前解決できない場合があるのでIPアドレスを指定します。

設定の確認

# bacula-dir -tc /etc/bacula/bacula-dir.conf
# systemctl start bacula-dir
# systemctl enable bacula-dir

クライアントの設定

バックアップ対象のサーバに設定します。

# cd /etc/yum.repos.d/
# wget https://repos.fedorapeople.org/repos/slaanesh/bacula7/epel-bacula7.repo
# yum install bacula-client
# firewall-cmd --add-service=bacula-client --permanent
# firewall-cmd --reload

Client

/etc/bacula/bacula-fd.conf
Director {
  Name = bacula-dir # この名前のbacula-dirからのアクセスを許可する↓
  Password = "baculafd" # パスワード
}

Director {
  Name = bacula-mon
  Password = "baculamon"
  Monitor = yes
}

FileDaemon {        
  Name = bacula-fd # Clientの名前
  FDport = 9102
  WorkingDirectory = /var/spool/bacula
  Pid Directory = /var/run
  Maximum Concurrent Jobs = 20
}

Messages {
  Name = Standard
  director = bacula-dir = all, !skipped, !restored
}
# systemctl start bacula-fd
# systemctl enable bacula-fd

参考

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13