Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add restore capability #2

Draft
wants to merge 1 commit into
base: civo-soon-market
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions civo-github/registry/environments/development/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -114,6 +114,7 @@ data:
fi
echo "Created database: $db"
grant_read_access "$db"
restore "$db"
done
}

Expand All @@ -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
create_databases_with_and_set_grant_privileges
20 changes: 18 additions & 2 deletions civo-github/registry/environments/production/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -114,6 +114,7 @@ data:
fi
echo "Created database: $db"
grant_read_access "$db"
restore "$db"
done
}

Expand All @@ -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
create_databases_with_and_set_grant_privileges