paloma blog

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

8月になった

先月は仕事が忙しくて全部記事をかけませんでした。
openpyxlさえ入れとけばexcel方眼紙の設計書なんか瞬殺だと思っていたけど甘かったです。

今のフォーマットを崩さず入出力をどうすっかと考えながらて入力してます。


先月は着手できなかったけど夏の間にやりたいことメモっときます。

  • portainer.ioを触ってみる
    • LXDがシンプルで好きですが、時代の流れはDockerが修理だと思いますので軽めの管理ツールを触ってみようかなと。
      kubernetesやrancherは個人で触るには思い気がします。
  • proxyサーバを立ててみる
    • 自宅のトラフィックログを取ってみたくなったので作ってみます。
      NW機器買ったりするよりお手軽にできるはず
  • VPSを契約する
    • このブログは技術用ブログで使いたいので他の話は別にwordpressとかで作ろうかなと考えてます。
      せっかくなのでサイトの運用経験もつけようでVPSでやるつもりです。 どこ使うかは検討中。

twitterで通勤中にブログかくと捗るよって言うツイートを見たので今日試してみました。
でもスマホだと書きづらいし画像やソースも張りづらいです。

PC持ち出して書くほどでもないのでやりたいことを思いとどめるだけにした方が良さそうです。
あと途中で一回公開ボタン押してしまいました(笑)

pythonで出力した通信要件を加工する

7月に入りました。2018年も折り返しです。
今年は本プログの記事を週一ペースで50本上げることが目標なのですが、ちょっと足りてないですね。 後半頑張れるか…


前回出力した通信要件をもう少し加工します。

(python3) masashi@PC-ubuntu:~/trafficsorting$ python traffic.py 
<Worksheet "通信一覧">
any 192.168.10.1/24 TCP 80
any 192.168.10.2/24 TCP 80
<Worksheet "通信一覧">
192.168.10.1/24 192.168.20.1/24 TCP 8009
192.168.10.1/24 192.168.20.2/24 TCP 8009
192.168.10.2/24 192.168.20.1/24 TCP 8009
192.168.10.2/24 192.168.20.2/24 TCP 8009
<Worksheet "通信一覧">
192.168.20.1/24 192.168.30.1/24 TCP 1521
192.168.20.2/24 192.168.30.1/24 TCP 1521
<Worksheet "通信一覧">
192.168.40.1/24 192.168.10.1/24 ICMP -
192.168.40.1/24 192.168.10.2/24 ICMP -
<Worksheet "通信一覧">
192.168.40.1/24 192.168.20.1/24 ICMP -
192.168.40.1/24 192.168.20.2/24 ICMP -
<Worksheet "通信一覧">
192.168.40.1/24 192.168.30.2/24 ICMP -
192.168.40.1/24 192.168.30.3/24 ICMP -

こんな感じでわっと出るのですがconfig等に利用したいのでもう少し加工します。

成形

シート名を出すようにしたのですが邪魔なので消します。
pythonだけで完結できたらいいのですが、未熟なものでshellの力を借ります。

(python3) masashi@PC-ubuntu:~/trafficsorting$ python traffic.py | grep -vE "Error|^<"
any 192.168.10.1/24 TCP 80
any 192.168.10.2/24 TCP 80
192.168.10.1/24 192.168.20.1/24 TCP 8009
192.168.10.1/24 192.168.20.2/24 TCP 8009
192.168.10.2/24 192.168.20.1/24 TCP 8009
192.168.10.2/24 192.168.20.2/24 TCP 8009
192.168.20.1/24 192.168.30.1/24 TCP 1521
192.168.20.2/24 192.168.30.1/24 TCP 1521
192.168.40.1/24 192.168.10.1/24 ICMP -
192.168.40.1/24 192.168.10.2/24 ICMP -
192.168.40.1/24 192.168.20.1/24 ICMP -
192.168.40.1/24 192.168.20.2/24 ICMP -
192.168.40.1/24 192.168.30.2/24 ICMP -
192.168.40.1/24 192.168.30.3/24 ICMP -

これで通信だけになりました。
出た結果をファイルにリダイレクトして、さらにネットワークに変換する処理を咬ませます。

ipaddressモジュール

ipaddressというモジュールを使います。

IPv4Interfaceというクラスがあり、
CIDR表記のIPアドレスをネットワークアドレスに変換してくれます。

ルーティング、ACLはネットワーク単位で書くことが多いのでこの変換は大変便利です。

さっきの結果をネットワークアドレスに変換するプログラムです。
文字列はエラー吐いてしまうのでこれもtryでハンドリングします。
(馬鹿の一つ覚えみたいにtry文を使ってしまいます)

いろんな本をちょろちょろ読んでるので、pythonの書き方がバラバラです。
そろそろ統一していかないと。

#!/usr/bin/env python3
import ipaddress

def main():
    with open('pattern.txt') as f:
        for row in f:
            try:
                column = row.strip().split()
                print(ipaddress.IPv4Interface(column[0]).network, ipaddress.IPv4Interface(column[1]).network, column[3])
            except:
                print('Error: ', column[0], column[1], column[3])


main()
  • さっきリダイレクトしたファイルをread
  • 列操作をしやすくするためにスペース区切りにする
  • 1列目、2列目をネットワークアドレスに変換して出力ついでにポート番号も入れておきます。
  • 文字列がある行はErrorの文字をつけて出力

動かしてみる

(python3) masashi@PC-ubuntu:~/trafficsorting$ python subnet.py 
Error:  any 192.168.10.1/24 80
Error:  any 192.168.10.2/24 80
192.168.10.0/24 192.168.20.0/24 8009
192.168.10.0/24 192.168.20.0/24 8009
192.168.10.0/24 192.168.20.0/24 8009
192.168.10.0/24 192.168.20.0/24 8009
192.168.20.0/24 192.168.30.0/24 1521
192.168.20.0/24 192.168.30.0/24 1521
192.168.40.0/24 192.168.10.0/24 -
192.168.40.0/24 192.168.10.0/24 -
192.168.40.0/24 192.168.20.0/24 -
192.168.40.0/24 192.168.20.0/24 -
192.168.40.0/24 192.168.30.0/24 -
192.168.40.0/24 192.168.30.0/24 -

サブネットに変換されましたね。
これだと重複行がでるのでここでもshellの力を借ります。

(python3) masashi@PC-ubuntu:~/trafficsorting$ python subnet.py | sort | uniq
192.168.10.0/24 192.168.20.0/24 8009
192.168.20.0/24 192.168.30.0/24 1521
192.168.40.0/24 192.168.10.0/24 -
192.168.40.0/24 192.168.20.0/24 -
192.168.40.0/24 192.168.30.0/24 -
Error:  any 192.168.10.1/24 80
Error:  any 192.168.10.2/24 80

このようにパターンがシンプルになりました。
サンプルなんで全部24ビットで書いてしまいましたが他のサブネットで書いてもちゃんと出力してくれます。

今回はここまでしか動かしていませんが、sedawkで処理すればそのままconfigに使えそうです。

Error行は処理をまるまるスキップさせたので手で変換しないといけないですが、
any -> 0.0.0.0/0みたいにIPアドレスに変換して綺麗にしてしまいたいですね。

まとめ

pythonファイルが分割していたり途中でshellを挟んだりとエレガントさに欠ける処理ですが、
目視で確認していくよりずっと早く落とし込みができそうです。

通信要件の資料って書く人によってばらつきがあるので、綺麗に出したければ自分で元ファイルを修正する必要がありますが、何とか使いやすい形に持ってくることができました。

このフローは日々の業務で発生するので、メンテして使いやすくしていきたいと思います。
本チャンの資料は上げられませんがコードはgithubにでもあげようかな。

ipaddressモジュール、IPアドレス用の処理がいろいろできそうでネットワークエンジニアとしていろいろ遊んでみたいですが、うまい使い道が思い浮かばないですね。
IPv6変換とかできたら使えるかな?

pythonで通信要件を一意に出力する

私はSIerのネットワークエンジニアとして働いているのですが、どこのシステムでも設計のために通信要件一覧というのがあると思います。
(Web系の業界は詳しくないので使っていないかも)

FWやルーティング設計のために、通信名, From, To, Portなど書かれることが多いと思います。

また、資料はExcelで作られているものが多いと思いますが、方眼紙とまではいかなくても使い勝手はよくありません。
正直私の現場では使いづらいです。

こんな感じ

サンプルなので適当に作りましたが、送信元、宛先、IPアドレス、ポートなどは最低限書いてあると思います。
(Ubuntuで検証したのでLibreOfficeです)

f:id:paloma69:20180629001724p:plain

ネットで調べてもこんな感じのが出てきます。

小規模システムなら良いですが、大規模で大量の種類の通信があるシステムもこの様に書かれると、
読むのもパラメータに落とすのも一苦労です。
書き方によっては重複の行がいくつか出てくることもあります。

対象のセルをコピーして他の資料に貼り付ければいいのですが、
セル内改行のものがあったりすると一気に使い勝手が悪くなります。

こういうのをいちいち転記するのも馬鹿らしいので、Configに落としていく際に簡単にできないかと思いpythonで書いてみました。

やりたいこと

  • 各Cellに書かれている値を抽出する
  • Cellに数行書かれている場合も1行ずつ出力する
  • Config作成用にIPアドレスとポートだけ出力する

Excelファイルを処理するのはopenpyxlモジュールでやります。

今回ファイルは同階層におきます。

(python3) masashi@PC-ubuntu:~/trafficsorting$ ls
traffic.py  通信要件.xlsx
  • IPとポートだけ出力できれば良いのでD,F,G,H列だけ処理します。
  • 処理が途中で止まらないように書き方が変なセルは行数をメモっときます。
    • まだハンドリングが不完全なので空白でも反応してしまいます。
  • 複数シートがある場合を想定して一応シート名も出力します。
  • セル内改行してあるものは改行コードで文字列を分割します。
  • 全パターン抽出するにはforをネストすることによってできるようです。
    (もっと綺麗な方法があるかも)
#!/usr/bin/env python3

import openpyxl

wb = openpyxl.load_workbook("通信要件.xlsx", data_only = True)

wsa = wb['通信一覧']

def Traffic(sheet, ret):
    try:
        # All pattern output for each cell value
        for src in sheet['D' + str(ret)].value.split():
            for dst in sheet['F' + str(ret)].value.split():
                    for ptc in sheet['G' + str(ret)].value.split():
                            for port in str(sheet['H' + str(ret)].value).split():
                                print(src, dst, ptc, port)
    except:
        print(str(ret) + ' row has Error!')
        print('Cell\'s value is "x.x.x.x/x" with numbers only.')
        pass

# Display sheet to last line
for a in range(3, wsa.max_row + 1):
    print(wsa)
    Traffic(wsa, a)

動かしてみる

(python3) masashi@PC-ubuntu:~/trafficsorting$ python traffic.py 
<Worksheet "通信一覧">
any 192.168.10.1/24 TCP 80
any 192.168.10.2/24 TCP 80
<Worksheet "通信一覧">
192.168.10.1/24 192.168.20.1/24 TCP 8009
192.168.10.1/24 192.168.20.2/24 TCP 8009
192.168.10.2/24 192.168.20.1/24 TCP 8009
192.168.10.2/24 192.168.20.2/24 TCP 8009
<Worksheet "通信一覧">
192.168.20.1/24 192.168.30.1/24 TCP 1521
192.168.20.2/24 192.168.30.1/24 TCP 1521
<Worksheet "通信一覧">
192.168.40.1/24 192.168.10.1/24 ICMP -
192.168.40.1/24 192.168.10.2/24 ICMP -
<Worksheet "通信一覧">
192.168.40.1/24 192.168.20.1/24 ICMP -
192.168.40.1/24 192.168.20.2/24 ICMP -
<Worksheet "通信一覧">
192.168.40.1/24 192.168.30.2/24 ICMP -
192.168.40.1/24 192.168.30.3/24 ICMP -

ちゃんと出ました!

全てのパターンに対し、一意な値で出力できました。
また、テキストで出力する事により検索等しやすくなりました。

シート名が都度出てしまうのがかっこ悪いのでもう少し綺麗にしたいですね。

改修は置いといて次回は出力結果をもう少し加工したいと思います。

その他課題

セルが結合してあると結合がある行がまるまるエラーとして出力されてしまったので、実はExcelを修正しました。
これはどう直すかな…

pythonのmain関数についてメモ

Baculaについて残課題はいろいろ残っていますが、いったんバックアップも取れたのでまたほかの事書きたいと思います。

というわけでまたpythonです。


今「Python Programming: An Introduction to Computer Science」という本を読んでいます。
その中にmain関数について説明している部分があったのでメモします。

  • pythonプログラムの実行について

    • 直接実行するもの
    • 他のプログラムからインポートされる
      • ライブラリと呼ばれる
  • これまで(書籍内のサンプルコード)はmain関数を呼び出す行が一番下にあった

こんなの

def main():
    print(’Hello’)

main()
  • Pythonはインポートプロセス中にモジュールの行を評価する
  • 一般にモジュールをimportする際はモジュールを実行させないほうが良い
  • インポートされたか、直接実行できるプログラムでは一番下のmainへの呼び出しを条件付きにする必要がある
if __name__=='__main__':
    main()
  • モジュールがインポートされるたびに、pythonはimportされたモジュールの名前にnameという名前のモジュール内の特別な変数を設定する。
>>> import math
>>> 
>>> math.__name__
'math'
>>> 
>>> __name__
'__main__'
  • mathをimportするとname変数にmathが割り当てられている
  • pythonコードが直接実行(not import)されている場合、pythonはnameの値をmainに設定する

つまりこの記載となっているモジュールをインポートしてもname変数がmainでないため、処理が実行されないということですね。
余計な動きをさせないようにってことでいいのかな?

いろんなブログとかでこの表記が出てきていまいちわからなかったけどなんとなく動きが理解できました。
name変数が何者なのかも調べたいな。

Baculaでバックアップを取ってみる ubuntu client編

前回のバックアップから間が空いてしまいましたが別マシンのバックアップを挑戦します。

2台目クライアント追加

下記手順を参考に2台めのクライアント設定を追記します。

簡易版チュートリアル – Bacula

サーバ側

  • bacula-dir.conf

jobに2台目を追加。

# 1台目
Job {
  Name = "BackupClient1"
  JobDefs = "DefaultJob"
}

# 2台目
Job {
  Name = "BackupClient2"
  Client = PC-ubuntu-fd
  JobDefs = "DefaultJob"
}

clientも。

# 1台目
Client {
  Name = bacula-fd
  Address = localhost
  FDPort = 9102
  Catalog = MyCatalog
  Password = "bacula-fd"          # password for FileDaemon
  File Retention = 60 days            # 60 days
  Job Retention = 6 months            # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}

# 2台目
Client {
  Name = PC-ubuntu-fd
  Address = 192.168.0.10
  FDPort = 9102
  Catalog = MyCatalog
  Password = "bacula-fd"          # password for FileDaemon
  File Retention = 60 days            # 60 days
  Job Retention = 6 months            # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}  

Storageも修正

Autochanger {
  Name = File1
# Do not use "localhost" here
# Addressの行を外のサーバからもつつけるように外向けのIPに変更する
  Address = 192.168.0.12                # N.B. Use a fully qualified name here
  SDPort = 9103
  Password = "bacula-sd"
  Device = FileChgr1
  Media Type = File1
  Maximum Concurrent Jobs = 10        # run up to 10 jobs a the same time
  Autochanger = File1                 # point to ourself
}

クライアント側

  • ubuntu16.04 LTS デスクトップです。
  • bacula-clientをインストール。

9系は一部のパッケージがインストールできなかったため、標準のリポジトリからインストールします。

  • 9系のbuild手順

bacula.us

依存で入るdefault-libmysqlclient-devというパッケージが17.10からサポートされていないため、9系は諦めます。

Ubuntu – Package Search Results -- default-libmysqlclient-dev

masashi@PC-ubuntu:~$ sudo apt install bacula-client

7系がインストールされます。

masashi@PC-ubuntu:~$ dpkg -l | grep bacula
ii  bacula-client                               7.0.5+dfsg-4ubuntu0.1                        all          network backup service - client metapackage
ii  bacula-common                               7.0.5+dfsg-4ubuntu0.1                        amd64        network backup service - common support files
ii  bacula-console                              7.0.5+dfsg-4ubuntu0.1                        amd64        network backup service - text console
ii  bacula-fd                                   7.0.5+dfsg-4ubuntu0.1                        amd64        network backup service - file daemon
  • bacula-fd.conf
#
# List Directors who are permitted to contact this File daemon
#
Director {
  Name = bacula-dir 
  Password = "bacula-fd"
}

#
# Restricted Director, used by tray-monitor to get the
#   status of the file daemon
#
Director {
  Name = 192.168.0.12 #bacula-dir と書くとconfigtestでエラーになる
  Password = "Bacula"
  Monitor = yes
}

#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = PC-ubuntu-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /var/lib/bacula
  Pid Directory = /var/run/bacula
  Maximum Concurrent Jobs = 20
# Plugin Directory = /usr/lib/bacula
  FDAddress = 192.168.0.10 #127.0.0.1
}

それぞれサービスをrestart

  • 手順は割愛

サーバから接続してみます。

[root@bacula bacula]# bconsole
Connecting to Director localhost:9101
1000 OK: 103 bacula-dir Version: 9.0.6 (20 November 2017)
Enter a period to cancel a command.
*
*status client
The defined Client resources are:
     1: bacula-fd
     2: PC-ubuntu-fd
Select Client (File daemon) resource (1-2): 2
Connecting to Client PC-ubuntu-fd at 192.168.0.10:9102

PC-ubuntu-fd Version: 7.0.5 (28 July 2014)  x86_64-pc-linux-gnu ubuntu 16.04
Daemon started 14- 6��2018 01:08. Jobs: run=0 running=0.
 Heap: heap=143,360 smbytes=187,691 max_bytes=187,838 bufs=53 max_bufs=54
 Sizes: boffset_t=8 size_t=8 debug=0 trace=0 mode=0,0 bwlimit=0kB/s

Running Jobs:
Director connected at: 14- 6��2018 01:08
No Jobs running.
====

Terminated Jobs:
====
*
*

version7で見えてます。

runでバックアップします。

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: BackupClient1
     2: BackupClient2
     3: BackupCatalog
     4: RestoreFiles
Select Job resource (1-4): 2
Run Backup job
JobName:  BackupClient2
Level:    Incremental
Client:   PC-ubuntu-fd
FileSet:  Full Set
Pool:     File (From Job resource)
Storage:  File1 (From Job resource)
When:     2018-06-14 01:28:10
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=40
*

runningにならない…

*status dir
bacula-dir Version: 9.0.6 (20 November 2017) x86_64-redhat-linux-gnu redhat (Core)
Daemon started 14- 6��2018 01:23, conf reloaded 14- 6-2018 01:23:03
 Jobs: run=0, running=1 mode=0,0
 Heap: heap=270,336 smbytes=102,538 max_bytes=137,949 bufs=339 max_bufs=343
 Res: njobs=4 nclients=2 nstores=2 npools=3 ncats=1 nfsets=2 nscheds=2

Scheduled Jobs:
Level          Type     Pri  Scheduled          Job Name           Volume
===================================================================================
Incremental    Backup    10  14- 6��2018 23:05  BackupClient1      Vol-0019
Incremental    Backup    10  14- 6��2018 23:05  BackupClient2      Vol-0019
Full           Backup    11  14- 6��2018 23:10  BackupCatalog      Vol-0019
====

Running Jobs:
Console connected at 14- 6��2018 01:27
 JobId  Type Level     Files     Bytes  Name              Status
======================================================================
    40  Back Full          0         0  BackupClient2     is waiting for Client PC-ubuntu-fd to connect to Storage File1
====

Terminated Jobs:
 JobId  Level      Files    Bytes   Status   Finished        Name 
====================================================================
    19  Full           0         0   Error    02- 6��2018 23:05 JOB-Bacula-ubuntu
    20  Full           0         0   Error    02- 6��2018 23:05 BackupClient1
    21  Full           0         0   Error    02- 6��2018 23:10 BackupCatalog
    22  Full           0         0   Error    03- 6��2018 20:14 JOB-Bacula-ubuntu
    23  Full           0         0   Error    03- 6��2018 23:05 JOB-Bacula-ubuntu
    24  Full           0         0   Error    03- 6��2018 23:05 BackupClient1
    25  Full           0         0   Error    03- 6��2018 23:10 BackupCatalog
    26  Full           0         0   Error    04- 6��2018 23:05 JOB-Bacula-ubuntu
    27  Full           0         0   Error    04- 6��2018 23:05 BackupClient1
    28  Full           0         0   Error    04- 6��2018 23:10 BackupCatalog

====
*

もしやと思いfirewalldを止めたらrunningになりました。
後でポート開けないと。
(SELinuxは止めてたような。後で確認しよう)

[root@bacula ~]# systemctl stop firewalld
[root@bacula ~]# 
[root@bacula ~]# 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-06-14 01:30:05 JST; 4s ago
     Docs: man:firewalld(1)
  Process: 658 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 658 (code=exited, status=0/SUCCESS)

 614 01:22:55 bacula systemd[1]: Starting firewalld - dynamic firewall daemon...
 614 01:22:58 bacula systemd[1]: Started firewalld - dynamic firewall daemon.
 614 01:30:05 bacula systemd[1]: Stopping firewalld - dynamic firewall daemon...
 614 01:30:05 bacula systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@bacula ~]# 
[root@bacula ~]# 
[root@bacula ~]# 
[root@bacula ~]# bconsole 
Connecting to Director localhost:9101
1000 OK: 103 bacula-dir Version: 9.0.6 (20 November 2017)
Enter a period to cancel a command.
*
You have messages.
*status dir
bacula-dir Version: 9.0.6 (20 November 2017) x86_64-redhat-linux-gnu redhat (Core)
Daemon started 14- 6��2018 01:23, conf reloaded 14- 6-2018 01:23:03
 Jobs: run=0, running=1 mode=0,0
 Heap: heap=270,336 smbytes=102,296 max_bytes=137,949 bufs=337 max_bufs=343
 Res: njobs=4 nclients=2 nstores=2 npools=3 ncats=1 nfsets=2 nscheds=2

Scheduled Jobs:
Level          Type     Pri  Scheduled          Job Name           Volume
===================================================================================
Incremental    Backup    10  14- 6��2018 23:05  BackupClient1      Vol-0019
Incremental    Backup    10  14- 6��2018 23:05  BackupClient2      Vol-0019
Full           Backup    11  14- 6��2018 23:10  BackupCatalog      Vol-0019
====

Running Jobs:
Console connected at 14- 6��2018 01:30
 JobId  Type Level     Files     Bytes  Name              Status
======================================================================
    40  Back Full          0         0  BackupClient2     is running
====

Terminated Jobs:
 JobId  Level      Files    Bytes   Status   Finished        Name 
====================================================================
    19  Full           0         0   Error    02- 6��2018 23:05 JOB-Bacula-ubuntu
    20  Full           0         0   Error    02- 6��2018 23:05 BackupClient1
    21  Full           0         0   Error    02- 6��2018 23:10 BackupCatalog
    22  Full           0         0   Error    03- 6��2018 20:14 JOB-Bacula-ubuntu
    23  Full           0         0   Error    03- 6��2018 23:05 JOB-Bacula-ubuntu
    24  Full           0         0   Error    03- 6��2018 23:05 BackupClient1
    25  Full           0         0   Error    03- 6��2018 23:10 BackupCatalog
    26  Full           0         0   Error    04- 6��2018 23:05 JOB-Bacula-ubuntu
    27  Full           0         0   Error    04- 6��2018 23:05 BackupClient1
    28  Full           0         0   Error    04- 6��2018 23:10 BackupCatalog

====
*

途中経過

このPCはデスクトップなのでそこそこサイズでかくなりそう。

Running Jobs:
Console connected at 14- 6��2018 01:30
 JobId  Type Level     Files     Bytes  Name              Status
======================================================================
    40  Back Full      9,806    567.7 M BackupClient2     is running
====

ここで事件発生

夜に仕掛けて朝確認しようと思ったんですが、起きたらBaculaサーバが停止していました…
外付けHDDにBaculaサーバの仮想マシンの保存領域があるのですが、このHDDが何故か電源が落ちていて最終的な結果が不明です。

実はbaculaの再起動時にエラーが出ていたので、この辺調べればなにかわかるかも。
サービス再起動に失敗するのでOSごと再起動して検証していました。

[root@bacula bacula]# systemctl restart bacula-dir.conf
Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: GDBus.Error:org.freedesktop.DBus.Error.TimedOut: Failed to activate service 'org.freedesktop.PolicyKit1': timed out (g-dbus-error-quark, 20)
Failed to restart bacula-dir.conf.service: 接続がタイムアウトしました
See system logs and 'systemctl status bacula-dir.conf.service' for details.
[root@bacula bacula]# 

とりあえずクライアント追加の手順もなんとなく出来たので、引き続きWindows機のバックアップもやりたいと思います。

その前にbaculaサーバの復旧か作りなおした方がいいかもですね。
HDDは電源入ったのですが、サーバがEmergency modeで起動しちゃってる…

Baculaでバックアップを取ってみる

なんとかバックアップを取ることに成功したのでメモ。
baculaサーバ自身のバックアップです。

作業概要

  • 設定ファイルを一回リストアした

    • いかにも不要そうな設定は消して動かしてみたのですが、ストレージデーモンに接続できなくなってしまいました。
      デフォルトのconfigをリストアしてパスワードのみ変えて動かしました。
  • 外部ストレージにアクセスできなかった

    • baculaサーバはVMであがってます
    • バックアップ先をホストの外部ストレージにしました。
      しかしマウント、書き込みはOKだったのですがバックアップを開始するとプロセスが進まなかったので一旦ローカルに戻しました。

設定ファイルのメモ

公式マニュアルをに詳しくあると思いますが、一旦自分用のメモ

bacula-dir

  • job、jobdef

    • バックアップのジョブ
    • デフォルト(jobdef)から追記していくっぽい
  • Storage

    • bacula-dirのStorageはlocalhostを設定しない
      各ファイルデーモンはここの設定に見に行く
  • Autochanger

    • Storageのクラスタ
      設定しなくてもOKっぽい
  • Client

    • バックアップ対象クライアントのIP指定
  • Fileset

bacula-sd

  • Autochanger

    • Deviceのクラスタ
    • Nameがディレクタと紐づいているっぽい
  • Device

    • バックアップファイル保存場所
    • Filetypeはディレクタと紐づいている

bacula-fd

  • 各クライアントに設定

バックアップ実行してみる

bconsoleでbaculaコンソールにはいってrunで実行します。
1は設定したバックアップクライアント、2はデータベースのバックアップのようです。
3は不明…

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: BackupClient1
     2: BackupCatalog
     3: RestoreFiles
Select Job resource (1-3): 1
Run Backup job
JobName:  BackupClient1
Level:    Incremental
Client:   bacula-fd
FileSet:  Full Set
Pool:     File (From Job resource)
Storage:  File1 (From Job resource)
When:     2018-06-05 20:00:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=32
You have messages.
*

完了すると履歴に出ます。
日付のところが文字化けしてるけど何だろ?
あとErrorが出てるのは過去の失敗の履歴です。

*status dir
bacula-dir Version: 9.0.6 (20 November 2017) x86_64-redhat-linux-gnu redhat (Core)
Daemon started 05- 6��2018 18:56, conf reloaded 05- 6-2018 18:56:52
 Jobs: run=4, running=0 mode=0,0
 Heap: heap=270,336 smbytes=142,664 max_bytes=185,328 bufs=335 max_bufs=389
 Res: njobs=3 nclients=1 nstores=2 npools=3 ncats=1 nfsets=2 nscheds=2

Scheduled Jobs:
Level          Type     Pri  Scheduled          Job Name           Volume
===================================================================================
Incremental    Backup    10  05- 6��2018 23:05  BackupClient1      Vol-0019
Full           Backup    11  05- 6��2018 23:10  BackupCatalog      Vol-0019
====

Running Jobs:
Console connected at 05- 6��2018 19:59
No Jobs running.
====

Terminated Jobs:
 JobId  Level      Files    Bytes   Status   Finished        Name 
====================================================================
    23  Full           0         0   Error    03- 6��2018 23:05 JOB-Bacula-ubuntu
    24  Full           0         0   Error    03- 6��2018 23:05 BackupClient1
    25  Full           0         0   Error    03- 6��2018 23:10 BackupCatalog
    26  Full           0         0   Error    04- 6��2018 23:05 JOB-Bacula-ubuntu
    27  Full           0         0   Error    04- 6��2018 23:05 BackupClient1
    28  Full           0         0   Error    04- 6��2018 23:10 BackupCatalog
    29  Full           0         0   Incomplete  05- 6��2018 19:18 BackupClient1
    30  Full           0         0   Incomplete  05- 6��2018 19:32 BackupClient1
    31  Full           0         0   Cancel   05- 6��2018 19:59 BackupClient1
    32  Full      70,123    1.423 G  OK       05- 6��2018 20:05 BackupClient1  # 先ほどの成功ログ

====
*

リストアしてみる

クライアントのリストアは5番を選択します。
対象クライアントは2番の自信です。
1は別のマシンなので今度バックアップからやります。
Full setで取ったファイルをリストアになるようです。

*restore 
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"

First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.

To select the JobIds, you have the following choices:
     1: List last 20 Jobs run
     2: List Jobs where a given File is saved
     3: Enter list of comma separated JobIds to select
     4: Enter SQL list command
     5: Select the most recent backup for a client
     6: Select backup for a client before a specified time
     7: Enter a list of files to restore
     8: Enter a list of files to restore before a specified time
     9: Find the JobIds of the most recent backup for a client
    10: Find the JobIds for a backup for a client before a specified time
    11: Enter a list of directories to restore for found JobIds
    12: Select full restore to a specified Job date
    13: Cancel
Select item:  (1-13): 5
Defined Clients:
     1: PC-ubuntu-fd
     2: bacula-fd
Select the Client (1-2): 2
The defined FileSet resources are:
     1: Catalog
     2: Full Set
Select FileSet resource (1-2): 2
+-------+-------+----------+---------------+---------------------+------------+
| JobId | Level | JobFiles | JobBytes      | StartTime           | VolumeName |
+-------+-------+----------+---------------+---------------------+------------+
|    32 | F     |   70,123 | 1,423,788,515 | 2018-06-05 20:00:05 | Vol-0019   |
+-------+-------+----------+---------------+---------------------+------------+
You have selected the following JobId: 32

Building directory tree for JobId(s) 32 ...  +++++++++++++++++++++++++++++++++++++++++
57,724 files inserted into the tree.

続いて対象のファイルを選択します。
今回はbaculaのディレクトリをリストアしてみます。
configは私は作成した退避用ディレクトリです。

You are now entering file selection mode where you add (mark) and
remove (unmark) files to be restored. No files are initially added, unless
you used the "all" keyword on the command line.
Enter "done" to leave this mode.

cwd is: /
$ cd /etc/
cwd is: /etc/
$ cd bacula
cwd is: /etc/bacula/
$ ls
bacula-dir.conf
bacula-dir.conf.org
bacula-fd.conf
bacula-fd.conf.org
bacula-sd.conf
bacula-sd.conf.org
bconsole.conf
bconsole.conf.org
config/
query.sql
$ 

移動したらmarkします。
つけたファイルのみリストアされます。
doneで実行。
空エンターはエラーになってます。

$ mark *
12 files marked.
$ 
Invalid command "".  Enter "done" to exit.
$ ls
*bacula-dir.conf
*bacula-dir.conf.org
*bacula-fd.conf
*bacula-fd.conf.org
*bacula-sd.conf
*bacula-sd.conf.org
*bconsole.conf
*bconsole.conf.org
*config/
*query.sql
$ 
Invalid command "".  Enter "done" to exit.
$ 
Invalid command "".  Enter "done" to exit.
$ done

いろいろ出て完了。

Bootstrap records written to /var/spool/bacula/bacula-dir.restore.1.bsr

The Job will require the following (*=>InChanger):
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
   
    Vol-0019                  File1                     FileChgr1                

Volumes marked with "*" are in the Autochanger.


14 files selected to be restored.

Using Catalog "MyCatalog"
Run Restore job
JobName:         RestoreFiles
Bootstrap:       /var/spool/bacula/bacula-dir.restore.1.bsr
Where:           /tmp/bacula-restores
Replace:         Always
FileSet:         Full Set
Backup Client:   bacula-fd
Restore Client:  bacula-fd
Storage:         File1
When:            2018-06-05 20:09:15
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=33
*

デフォルトは/tmp/bacula-restores配下にリストアされるようです。

[root@bacula bacula]# ls -l /tmp/bacula-restores/etc/bacula/
合計 68
-rw-r-----. 1 root   root   9165  65 18:42 bacula-dir.conf
-rw-r-----. 1 bacula bacula 9186  519 19:29 bacula-dir.conf.org
-rw-r-----. 1 bacula bacula 1048  65 18:44 bacula-fd.conf
-rw-r-----. 1 bacula bacula 1067  524 19:01 bacula-fd.conf.org
-rw-r-----. 1 root   root   9795  65 19:59 bacula-sd.conf
-rw-r-----. 1 bacula bacula 9814  524 19:06 bacula-sd.conf.org
-rw-r-----. 1 bacula bacula  239  524 19:09 bconsole.conf
-rw-r-----. 1 bacula bacula  249  524 19:09 bconsole.conf.org
drwxr-xr-x. 2 root   root     51  65 18:39 config
-rw-r-----. 1 bacula bacula  312  129 21:38 query.sql
[root@bacula bacula]# 

元のディレクトリ見ると同じ状態になってますね。
ファイルのリストアができました!

[root@bacula bacula]# ls -l /etc/bacula/
合計 68
-rw-r-----. 1 root   root   9165  65 18:42 bacula-dir.conf
-rw-r-----. 1 bacula bacula 9186  519 19:29 bacula-dir.conf.org
-rw-r-----. 1 bacula bacula 1048  65 18:44 bacula-fd.conf
-rw-r-----. 1 bacula bacula 1067  524 19:01 bacula-fd.conf.org
-rw-r-----. 1 root   root   9795  65 19:59 bacula-sd.conf
-rw-r-----. 1 bacula bacula 9814  524 19:06 bacula-sd.conf.org
-rw-r-----. 1 bacula bacula  239  524 19:09 bconsole.conf
-rw-r-----. 1 bacula bacula  249  524 19:09 bconsole.conf.org
drwxr-xr-x. 2 root   root     51  65 18:39 config
-rw-r-----. 1 bacula bacula  312  129 21:38 query.sql
[root@bacula bacula]# 

バックアップはルートディレクトリから取ってるのでリストア先をルートにすればOSごとリストア出来るんですかね?
余裕があればやってみます。

バックアップの残作業

  • ubuntuのバックアップを取る
  • Windoswsのバックアップを取る
  • バックアップ先を別ディレクトリにする。

とりあえずバックアップを取れればよいのでConfigの精査は後回しにします。
次はubuntuのバックアップをやってみます。

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のセキュリティ周りも整備しなくては…。