Skip to content

Commit

Permalink
Merge pull request #25 from GSA/inventory-backup-restore
Browse files Browse the repository at this point in the history
Scripts used to do CKAN 2.10 migration
  • Loading branch information
FuhuXia authored Jul 11, 2023
2 parents 31e1e51 + f7a0323 commit ba0202e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/backup_restore/inventory-db-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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
# Service name: the name of the service that is hosting the S3 Backup
# Backup path: the path in S3 that is the backup location
# Storage size (in GB): minimum 250 for catalog
space_name=$(cf t | grep "space" | cut -d ':' -f 2 | awk '{$1=$1};1')

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

backup_id=$$
backup_path="inventory-db-$(date +%Y%m%d-%H%M%S)-$space_name.gz"

cf run-task backup-manager --name "inventory-db-backup-$backup_id" --command "backup psql inventory-db $backup_path"

wait_for "catalog-db-backup-$backup_id"
31 changes: 31 additions & 0 deletions docs/backup_restore/inventory-db-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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

# Get input params
# Service name: the name of the service that is hosting the S3 Backup
# Backup path: the path in S3 that is the backup location
# Storage size (in GB): minimum 250 for catalog
read -p "S3 Backup path> " backup_path
read -p "New Service name> " service_name
space_name=$(cf t | grep "space" | cut -d ':' -f 2 | awk '{$1=$1};1')

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 "inventory-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 "catalog-db-restore-$restore_id"

0 comments on commit ba0202e

Please sign in to comment.