thoughtbot / parity

Shell commands for development, staging, and production parity for Heroku apps
https://thoughtbot.com
MIT License
889 stars 57 forks source link

Don't delete local temp backup after restore #179

Closed croaky closed 4 years ago

croaky commented 4 years ago

My current database takes about 10 minutes to fetch from Heroku. If the pg_restore fails for any reason, I don't want to re-fetch the dump.

curl -o will already overwrite tmp/latest.backup when it begins and tmp is ignored in Git by default in Rails apps.

It might be nice if Parity had a command to "restore from local backup" but in the meantime, this worked well for me:

#!/bin/bash
set -euo pipefail

db="MYDB_development"

dropdb --if-exists "$db"
createdb "$db"
time pg_restore tmp/latest.backup --verbose --no-acl --no-owner --dbname "$db"
psql "$db" -c "UPDATE ar_internal_metadata SET value = 'development' WHERE key = 'environment'"
croaky commented 4 years ago

That's a good point about helping users of the gem clean up.

I think I'm personally going to switch from Parity to individual shell scripts that live in the repo and have no arguments, as documented below in case any of these ideas are useful for the maintainers for future PRs.

Create backup of production follower:

./bin/db_backup_prod_follower

Restore staging from production backup. The script puts staging in maintenance mode and post-processes some data via heroku pg:psql:

./bin/db_restore_staging_from_prod_backup

Create backup of staging:

./bin/db_backup_staging

Download staging backup:

./bin/db_download_staging_backup

Restore development from downloaded backup:

./bin/db_restore_dev_from_downloaded_backup

Optionally, clean up:

rm tmp/latest.backup
geoffharcourt commented 4 years ago

I haven't been able to use Heroku PG for almost a year now, so I've still found Parity very useful for general app management, but the PG cases have gotten quite complicated.