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サーバーで、グローバル構成ファイルが\ ``/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は、毎分実行され、\ ``barman cron``
を呼び出してメンテナンスタスクを実行する\ ``/etc/cron.d/barman``
にcronジョブをインストールします。

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

SSHキー
-------

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