Skip to content

Commit

Permalink
Add force_drop_db to EDARestore
Browse files Browse the repository at this point in the history
  • Loading branch information
rooftopcellist committed Jan 26, 2024
1 parent 607e79b commit 11e0563
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/crd/bases/eda.ansible.com_edas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,10 @@ spec:
bundle_cacert_secret:
description: Secret where the trusted Certificate Authority Bundle is stored
type: string
force_drop_db:
description: Force drop the database before restoring. USE WITH CAUTION!
type: boolean
default: false
status:
description: Status defines the observed state of EDA
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ spec:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- urn:alm:descriptor:com.tectonic.ui:hidden
- displayName: Force drop database before restore
path: force_drop_db
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
statusDescriptors:
- description: Admin password for the instance deployed
displayName: Admin Password
Expand Down
24 changes: 24 additions & 0 deletions roles/restore/tasks/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@
-p {{ eda_postgres_port }}
no_log: "{{ no_log }}"

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

- name: Set create db command
set_fact:
pg_create_db: >-
echo 'CREATE DATABASE {{ eda_postgres_database }} WITH OWNER = {{ eda_postgres_user }};' | PGPASSWORD='{{ eda_postgres_pass }}' psql
-U {{ eda_postgres_user }}
-h {{ resolvable_db_host }}
-d postgres
-p {{ eda_postgres_port }}
no_log: "{{ no_log }}"

- name: Restore database dump to the new postgresql container
k8s_exec:
namespace: "{{ backup_pvc_namespace }}"
Expand All @@ -102,6 +122,10 @@
trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
echo keepalive_pid: $keepalive_pid
set -e -o pipefail
if {{ force_drop_db }}; then
{{ pg_drop_db }}
{{ pg_create_db }}
fi
cat {{ backup_dir }}/eda.db | PGPASSWORD='{{ eda_postgres_pass }}' {{ pg_restore }}
echo 'Successful'
"
Expand Down

0 comments on commit 11e0563

Please sign in to comment.