Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash function for pulling remote heroku database and loading locally
heroku_pg_pull() {
database=$1
environment=$2
if [ "$database" = "" ]; then
echo "Must pass in local database name, maybe one of these?"
cat config/database.yml | grep "database:"
return 1
fi
if [ "$environment" = "" ]; then
environment=production
fi
heroku pg:backups:capture -r $environment
file_path="db_$(date +%Y_%m_%d-%H_%M_%S).dump"
curl -o $file_path `heroku pg:backups:public-url -r $environment`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U efatsi -d $database $file_path
project=`echo "$database" | awk '{ gsub(/_.+/, ""); print }'`
save_name="$project-$environment-$(date +%Y_%m_%d).dump"
mv $file_path ~/Desktop/db_backups/$save_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.