简体   繁体   中英

How do I git clone the actual DATA in a remote Ruby on Rails/PostgreSQL database?

I am working with a Ruby on Rails application that I clone from Git and uses a Postgres database. I successfully clone the repository to my local area and bring up the website, but all of my database tables are empty. What do I need to do to transfer the data in the tables to my local build? (I am new to Ruby on Rails, PostgreSQL AND Git!)

Option 1:

You can seed the basic data your application depends from the seeds.rb using the rake task

RAILS_ENV=development rake db:seed

Option 2:

You can backup and restore the data from another remote /local database(like production database / staging database) using the utilities pg_dump and psql from postgres

Step1: Backup

pg_dump utility can be used to back up the database into the SQL commands and output to the given file. The below will create a file dump.sql on the given directory with the series of SQL commands.

pg_dump -h host_name -U user_name -d remote_database_name  > /path/to/backup/file/dump.sql

Step2: Restore

Then restore the data from the file to your local database using:

psql -U user_name -d local_data_base_name < /path/to/backuo/file/dump.sql

Caution:

Please be careful on using the production database backup (if any) in your local, since there may be real users and we might mistakenly trigger emails / SMS.,etc to these users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM