Last active
July 11, 2017 15:33
-
-
Save jwenerd/1f9d814b4547cfcd1e51ed45f6837d73 to your computer and use it in GitHub Desktop.
Revisions
-
jwenerd revised this gist
Jul 11, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,5 +64,5 @@ Stop the rails development server, get the new enviroment config `source ~/.bash 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. -
jwenerd revised this gist
Jul 11, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ 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_ -
jwenerd revised this gist
Jul 11, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,8 @@ pg_dump --host localhost --username badges --verbose --clean --no-owner --no-acl 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`: ``` -
jwenerd created this gist
Jul 11, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ 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. 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 --role=badges -U badges ~/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 `badgesappproduction.vmhost.psu.edu` for good housekeeping sake.