Skip to content

Commit

Permalink
1587: drop/create database DB before restoring it
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Kuzmik committed Oct 18, 2023
1 parent bb30b3b commit b3a2167
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions roles/restore/tasks/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@
-p {{ awx_postgres_port }}
no_log: "{{ no_log }}"

- name: Set drop db command
set_fact:
pg_drop_db: >-
echo 'DROP DATABASE {{ awx_postgres_database }} WITH (FORCE);' | PGPASSWORD='{{ awx_postgres_pass }}' psql
-U {{ awx_postgres_user }}
-h {{ resolvable_db_host }}
-d postgres
-p {{ awx_postgres_port }}
no_log: "{{ no_log }}"

- name: Set create db command
set_fact:
pg_create_db: >-
echo 'CREATE DATABASE {{ awx_postgres_database }} WITH OWNER = {{ awx_postgres_user }};' | PGPASSWORD='{{ awx_postgres_pass }}' psql
-U {{ awx_postgres_user }}
-h {{ resolvable_db_host }}
-d postgres
-p {{ awx_postgres_port }}
no_log: "{{ no_log }}"

- name: Restore database dump to the new postgresql container
k8s_exec:
namespace: "{{ backup_pvc_namespace }}"
Expand All @@ -104,6 +124,8 @@
trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
echo keepalive_pid: $keepalive_pid
set -e -o pipefail
{{ pg_drop_db }}
{{ pg_create_db }}
cat {{ backup_dir }}/tower.db | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }}
set +e +o pipefail
echo 'Successful'
Expand Down

0 comments on commit b3a2167

Please sign in to comment.