Barman
======

インスタンスが\ ``config.yml`` の\ ``barman``
ロールを持つ場合、TPAはインスタンスを `Barman <https://pgbarman.org/>`_ サーバーとして構成して、\ ``backup``
設定で名前を付けている他のインスタンスのバックアップを取ります。

.. code:: yaml

   instances:

   - Name: one
     backup: two
     …


   - Name: two
     role:
     - barman
     …

複数の\ ``postgres`` インスタンスは、\ ``backup``
と同じ名前のBarmanサーバーを持つことができます。 ``postgres``
インスタンスは、 ``backup``
として名前付けのBarmanサーバーのリストを持つことができます。この場合、バックアップはすべての名前付けサーバーに取得されます。

デフォルトのBarman構成は、\ ``pg_receivewal``
を使用してPostgreSQLに接続し、WALの継続的なバックアップを取得します。週に2回、sshでrsyncを使用してインスタンスの完全なバックアップを取得します。完全なバックアップとWALは、過去4週間の任意のポイントにリカバリーできるように十分な期間保持されます。

Barman構成
----------

各Barmanサーバーでは、グローバル構成ファイルが\ ``/etc/barman.conf``
として作成されます。このファイルには、多くのBarman構成変数のデフォルト値が含まれています。バックアップされるPostgresサーバーごとに、追加のBarman構成ファイルが作成されます。たとえば、サーバー\ ``one``
をバックアップする場合、ファイルは\ ``/etc/barman.d/one.conf``
であり、バックアップは\ ``/var/lib/barman/one``
に保存されます。ファイル名とディレクトリ名は、バックアップされたインスタンスの\ ``backup_name``
設定から取得されます。この設定のデフォルトはインスタンス名です。

バックアップされたインスタンスでは、次の変数を設定できます。これらは、接頭辞\ ``barman_``
が削除された状態でBarmanの構成にパススルーされます。

.. csv-table::
  :header: Variable,Default
  :widths: 25,15
  :align: left
  :class: longtable

  barman_archiver,false
  barman_log_file,/var/log/barman.log
  barman_backup_method,rsync
  barman_compression,pigz
  barman_reuse_backup,link
  barman_parallel_jobs,1
  barman_backup_options,concurrent_backup
  barman_immediate_checkpoint,false
  barman_network_compression,false
  barman_basebackup_retry_times,3
  barman_basebackup_retry_sleep,30
  barman_minimum_redundancy,3
  barman_retention_policy,RECOVERY WINDOW OF 4 WEEKS
  barman_last_backup_maximum_age,1 WEEK
  barman_pre_archive_retry_script,""
  barman_post_backup_retry_script,""
  barman_post_backup_script,""
  barman_streaming_wals_directory,""

バックアップ スケジュール
-------------------------

TPAは、1分ごとに実行され、\ ``barman cron``
を呼び出してメンテナンスタスクを実行するcronジョブを\ ``/etc/cron.d/barman``
にインストールします。

バックアップされるインスタンスごとに、TPAはそのインスタンスのバックアップを取得する別のcronジョブを\ ``/etc/cron.d/<backup_name>``
にインストールします。このジョブは、インスタンスの\ ``barman_backup_interval``
変数の決定に従って実行されます。デフォルトでは、毎週水曜日と土曜日の04:00にバックアップが作成されます。

SSHキー
-------

TPAは、
postgresおよびbarmanユーザーのsshキーペアを生成し、それぞれの\ ``~/.ssh``
ディレクトリにインストールします。 postgresユーザーのキーはbarman
``authorized_keys`` ファイルに追加され、barmanユーザーのキーはpostgres
``authorized_keys`` ファイルに追加されます。
postgresユーザーはBarmanサーバーにssh接続してWALセグメント構成されている場合を必要とし、barmanユーザーはPostgresインスタンスにssh接続してバックアップを取得または復元できる必要があります。
