Skip to content

Commit

Permalink
Allow to set options for barman connectivity
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
Théophile Helleboid committed May 3, 2019
1 parent c6719a8 commit 99504fe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#------------------------------------------------------------#
Expand All @@ -18,4 +19,3 @@ postgres_locale_system: C.UTF-8
postgres_locale_formats: C.UTF-8
postgres_text_search_config: pg_catalog.english
#------------------------------------------------------------#

12 changes: 12 additions & 0 deletions tasks/postgres-standby-barman.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion templates/postgresql.10.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
7 changes: 2 additions & 5 deletions templates/standby-clone.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99504fe

Please sign in to comment.