giner.barman
Ansibleロール: Barman
LinuxにBarmanをインストールして設定します。オプションとして:
- 定期バックアップ(cronで実行)
- WALSとスナップショットをS3にアップロード(cronで実行)
- メトリクス収集(Telegrafによる)
このロールはできるだけ中立的に作られており、設定パラメータはすべてBarmanの設定に直接渡されます。
要件
- Ubuntu
インストール
Ansible Galaxyを介してインストール:
ansible-galaxy collection install giner.barman
または、requirements.yml
ファイルにこのロールを含めます:
roles:
- name: giner.barman
ロール変数
使用できる変数は以下の通りで、デフォルト値を含みます(defaults/main.yml
参照):
Barmanの要求された状態。absent
で上書きするとBarmanがアンインストールされます。データは削除されません。
barman_state: started
Barmanパッケージの要求された状態。latest
で上書きするとBarmanがアップグレードされます。
barman_package_state: present
Barmanのグローバル設定の上書き(キー/バリュー)。
barman_config: {}
バックアップ対象のPostgreSQLサーバー。
barman_pg_servers: [] # キーは: name, params, pgpass, cronです。以下に例を示します。
Telegrafを設定してBarmanメトリクスを収集します。
barman_telegraf_enabled: false
メトリクス収集の間隔。
barman_telegraf_interval: 1m
依存関係
なし。
例プレイブック
# PostgreSQLデータベースサーバー上のユーザーとその権限を設定
# http://docs.pgbarman.org/release/2.12/#postgresql-connection
- hosts: postgresqls
vars:
barman_user: barman
barman_pass: BARMANPASS_CHANGEME
barman_streaming_user: streaming_barman
barman_streaming_pass: STREAMINGPASS_CHANGEME
tasks:
- name: PostgreSQLユーザーbarman_userを追加
community.postgresql.postgresql_user:
user: "{{ barman_user }}"
password: "{{ barman_pass }}"
role_attr_flags: replication
groups: [pg_read_all_settings, pg_read_all_stats]
- name: PostgreSQLユーザーbarman_streaming_userを追加
community.postgresql.postgresql_user:
user: "{{ barman_streaming_user }}"
password: "{{ barman_streaming_pass }}"
role_attr_flags: replication
- name: barman_userにpg_XXXのEXECUTE権限を付与
community.postgresql.postgresql_privs:
db: postgres
privs: EXECUTE
type: function
obj: pg_start_backup(text:boolean:boolean),pg_stop_backup(),pg_stop_backup(boolean:boolean),pg_switch_wal(),pg_create_restore_point(text)
schema: pg_catalog
roles: "{{ barman_user }}"
# Barmanをセットアップして設定
- hosts: barmans
vars:
barman_name: mypgserver
barman_pg_hosts: 10.10.10.10
barman_pg_ports: 5432
barman_user: barman
barman_pass: BARMANPASS_CHANGEME
barman_streaming_user: streaming_barman
barman_streaming_pass: STREAMINGPASS_CHANGEME
barman_pg_servers:
- name: "{{ barman_name }}"
params:
- description: "PostgreSQLデータベース(ストリーミングのみ)"
- conninfo: 'host={{ barman_pg_hosts }} port={{ barman_pg_ports }} user={{ barman_user }} dbname=postgres'
- streaming_conninfo: 'host={{ barman_pg_hosts }} port={{ barman_pg_ports }} user={{ barman_streaming_user }}'
- backup_method: "postgres"
- streaming_archiver: "on"
- slot_name: "barman"
- create_slot: "auto"
- retention_policy: "31日間のリカバリウィンドウ"
pgpass:
- "*:*:postgres:{{ barman_user }}:{{ barman_pass }}"
- "*:*:replication:{{ barman_streaming_user }}:{{ barman_streaming_pass }}"
backup_schedule:
cron:
hour: 21
minute: 5
s3_sync:
src: "{{ barman_config['barman_home'] | default('/var/lib/barman') }}/{{ barman_name }}"
dst: "s3://db-backup"
base_cron:
hour: 22
minute: 5
wals_cron:
minute: 10
custom:
job: "barman delete '{{ barman_name }}' oldest"
cron:
hour: 23
minute: 15
roles:
- giner.barman
開発
テスト依存関係をインストール:
python3 -m pip install ansible -Ur requirements-molecule.txt
すべてのテストを実行(Dockerがインストールされている必要があります):
molecule test --all
ライセンス
Apache 2.0
著者
このロールは2021年にスタニスラフ・ゲルマン=エフツシェンコによって作成されました。
プロジェクトについて
Install and configure Barman on Linux with optional: metrics collection (telegraf), regular snapshots (cron) and uploading to S3 (cron)
インストール
ansible-galaxy install giner.barman
ライセンス
apache-2.0
ダウンロード
14.6k