paloma blog

NWエンジニアやってます。主に自宅環境のお遊びを書きます。Pythonもちょっと。タイトルは好きなカクテルから。

Baculaでバックアップ環境を構築する

今年の始めにメイン機が壊れてはや5ヶ月。
ようやく環境は戻ったのでそろそろバックアップをとろうと思います。
HDDが壊れた時の再イントールはめんどくさいですからね。

今は主に使っているのがwindowsubuntuがあるので両方のバックアップがとれるソフトにしたいと思います。
というわけでいい感じにできそうなBaculaで環境を作ります。

https://blog.bacula.org/

www.bacula.jp

私は普段ネットワークエンジニアとして働いているので、恥ずかしながらサーバやマシンのシステムバックアップはしっかり取ったことありません。
NW機器はtextのconfigファイルとっとけばなんとかなるんです。
仮想マシンならゲストのクローンとかスナップショットってイメージつくんですが、物理マシンはなかなか・・・。
ちゃんとできるかな。

環境

bacula.jpの手順に沿ってやりたいと思います。

www.bacula.jp

CentOS7でインストールするみたいですが、環境がないので取り急ぎVirutalboxのVMで構築します。
(今気づきましたがホスト名のスペルミスってました。次直します。)

[root@bakula ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 
[root@bakula ~]# uname -a
Linux bakula 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

CentOS7のminimalイメージから手順のとおり設定します。

  • Firewalld停止
[root@bakula ~]# systemctl stop firewalld
[root@bakula ~]# 
[root@bakula ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 日 2018-05-13 21:42:29 JST; 8s ago
     Docs: man:firewalld(1)
  Process: 665 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 665 (code=exited, status=0/SUCCESS)

 513 21:34:06 bakula systemd[1]: Starting firewalld - dynamic firewall daemon...
 513 21:34:08 bakula systemd[1]: Started firewalld - dynamic firewall daemon.
 513 21:42:28 bakula systemd[1]: Stopping firewalld - dynamic firewall daemon...
 513 21:42:29 bakula systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@bakula ~]# 
[root@bakula ~]# cd /etc/yum.repos.d/
[root@bakula yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]#  wget https://copr.fedorainfracloud.org/coprs/slaanesh/Bacula/repo/epel-7/slaanesh-Bacula-epel-7.repo
--2018-05-13 21:43:16--  https://copr.fedorainfracloud.org/coprs/slaanesh/Bacula/repo/epel-7/slaanesh-Bacula-epel-7.repo
copr.fedorainfracloud.org (copr.fedorainfracloud.org) をDNSに問いあわせています... 209.132.184.54
copr.fedorainfracloud.org (copr.fedorainfracloud.org)|209.132.184.54|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 326 [text/plain]
`slaanesh-Bacula-epel-7.repo' に保存中

100%[======================================================================================>] 326         --.-K/s 時間 0s      

2018-05-13 21:43:23 (45.5 MB/s) - `slaanesh-Bacula-epel-7.repo' へ保存完了 [326/326]
  • パッケージインストール
[root@bakula yum.repos.d]# yum -y install bacula-director bacula-client bacula-storage bacula-console mariadb-server
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
slaanesh-Bacula                                                                                          | 3.0 kB  00:00:00     
slaanesh-Bacula/x86_64/primary_db                                                                        |  13 kB  00:00:06     
依存性の解決をしています
--> トランザクションの確認を実行しています。
...
完了しました!
  • 確認
    • Baculaですが、今時点では系が最新のようです。
[root@bakula yum.repos.d]# rpm -qa | grep bacula
bacula-common-9.0.6-5.el7.centos.x86_64
bacula-libs-sql-9.0.6-5.el7.centos.x86_64
bacula-director-9.0.6-5.el7.centos.x86_64
bacula-client-9.0.6-5.el7.centos.x86_64
bacula-libs-9.0.6-5.el7.centos.x86_64
bacula-storage-9.0.6-5.el7.centos.x86_64
bacula-console-9.0.6-5.el7.centos.x86_64
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# rpm -qa | grep mariadb
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl start mariadb
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2018-05-13 21:49:48 JST; 16s ago
 Main PID: 10779 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─10779 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─10941 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-err...

 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: MySQL manual for more instructions.
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: Please report any problems at http://mariadb.org/jira
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: The latest information about MariaDB is available at http://mari...org/.
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: You can find additional information about the MySQL part at:
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: http://dev.mysql.com
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: Consider joining MariaDB's strong and vibrant community:
 5月 13 21:49:46 bakula mariadb-prepare-db-dir[10701]: https://mariadb.org/get-involved/
 5月 13 21:49:47 bakula mysqld_safe[10779]: 180513 21:49:47 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
 5月 13 21:49:47 bakula mysqld_safe[10779]: 180513 21:49:47 mysqld_safe Starting mysqld daemon with databases from /va.../mysql
 5月 13 21:49:48 bakula systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@bakula yum.repos.d]# 
  • セキュアインストール
[root@bakula yum.repos.d]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@bakula yum.repos.d]# 
  • データベース&ユーザ作成
[root@bakula yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> show tables;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> create database bacula;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> grant all privileges on bacula.* to bacula@localhost identified by 'password"
    '> ;
    '> 
    '> ;
    '> Ctrl-C -- exit!
Aborted
[root@bakula yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

MariaDB [(none)]> 
MariaDB [(none)]> quit
Bye
  • Bacula用テーブル作成
[root@bakula yum.repos.d]# /usr/libexec/bacula/make_bacula_tables mysql -u bacula -p
Making mysql tables
Enter password: 
Creation of Bacula MySQL tables succeeded.
[root@bakula yum.repos.d]# 
  • 使用するデータベース選択
[root@bakula yum.repos.d]#  alternatives --config libbaccats.so

3 プログラムがあり 'libbaccats.so' を提供します。

  選択       コマンド
-----------------------------------------------
   1           /usr/lib64/libbaccats-mysql.so
   2           /usr/lib64/libbaccats-sqlite3.so
*+ 3           /usr/lib64/libbaccats-postgresql.so

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:1
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# alternatives --config libbaccats.so

3 プログラムがあり 'libbaccats.so' を提供します。

  選択       コマンド
-----------------------------------------------
 + 1           /usr/lib64/libbaccats-mysql.so
   2           /usr/lib64/libbaccats-sqlite3.so
*  3           /usr/lib64/libbaccats-postgresql.so

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:
[root@bakula yum.repos.d]# 

ここまででインストール完了。
configをいじっていきます。

設定ファイル

Baculaサーバ設定 | Bacula

これもサイトのとおり設定します。 いろいろパラメータがありますが、まだ触り始めたばかりなので、慣れてきたらカスタムしていこうと思います。

3つデーモンを動かすようですね。

  1. Directorデーモン
    • 全体管理。DB連携もやる。
  2. Storageデーモン
    • バックアップしたデータ管理
  3. Fileデーモン
    • バックアップ対象マシンにインストールする

それぞれバックアップ取って設定。

[root@bakula ~]# cp /etc/bacula/bacula-dir.conf{,.org} 
[root@bakula ~]# vi /etc/bacula/bacula-dir.conf
[root@bakula ~]# 
[root@bakula ~]# cd /etc/bacula/
[root@bakula bacula]# ls
bacula-dir.conf  bacula-dir.conf.org  bacula-fd.conf  bacula-sd.conf  bconsole.conf  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bacula-fd.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bacula-fd.conf 
[root@bakula bacula]# 
[root@bakula bacula]# ls
bacula-dir.conf  bacula-dir.conf.org  bacula-fd.conf  bacula-fd.conf.org  bacula-sd.conf  bconsole.conf  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bacula-sd.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bacula-sd.conf
[root@bakula bacula]# ls
bacula-dir.conf      bacula-fd.conf      bacula-sd.conf      bconsole.conf
bacula-dir.conf.org  bacula-fd.conf.org  bacula-sd.conf.org  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bconsole.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bconsole.conf
  • 起動します
[root@bakula bacula]# systemctl start bacula-dir
[root@bakula bacula]# systemctl start bacula-sd
[root@bakula bacula]# systemctl start bacula-fd
  • 確認
    • bacula-dirだけFileset部分の構文をミスっていたのであとから取りました。
[root@bakula bacula]# systemctl status bacula-dir
● bacula-dir.service - Bacula-Director, the Backup-server
   Loaded: loaded (/usr/lib/systemd/system/bacula-dir.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 22:51:42 JST; 7s ago
     Docs: man:bacula-dir(8)
 Main PID: 7506 (bacula-dir)
   CGroup: /system.slice/bacula-dir.service
           └─7506 /usr/sbin/bacula-dir -f -c /etc/bacula/bacula-dir.conf -u bacula -g bacula

 524 22:51:42 bakula systemd[1]: Started Bacula-Director, the Backup-server.
 524 22:51:42 bakula systemd[1]: Starting Bacula-Director, the Backup-server...
[root@bakula bacula]# 
[root@bakula bacula]# systemctl status bacula-fd
● bacula-fd.service - Bacula-FileDaemon, a Backup-client
   Loaded: loaded (/usr/lib/systemd/system/bacula-fd.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 20:53:03 JST; 29s ago
     Docs: man:bacula-fd(8)
 Main PID: 7221 (bacula-fd)
   CGroup: /system.slice/bacula-fd.service
           └─7221 /usr/sbin/bacula-fd -f -c /etc/bacula/bacula-fd.conf -u root -g root

 524 20:53:03 bakula systemd[1]: Started Bacula-FileDaemon, a Backup-client.
 524 20:53:03 bakula systemd[1]: Starting Bacula-FileDaemon, a Backup-client...
[root@bakula bacula]# 
[root@bakula bacula]# systemctl status bacula-sd
● bacula-sd.service - Bacula-StorageDaemon, the storage-server
   Loaded: loaded (/usr/lib/systemd/system/bacula-sd.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 20:53:01 JST; 39s ago
     Docs: man:bacula-sd(8)
 Main PID: 7212 (bacula-sd)
   CGroup: /system.slice/bacula-sd.service
           └─7212 /usr/sbin/bacula-sd -f -c /etc/bacula/bacula-sd.conf -u bacula -g tape

 524 20:53:01 bakula systemd[1]: Started Bacula-StorageDaemon, the storage-server.
 524 20:53:01 bakula systemd[1]: Starting Bacula-StorageDaemon, the storage-server...
[root@bakula bacula]# 
  • listenポート確認
[root@bakula ~]# ss -lnt
State      Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port              
LISTEN     0      50                                   *:3306                                             *:*                  
LISTEN     0      50                                   *:9101                                             *:*                  
LISTEN     0      50                                   *:9102                                             *:*                  
LISTEN     0      50                                   *:9103                                             *:*                  
LISTEN     0      128                                  *:22                                               *:*                  
LISTEN     0      100                          127.0.0.1:25                                               *:*                  
LISTEN     0      128                                 :::22                                              :::*                  
LISTEN     0      100                                ::1:25                                              :::*                  
[root@bakula ~]# 
[root@bakula ~]# 
  1. Directorデーモン:9101
  2. Storageデーモン:9103
  3. Fileデーモン:9102

らしいです。

とりあえずサービスは立ち上がったので、次回マシンのバックアップを取ってみたいと思います。
この辺の動きが確認できたらGUIの管理コンソールなど入れていくつもりです。
OSのセキュリティ周りも整備しなくては…。