# 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
# postgres_pgbadger_server: ~
postgres_backup_enabled: false
postgres_barman_rsync_enabled: false
+postgres_barman_remote_user: barman
postgres_become_method: su
#------------------------------------------------------------#
postgres_locale_formats: C.UTF-8
postgres_text_search_config: pg_catalog.english
#------------------------------------------------------------#
-
---
+- 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
{% 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 = ''
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