Skip to content

Instantly share code, notes, and snippets.

@sagzy
Forked from sowenjub/gist:1033876
Last active February 9, 2016 10:49
Show Gist options
  • Save sagzy/b4559f74640cbcd9bac0 to your computer and use it in GitHub Desktop.
Save sagzy/b4559f74640cbcd9bac0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script does the following:
# 1/ capture and download the latest backup
# 2/ load it to your local database
# Just replace any uppercase string with your own data
#
# CAPTURE
#
# Note : 'heroku pg:backups capture' command might take some time.
# If you have recently saved PG Backups (Log into your Heroku dashboard -> Select your App -> "Create PGBackup" below your database plan),
# you can skip that line and use the last PG Backup of your Heroku database.
cd YOUR_LOCAL_BACKUP_FOLDER
heroku pg:backups capture --app YOUR_APP_NAME
file_path="db_$(date +%Y_%m_%d-%H_%M_%S).dump"
curl `heroku pg:backups public-url --app YOUR_APP_NAME` > $file_path
#
# LOAD
#
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U YOUR_LOCAL_DB_USERNAME -d YOUR_LOCAL_DB_NAME $file_path
cd YOUR_LOCAL_APP # for me something like ~/Sites/app_name
Copy link

ghost commented Feb 9, 2016

Pouce vert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment