From 6cc3002b5b1a617bc7ea3c407dd319724a281ec6 Mon Sep 17 00:00:00 2001 From: Michel Meier Date: Thu, 9 Nov 2023 22:50:37 +0100 Subject: [PATCH] feat: restore dumpfile --- .../environments/development/postgres.yaml | 20 +++++++++++++++++-- .../environments/production/postgres.yaml | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/civo-github/registry/environments/development/postgres.yaml b/civo-github/registry/environments/development/postgres.yaml index 450a0c9c3..fff9ee766 100644 --- a/civo-github/registry/environments/development/postgres.yaml +++ b/civo-github/registry/environments/development/postgres.yaml @@ -4,7 +4,7 @@ metadata: name: dev-postgres namespace: argocd finalizers: - - resources-finalizer.argocd.argoproj.io + - resources-finalizer.argocd.argoproj.io annotations: argocd.argoproj.io/sync-wave: '45' spec: @@ -114,6 +114,7 @@ data: fi echo "Created database: $db" grant_read_access "$db" + restore "$db" done } @@ -130,7 +131,22 @@ data: echo "Granted read-only access to database: $DATABASE" } + # restore existing schema + # --no-acl: prevent restoration of access privileges (grant/revoke commands) + # -v: verbose mode output + function restore() { + local DATABASE=$1 + local DUMPFILE="$BACKUP_DIRECTORY/$2.tar" + + if [ -f "$DUMPFILE"] + then + echo "Restoring $DATABASE from dumpfile $DUMPFILE" + pg_restore -d $DATABASE --no-acl -v $DUMPFILE + echo "Finished restoring $DATABASE from dumpfile $DUMPFILE" + fi + } + echo "Executing custom initdb ..." create_users create_read_role_and_user - create_databases_with_and_set_grant_privileges \ No newline at end of file + create_databases_with_and_set_grant_privileges diff --git a/civo-github/registry/environments/production/postgres.yaml b/civo-github/registry/environments/production/postgres.yaml index 54f2d85bd..7fe5e4616 100644 --- a/civo-github/registry/environments/production/postgres.yaml +++ b/civo-github/registry/environments/production/postgres.yaml @@ -4,7 +4,7 @@ metadata: name: prd-postgres namespace: argocd finalizers: - - resources-finalizer.argocd.argoproj.io + - resources-finalizer.argocd.argoproj.io annotations: argocd.argoproj.io/sync-wave: '45' spec: @@ -114,6 +114,7 @@ data: fi echo "Created database: $db" grant_read_access "$db" + restore "$db" done } @@ -130,7 +131,22 @@ data: echo "Granted read-only access to database: $DATABASE" } + # restore existing schema + # --no-acl: prevent restoration of access privileges (grant/revoke commands) + # -v: verbose mode output + function restore() { + local DATABASE=$1 + local DUMPFILE="$BACKUP_DIRECTORY/$2.tar" + + if [ -f "$DUMPFILE"] + then + echo "Restoring $DATABASE from dumpfile $DUMPFILE" + pg_restore -d $DATABASE --no-acl -v $DUMPFILE + echo "Finished restoring $DATABASE from dumpfile $DUMPFILE" + fi + } + echo "Executing custom initdb ..." create_users create_read_role_and_user - create_databases_with_and_set_grant_privileges \ No newline at end of file + create_databases_with_and_set_grant_privileges