Skip to content

Instantly share code, notes, and snippets.

@efatsi
Created May 8, 2017 23:16
Show Gist options
  • Save efatsi/18dd0f21a57f277f1c7bb8b5782edf3e to your computer and use it in GitHub Desktop.
Save efatsi/18dd0f21a57f277f1c7bb8b5782edf3e to your computer and use it in GitHub Desktop.
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