mirror of
https://github.com/ansible/awx-operator.git
synced 2026-05-08 06:12:54 +00:00
Add option to force drop database before restore (#1639)
This commit is contained in:
@@ -121,6 +121,10 @@ spec:
|
|||||||
description: Maintain some of the recommended `app.kubernetes.io/*` labels on the resource (self)
|
description: Maintain some of the recommended `app.kubernetes.io/*` labels on the resource (self)
|
||||||
type: boolean
|
type: boolean
|
||||||
default: true
|
default: true
|
||||||
|
force_drop_db:
|
||||||
|
description: Force drop the database before restoring. USE WITH CAUTION!
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
status:
|
status:
|
||||||
type: object
|
type: object
|
||||||
x-kubernetes-preserve-unknown-fields: true
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
|
|||||||
@@ -194,6 +194,11 @@ spec:
|
|||||||
path: db_management_pod_node_selector
|
path: db_management_pod_node_selector
|
||||||
x-descriptors:
|
x-descriptors:
|
||||||
- urn:alm:descriptor:com.tectonic.ui:advanced
|
- urn:alm:descriptor:com.tectonic.ui:advanced
|
||||||
|
- 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:
|
statusDescriptors:
|
||||||
- description: The state of the restore
|
- description: The state of the restore
|
||||||
displayName: Restore Status
|
displayName: Restore Status
|
||||||
|
|||||||
@@ -82,6 +82,26 @@
|
|||||||
-p {{ awx_postgres_port }}
|
-p {{ awx_postgres_port }}
|
||||||
no_log: "{{ no_log }}"
|
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
|
- name: Restore database dump to the new postgresql container
|
||||||
k8s_exec:
|
k8s_exec:
|
||||||
namespace: "{{ backup_pvc_namespace }}"
|
namespace: "{{ backup_pvc_namespace }}"
|
||||||
@@ -104,6 +124,10 @@
|
|||||||
trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
|
trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
|
||||||
echo keepalive_pid: $keepalive_pid
|
echo keepalive_pid: $keepalive_pid
|
||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
|
if {{ force_drop_db }}; then
|
||||||
|
{{ pg_drop_db }}
|
||||||
|
{{ pg_create_db }}
|
||||||
|
fi
|
||||||
cat {{ backup_dir }}/tower.db | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }}
|
cat {{ backup_dir }}/tower.db | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }}
|
||||||
set +e +o pipefail
|
set +e +o pipefail
|
||||||
echo 'Successful'
|
echo 'Successful'
|
||||||
|
|||||||
Reference in New Issue
Block a user