From fb38c9cea961a6d512d87731521f13c754e5f355 Mon Sep 17 00:00:00 2001 From: Kyle Umstatter Date: Thu, 24 Oct 2019 03:09:11 -0700 Subject: [PATCH] Support PostgreSQL Custom Format (#63806) * Support PGC Restores * Fix whitespace * support pgc both dump and restore --- changelogs/fragments/63629-postgresql_db_pgc_support.yaml | 2 ++ lib/ansible/modules/database/postgresql/postgresql_db.py | 8 +++++++- test/integration/targets/postgresql_db/tasks/main.yml | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/63629-postgresql_db_pgc_support.yaml diff --git a/changelogs/fragments/63629-postgresql_db_pgc_support.yaml b/changelogs/fragments/63629-postgresql_db_pgc_support.yaml new file mode 100644 index 00000000000..12089b251b7 --- /dev/null +++ b/changelogs/fragments/63629-postgresql_db_pgc_support.yaml @@ -0,0 +1,2 @@ +minor_changes: +- postgresql_db - add support for .pgc file format for dump and restores. diff --git a/lib/ansible/modules/database/postgresql/postgresql_db.py b/lib/ansible/modules/database/postgresql/postgresql_db.py index c32e4db3ec7..c70ff7702d7 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_db.py +++ b/lib/ansible/modules/database/postgresql/postgresql_db.py @@ -71,7 +71,7 @@ options: pg_dump returns rc 1 in this case. - C(restore) also requires a target definition from which the database will be restored. (Added in Ansible 2.4) - The format of the backup will be detected based on the target name. - - Supported compression formats for dump and restore include C(.bz2), C(.gz) and C(.xz) + - Supported compression formats for dump and restore include C(.pgc), C(.bz2), C(.gz) and C(.xz) - Supported formats for dump and restore include C(.sql) and C(.tar) type: str choices: [ absent, dump, present, restore ] @@ -346,6 +346,8 @@ def db_dump(module, target, target_opts="", if os.path.splitext(target)[-1] == '.tar': flags.append(' --format=t') + elif os.path.splitext(target)[-1] == '.pgc': + flags.append(' --format=c') if os.path.splitext(target)[-1] == '.gz': if module.get_bin_path('pigz'): comp_prog_path = module.get_bin_path('pigz', True) @@ -392,6 +394,10 @@ def db_restore(module, target, target_opts="", flags.append(' --format=Tar') cmd = module.get_bin_path('pg_restore', True) + elif os.path.splitext(target)[-1] == '.pgc': + flags.append(' --format=Custom') + cmd = module.get_bin_path('pg_restore', True) + elif os.path.splitext(target)[-1] == '.gz': comp_prog_path = module.get_bin_path('zcat', True) diff --git a/test/integration/targets/postgresql_db/tasks/main.yml b/test/integration/targets/postgresql_db/tasks/main.yml index d9e6447835e..a68581b73cb 100644 --- a/test/integration/targets/postgresql_db/tasks/main.yml +++ b/test/integration/targets/postgresql_db/tasks/main.yml @@ -18,6 +18,7 @@ - dbdata.tar.gz - dbdata.tar.bz2 - dbdata.tar.xz + - dbdata.pgc loop_control: loop_var: loop_item