-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
6cf3d1c
commit fefd93b
Showing
2 changed files
with
50 additions
and
36 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
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,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Cf : https://doc.scalingo.com/platform/databases/duplicate | ||
DUPLICATE_ADDON_KIND=postgresql | ||
ARCHIVE_NAME="backup.tar.gz" | ||
|
||
install-scalingo-cli | ||
|
||
# 1. Login to Scalingo, using the token stored in `DUPLICATE_API_TOKEN`: | ||
scalingo login --api-token "${DUPLICATE_API_TOKEN}" | ||
|
||
# 3. Install postgres tools | ||
dbclient-fetcher "${DUPLICATE_ADDON_KIND}" | ||
|
||
# 4. Retrieve the addon id: | ||
addon_id="$( scalingo --app "${PRODUCTION_APP}" addons \ | ||
| grep "${DUPLICATE_ADDON_KIND}" \ | ||
| cut -d "|" -f 3 \ | ||
| tr -d " " )" | ||
|
||
# 5. Download the latest backup available for the specified addon: | ||
scalingo --app "${PRODUCTION_APP}" --addon "${addon_id}" \ | ||
backups-download --output "${ARCHIVE_NAME}" | ||
# 6. Get the name of the backup file: | ||
backup_file_name="$( tar --list --file="${ARCHIVE_NAME}" \ | ||
| tail -n 1 \ | ||
| cut -d "/" -f 2 )" | ||
|
||
# 7. Extract the archive containing the downloaded backup: | ||
tar --extract --verbose --file="${ARCHIVE_NAME}" | ||
|
||
# 8. Restore the data: | ||
for table in $(psql "${PREPROD_DATABASE_URL}" -t -c "SELECT \"tablename\" FROM pg_tables WHERE schemaname='public'"); do | ||
psql "${PREPROD_DATABASE_URL}" -c "DROP TABLE IF EXISTS \"${table}\" CASCADE;" | ||
done | ||
pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname "${PREPROD_DATABASE_URL}" ${backup_file_name} |