init backup & restore

This commit is contained in:
Christian M. Adams
2021-03-04 00:32:39 -05:00
parent 6cc3c47e33
commit 6a5bdaf2f7
2 changed files with 56 additions and 1 deletions

View File

@@ -30,7 +30,6 @@
namespace: '{{ meta.namespace }}'
name: '{{ meta.name }}-postgres-configuration'
register: _generated_pg_config_resources
when: not _pg_config['resources'] | default([]) | length
- name: Set PostgreSQL Configuration
@@ -51,3 +50,8 @@
awx_postgres_database: "{{ pg_config['resources'][0]['data']['database'] | b64decode }}"
awx_postgres_port: "{{ pg_config['resources'][0]['data']['port'] | b64decode }}"
awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}"
# no_log: true #TODO uncomment
- name: Migrate data from old Openshift instance
import_tasks: migrate_data.yml
when: tower_old_postgres_host is defined

View File

@@ -0,0 +1,51 @@
---
# - name: Use kubectl or oc
# set_fact:
# kubectl_or_oc: "{{ openshift_oc_bin if openshift_oc_bin is defined else 'kubectl' }}"
# TODO: Either make everything below a block or included tasks
- name: Get Postgres container name
shell: |
oc -n {{ tower_namespace }} get pods -o jsonpath={.items[*].metadata.name} --selector app=tower-postgres
register: postgres_pod
- name: oc exec command #TODO: Make this work with Kubectl too
set_fact:
container_exec: oc -n chadams-restore exec -i {{ postgres_pod.stdout }} -- bash -c
# - name: Set psql command
# set_fact:
# psql_conn: 'psql -h {{ tower_old_postgres_host }} -U {{ tower_old_postgres_user }} -d {{ tower_old_postgres_database }} -p {{ tower_old_postgres_port }}'
- name: Set pg_dump command
set_fact:
pgdump: |
pg_dump -h {{ tower_old_postgres_host }} \
-U {{ tower_old_postgres_user }} \
-d {{ tower_old_postgres_database }} \
-p {{ tower_old_postgres_port }}
- name: Set pg_restore command
set_fact:
psql_restore: |
psql \
-U {{ awx_postgres_user }} \
-d {{ awx_postgres_database }} \
-p {{ awx_postgres_port }}
- pause:
- name: Set backup & restore command
set_fact:
psql_backup_restore: |
PGPASSWORD={{ tower_old_postgres_password }} {{ pgdump }} | PGPASSWORD={{ awx_postgres_pass }} {{ psql_restore }}
# no_log: true #TODO uncomment
- name: Migrate data from old postgresql if defined
shell: |
{{ container_exec }} '{{ psql_backup_restore }}'
# environment:
# PGPASSWORD: "{{ tower_old_postgres_password }}"
register: data_migration