Saturday, November 22, 2014

Ubuntu Linux 14.04, Heroku PostgreSQL, and getting production data to your local DB

I just completed a clean upgrade (meaning that I did a fresh install)  from Ubuntu Linux 12.04 to the new long term support version of 14.04. Of course that means that my develope environment needed to be setup on the system. Database servers, code bases, etc. I wanted a backup of my Heroku PostgreSQL databases to restore to my local database. Since I literally just went through the process, I thought it best to record the steps:

From the command prompt:
sudo wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

Then, after a successful install from the prompt:
heroku login
Validate your account.

Then do the following to create a dump from which to restore locally:
heroku pgbackups --app herokuAppNameHere

Now get the URL of the dump
heroku pgbackups:url --app herokuAppNameHere

Browse to the URL via a Ctrl+Click on the link or copy the link into a web browser. Once you have the file, change into the folder with the dump file via a cd folderNameHere.

From the command prompt:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U dbAccountHere -d dbNameHere dumpFileName.dump

If all went well you should have a local copy of your production data from Heroku.

No comments: