-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
To backup an application database run: | ||
$ sh app-db-backup.sh | ||
App name (inventory|catalog)> catalog | ||
|
||
|
||
It will create catalog-db-20230714-110218-development.gz | ||
|
||
|
||
catalog-db-restore.sh | ||
|
||
To restore a database backup to a new DB, first you need to get the NEW DB set up | ||
|
||
cf create-service aws-rds medium-gp-psql catalog-new-db -c "{\"storage\": 250, \"version\": \"12\"}" | ||
refer to existing DB for correct plan and storage size | ||
|
||
then run: | ||
$ sh app-db-restore.sh | ||
S3 Backup path> catalog-db-20230714-110218-development.gz | ||
New Service name> catalog-new-db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# backup database to a dump zip file in S3 bucket cg-2bd85037-4eb6-450a-87f4-460d932a6c40 | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
# Get input params | ||
space_name=$(cf t | grep "space" | cut -d ':' -f 2 | awk '{$1=$1};1') | ||
read -rp "App name (inventory|catalog)> " app_name | ||
|
||
function wait_for () { | ||
while ! (cf tasks backup-manager | grep -q "$1 .*SUCCEEDED"); do | ||
echo "$1 .*SUCCEEDED" | ||
sleep 30 | ||
done | ||
} | ||
|
||
cf set-env backup-manager DATASTORE_S3_SERVICE_NAME backup-manager-s3 | ||
|
||
backup_id=$$ | ||
backup_path="$app_name-db-$(date +%Y%m%d-%H%M%S)-$space_name.gz" | ||
|
||
cf run-task backup-manager --name "$app_name-db-backup-$backup_id" --command "backup psql $app_name-db $backup_path" | ||
|
||
wait_for "$app_name-db-backup-$backup_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# restore catalog-db from a dump zip file in S3 bucket cg-2bd85037-4eb6-450a-87f4-460d932a6c40 | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
# Service name: the name of the service that is hosting the S3 Backup | ||
# Backup path: the path in S3 that is the backup location | ||
read -rp "S3 Backup path> " backup_path | ||
read -rp "New Service name> " service_name | ||
|
||
function wait_for () { | ||
while ! (cf tasks backup-manager | grep -q "$1 .*SUCCEEDED"); do | ||
sleep 5 | ||
done | ||
} | ||
|
||
cf set-env backup-manager DATASTORE_S3_SERVICE_NAME backup-manager-s3 | ||
cf bind-service backup-manager "$service_name" | ||
cf restart backup-manager | ||
|
||
# # Restore backup | ||
restore_id=$$ | ||
cf run-task backup-manager --name "db-restore-$restore_id" --command "PG_RESTORE_OPTIONS='--no-acl' restore psql $service_name $backup_path" | ||
|
||
# # This job may return "FAILED", and may not return successfully | ||
wait_for "db-restore-$restore_id" | ||
|