From bfc6f691de2cc447a08b4391a4b405f0725cfb49 Mon Sep 17 00:00:00 2001 From: Andy Bayer Roswell Date: Sun, 8 Dec 2024 02:50:45 +0100 Subject: [PATCH] added some handy scripts to export cells from psql pod in legacy db schema [used in tinydb] --- ...port-from-psql-pod-in-legacy-db-schema.ps1 | 24 +++++++++++++++++++ ...xport-from-psql-pod-in-legacy-db-schema.sh | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 create mode 100644 vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.sh diff --git a/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 new file mode 100644 index 0000000..5898b2f --- /dev/null +++ b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.ps1 @@ -0,0 +1,24 @@ +$project_root = Resolve-Path "$PSScriptRoot/../../.." + +$vreapi_pod_inf = kubectl get pod | sls '^vrepaas-vreapi-\w+-\w+' +$vreapi_pod_name = $vreapi_pod_inf.Matches.Value +$psql_pod_inf = kubectl get pod -owide | sls '^vrepaas-postgresql-0' +$psql_pod_IP = ($psql_pod_inf.Line | sls '\d+\.\d+\.\d+\.\d+').Matches.Value + +cd $project_root +$var = Get-Content export_VARS +$off_DB_HOST = ($var | sls '^export DB_HOST=').LineNumber - 1 +$off_DB_NAME = ($var | sls '^export DB_NAME=').LineNumber - 1 +$off_DB_USER = ($var | sls '^export DB_USER=').LineNumber - 1 +$off_DB_PASSWORD = ($var | sls '^export DB_PASSWORD=').LineNumber - 1 +$var[$off_DB_HOST] = "export DB_HOST=$psql_pod_IP" +$var[$off_DB_NAME] = "export DB_NAME=vrepaas" +$var[$off_DB_USER] = "export DB_USER=vrepaas" +$var[$off_DB_PASSWORD] = "export DB_PASSWORD=vrepaas" + +$var > /tmp/export_VARS +kubectl cp /tmp/export_VARS "${vreapi_pod_name}:/tmp" +kubectl cp "$PSScriptRoot/export-from-psql-pod-in-legacy-db-schema.sh" "${vreapi_pod_name}:/tmp" +kubectl exec -it $vreapi_pod_name -- bash "/tmp/export-from-psql-pod-in-legacy-db-schema.sh" + +kubectl cp "${vreapi_pod_name}:/app/NaaVRE_db.json" $project_root/NaaVRE_db.json diff --git a/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.sh b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.sh new file mode 100644 index 0000000..1e3d8bf --- /dev/null +++ b/vreapis/catalog/management/commands/export-from-psql-pod-in-legacy-db-schema.sh @@ -0,0 +1,3 @@ +source /opt/venv/bin/activate +source /tmp/export_VARS +python manage.py export_in_legacy_db_schema Cell