Skip to content

Commit 373b86b

Browse files
committed
Fixes for remote rsync + connection options
1 parent c13f7c5 commit 373b86b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

defaults/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ postgresql_backup_keep: 30
3131

3232
__postgresql_pgdg_bin_dir: "{{ '/usr/pgsql-' ~ (postgresql_version | replace('.', '')) ~ '/bin' }}"
3333
postgresql_backup_command: >-
34-
{{ postgresql_backup_local_dir | quote }}/bin/backup.py
34+
{{ postgresql_backup_python_executable }} {{ postgresql_backup_local_dir | quote }}/bin/backup.py
3535
{{ '--rsync-connect-opts ' ~ (postgresql_backup_rsync_connect_opts | quote) if postgresql_backup_rsync_connect_opts else '' }}
3636
--rsync-backup-opts {{ postgresql_backup_rsync_backup_opts | regex_replace('^-', '\-') | quote }}
3737
--keep {{ postgresql_backup_keep | quote }}
3838
{{ '--pg-bin-dir ' ~ __postgresql_pgdg_bin_dir if ansible_os_family == 'RedHat' else '' }}
3939
--backup --clean-archive {{ postgresql_backup_dir | quote }}
4040
41+
postgresql_backup_python_executable: "python"
42+
4143
postgresql_default_auth_method: "{{ (postgresql_version is version('13', '>')) | ternary('scram-sha-256', 'md5') }}"

files/backup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def pg_major_version(self):
109109
def rsync_cmd(self):
110110
cmd = ['rsync']
111111
if self._rsync_opts:
112-
cmd.extend(shlex.split(rsync_opts))
112+
cmd.extend(shlex.split(self._rsync_opts))
113113
return cmd
114114

115115
@property

templates/archive_wal.sh.j2

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

16+
{% if ":" in postgresql_backup_dir %}
17+
empty=$(mktemp -d -t ansible-postgresql-empty.XXXXXX)
18+
rsync {{ postgresql_backup_rsync_connect_opts }} "${empty}/" "$wal_archive_dir"
19+
rmdir "$empty"
20+
{% else %}
1621
mkdir -p "$wal_archive_dir"
22+
{% endif %}
1723

1824
# If rsync outputs anything to stdout, the destination already existed, which should not happen
19-
if [ -n "$(rsync {{ postgresql_archive_wal_rsync_args }} "$file_path" "$wal_archive_dir")" ]; then
25+
if [ -n "$(rsync {{ postgresql_backup_rsync_connect_opts }} {{ postgresql_archive_wal_rsync_args }} "$file_path" "$wal_archive_dir")" ]; then
2026
echo "ERROR: ${wal_archive_dir}/${file_name} already exists, overwriting is not allowed!"
2127
exit 1
2228
fi

0 commit comments

Comments
 (0)