Skip to content

Commit 21fcdfc

Browse files
committed
Make a var for whether postgresql_backup_dir is remote
and set it based on the first char being `/` rather than containing a `:`.
1 parent 6453bfe commit 21fcdfc

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ postgresql_backup_local_dir: >-
1717
'/var/lib/postgresql' if ansible_os_family == 'Debian' else '~postgres') }}/backup
1818
postgresql_create_backup_dir: true
1919

20+
# Controls whether the wal_archive directory is cleaned and whether postgresql_create_backup_dir can be used
21+
postgresql_backup_dir_is_remote: "{{ postgresql_backup_dir[0] != '/' }}"
22+
2023
# Options used for the WAL archive command - do not change this unless you have read the PITR documentation and
2124
# understand how this command must work.
2225
postgresql_archive_wal_rsync_args: '--ignore-existing -ptg --info=skip1'
@@ -36,7 +39,7 @@ postgresql_backup_command: >-
3639
--rsync-backup-opts {{ postgresql_backup_rsync_backup_opts | regex_replace('^-', '\-') | quote }}
3740
--keep {{ postgresql_backup_keep | quote }}
3841
{{ '--pg-bin-dir ' ~ __postgresql_pgdg_bin_dir if ansible_os_family == 'RedHat' else '' }}
39-
--backup {{ (':' in postgresql_backup_dir) | ternary('', '--clean-archive') }} {{ postgresql_backup_dir | quote }}
42+
--backup {{ postgresql_backup_dir_is_remote | ternary('', '--clean-archive') }} {{ postgresql_backup_dir | quote }}
4043
4144
postgresql_backup_python_executable: "python"
4245

tasks/backup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
mode: 0750
1919
state: directory
2020
path: "{{ postgresql_backup_dir }}"
21-
when: postgresql_backup_dir[0] == '/' and postgresql_create_backup_dir
21+
when: not postgresql_backup_dir_is_remote and postgresql_create_backup_dir
2222

2323
- name: Install backup script templates
2424
template:

templates/archive_wal.sh.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ wal_archive_dir={{ (postgresql_backup_dir ~ '/wal_archive') | quote }}
1313
file_path="$1"
1414
file_name="$2"
1515

16-
{% if ":" in postgresql_backup_dir %}
16+
{% if postgresql_backup_dir_is_remote %}
1717
empty=$(mktemp -d -t ansible-postgresql-empty.XXXXXX)
1818
rsync {{ postgresql_backup_rsync_connect_opts }} "${empty}/" "$wal_archive_dir"
1919
rmdir "$empty"

0 commit comments

Comments
 (0)