Barman
======

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

.. code:: yaml

   instances:

   - Name: one
     backup: two
     …


   - Name: two
     role:
     - barman
     …

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

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

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

BarmanサーバーのBarmanホームディレクトリは、クラスター変数\ ``barman_home``
を使用して設定できます。デフォルト値は\ ``/var/lib/barman`` です。

各Barmanサーバーでは、グローバル構成ファイルが\ ``/etc/barman.conf``
として作成されます。このファイルには、多くのBarman構成変数のデフォルト値が含まれています。バックアップされるPostgresサーバーごとに、追加のBarman構成ファイルが作成されます。たとえば、サーバー\ ``one``
をバックアップするには、ファイルは\ ``/etc/barman.d/one.conf``
で、バックアップは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は、\ ``/etc/cron.d/barman``
にcronジョブをインストールします。これは1分ごとに実行され、\ ``barman cron``
を呼び出してメンテナンスタスクを実行します。

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

SSHキー
-------

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