tzzzoz
tzzzoz

Reputation: 336

How to import Production Data from Development Database?

Recently, I learn to develop a rails application. Now, I have a problem. I want to change into Production Mode. But I don't want to copy my data in development database manually. How should I do these easily? I use mysql and Mac os and rails 3 beta.

Upvotes: 3

Views: 2677

Answers (2)

Thomas
Thomas

Reputation: 2466

If you are using Capistrano for deployments, you can also complete this via a ruby gem capistrano-db-tasks gem.

Obviously, it is definitely great to know how to complete via underlying mysqldump commands, but once you learn this, in my personal opinion, much nicer workflow to use the gem. With the gem, you can quickly push and pull data for all of your environments, I have listed several more advantages below. I add this by default to every rails app as I am constantly pull prod data down to local.

Advantages

  • don't have to SSH into your server, automated
  • no need to download the dump file from your server, automated
  • no need to leave terminal can be scripted in tasks
  • much faster to sync, push and pull data between local, stage and production envs
  • database independent, works with mysql, Postgres etc.
  • easier onboarding for new / junior devs

This allows you to run commands for push / pull for different environments in terminal:

cap production db:pull
cap production db:push # probably less common not something I would recommend
cap staging db:pull
cap staging db:push

I created a YouTube video demonstrating this gem and its advantages, thought it may be helpful if you wanted to learn more about using this gem.

Upvotes: 0

Sachin R
Sachin R

Reputation: 11876

Here are the basic commands for dumping/loading DBs in mysql:

Dumping the database:

$ mysqldump your_dev_db_name > your_db_dump.sql

Loading the dump:

$ mysql your_production_db_name < your_db_dump.sql

Upvotes: 8

Related Questions