From 99504fed92577795e1ab0bf2ec0cd30a2435799f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Helleboid?= Date: Thu, 2 May 2019 17:24:20 +0200 Subject: Allow to set options for barman connectivity - Allow to pass arbitrary options - Build the URL in a dedicated step - Allow to specify path prefix for barman files - Add documentation in [README.md](README.md) --- README.md | 7 +++++++ defaults/main.yml | 2 +- tasks/postgres-standby-barman.yml | 12 ++++++++++++ templates/postgresql.10.conf.j2 | 2 +- templates/standby-clone.sh.j2 | 7 ++----- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5482bc6..050fb65 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,13 @@ postgres_replication_hosts: # Ansible related Configuration postgres_become_method: su # Optional + +# Barman connectivity +postgres_barman_server: barman.example.com # Required if at least one server has archive_enabled enabled +postgres_barman_rsync_enabled: False # Optional +postgres_barman_rsync_options: '' # Optional +postgres_barman_remote_user: barman # Optional +postgres_barman_path_prefix: '~' # Optional, required if using rsync ``` #### Testing diff --git a/defaults/main.yml b/defaults/main.yml index 5876e94..587779c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,7 @@ postgres_clusters: [] # postgres_pgbadger_server: ~ postgres_backup_enabled: false postgres_barman_rsync_enabled: false +postgres_barman_remote_user: barman postgres_become_method: su #------------------------------------------------------------# @@ -18,4 +19,3 @@ postgres_locale_system: C.UTF-8 postgres_locale_formats: C.UTF-8 postgres_text_search_config: pg_catalog.english #------------------------------------------------------------# - diff --git a/tasks/postgres-standby-barman.yml b/tasks/postgres-standby-barman.yml index 65e87a6..6a94b75 100644 --- a/tasks/postgres-standby-barman.yml +++ b/tasks/postgres-standby-barman.yml @@ -1,4 +1,16 @@ --- +- name: Compute barman remote URL + set_fact: + barman_remote_url: "{{ scheme }}{{ user }}{{ server }}{{ delimiter }}{{ path }}" + rsync_options: "{{ postgres_barman_rsync_options | default('') }}{{ rsync_password_file }}" + vars: + scheme: "{{ postgres_barman_rsync_enabled | ternary('rsync://', '') }}" + user: "{{ postgres_barman_remote_user is defined | ternary(postgres_barman_remote_user + '@', '') }}" + server: "{{ postgres_barman_server }}" + delimiter: "{{ postgres_barman_rsync_enabled | ternary('', ':')}}" + path: "{{ postgres_barman_path_prefix | default('~') }}" + rsync_password_file: "{{ postgres_barman_rsync_enabled | ternary(' --password-file=/var/lib/postgresql/.rsync_pass ', '') }}" + - name: Copy secondary script template: src=standby-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755 diff --git a/templates/postgresql.10.conf.j2 b/templates/postgresql.10.conf.j2 index 588020f..b07b22b 100644 --- a/templates/postgresql.10.conf.j2 +++ b/templates/postgresql.10.conf.j2 @@ -228,7 +228,7 @@ wal_log_hints = on # also do full page writes of non-critical updates {% if postgres_archive_enabled %} archive_mode = on -archive_command = 'rsync -a %p barman@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f' +archive_command = 'rsync -a %p {{ postgres_barman_remote_user }}@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f' {% else %} archive_mode = off archive_command = '' diff --git a/templates/standby-clone.sh.j2 b/templates/standby-clone.sh.j2 index 16a6930..2db44b6 100755 --- a/templates/standby-clone.sh.j2 +++ b/templates/standby-clone.sh.j2 @@ -29,11 +29,8 @@ sudo -u postgres mkdir -p /var/lib/postgresql/{{ postgres_version }}/{{ postgres echo Get previous backup from backups server sudo -u postgres \ - time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \ -{% if postgres_barman_rsync_enabled|default(false) -%} - --password-file=/var/lib/postgresql/.rsync_pass \ -{%- endif %} - {% if postgres_barman_rsync_enabled|default(false) -%}rsync://{%- endif -%}barman@{{ postgres_barman_server }}{%- if postgres_barman_rsync_enabled|default(false) -%}/backups{%- else -%}:~{%- endif -%}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \ + time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete {{ rsync_options }} \ + {{ barman_remote_url }}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \ /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ echo Restoring .conf and server certificate -- cgit v1.2.3