-
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.
Merge pull request #25 from GSA/inventory-backup-restore
Scripts used to do CKAN 2.10 migration
- Loading branch information
Showing
2 changed files
with
57 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,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" |
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,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" | ||
|