Skip to content

Instantly share code, notes, and snippets.

@jwenerd
Last active July 11, 2017 15:33
Show Gist options
  • Save jwenerd/1f9d814b4547cfcd1e51ed45f6837d73 to your computer and use it in GitHub Desktop.
Save jwenerd/1f9d814b4547cfcd1e51ed45f6837d73 to your computer and use it in GitHub Desktop.
DB copy instructions for Christine

The following outlines how to access the badges production server and copy the production database to your local machine to use for development.

ssh to server:

ssh -p 1855 badgesapp.vmhost.psu.edu

The badges application code and db is run with the user badgesapp. Start a shell session using this account with:

sudo -u badgesapp bash

The badges production database is called badges_production which can be access via the psql command or dumped via pg_dump. Run the following to output the database in the pg binary database format.

pg_dump --host localhost --username badges --verbose --clean --no-owner --no-acl --format=c badges_production > /tmp/badges_production.dump

Note: the /tmp/badges_production.dump can be altered to whatever file name/location you want.

On your local machine

Now copy the the dump file to your local machine using scp:

scp -P 1855 badgesapp.vmhost.psu.edu:/tmp/badges_production.dump ~/Desktop/

Now we can create a psql database to hold this database and tell the Rails app to use the newly imported.

Run psql as your local user with the pql cli:

psql

At the psql cli enter:

CREATE DATABASE badges_production_july10;

feel free to rename badges_production_july10 to whatever appropriated

Quit psql by entering \q

At this point we can import the psql dump file into the new db via:

pg_restore -d badges_production_july10 ~/Desktop/badges_production.dump

there may be warnings here about badges role not existing, which are fine to ignore

The config/database.yml file has an option to override the development by setting an enviromental variable called BADGES_DEV_DB. To set open your local profile ~/.bash_profile and enter along with the other badges app configs:

export BADGES_DEV_DB='badges_production_july10'

Stop the rails development server, get the new enviroment config source ~/.bash_profile then restart the rails server.

Viola! You should now have a copy of the a production seeded database on your local machine.

P.S.: Please go back and delete the /tmp/badges_production.dump file on badgesapp.vmhost.psu.edu for good housekeeping sake.

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