Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bkenny
Last active March 17, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkenny/84d4577cb15df010e68c to your computer and use it in GitHub Desktop.
Save bkenny/84d4577cb15df010e68c to your computer and use it in GitHub Desktop.
Grab and Store PG Backup from Heroku

Exporting from Heroku

heroku pg:backups capture && curl -o ~/Desktop/app_latest.dump `heroku pg:backups public-url`

Importing locally

pg_restore --verbose --clean --no-acl --no-owner -h localhost -d app_db ~/Desktop/app_latest.dump

Export and import including dropping and creating the DB locally

dropdb butternutbox_development && rake db:create && heroku pg:backups capture && curl -o ~/Desktop/app_latest.dump `heroku pg:backups public-url` && pg_restore --verbose --clean --no-acl --no-owner -h localhost -d butternutbox_development ~/Desktop/app_latest.dump

Exporting to CSV

COPY people TO '/tmp/people.csv' DELIMITER ',' CSV HEADER;

Exporting JSON from Postgres

copy (select array_to_json(array_agg(row_to_json(t)))
from (
  select * from people
) t) to '/tmp/people.json' CSV QUOTE '$';

Exporting locally

pg_dump -Fc --no-acl --no-owner -h localhost db-dev > ~/Desktop/db-dev.dump

Importing into Dokku (Dump File)

dokku postgres:import global-invest-her < /root/gih_latest.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment