Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails rake task for loading live (MySQL) database to local development database

For years I've used a ssh pipe from mysqldump on the live server to mysql on my development machine for getting a copy of the current data.

ssh -C <server> mysqldump --opt <live_database_name> |mysql <local_dev_database_name>

Where -C enables ssh compression and --opt enables quickness and completeness.

Does anyone have a rails-ish equivalent rake task for this? Ideally it'd take the database names from config/database.yml

like image 583
noodl Avatar asked Nov 25 '10 12:11

noodl


2 Answers

https://gist.github.com/750129

This is not an elegant solution. It's basically a wrapper for your old method, so it's not even compatible with other database drivers.

But it is something you can put in your SCM under lib/tasks to share it with other developers on your team. It also uses config data from your existing config/database.yml file. You define the live db by simply adding another branch to that file and it uses the same key names that Rails do.

Maybe it would even make sense to reuse the production database configuration.

like image 166
Adam Wróbel Avatar answered Sep 24 '22 13:09

Adam Wróbel


Here's one I use for a Postgres database: https://gist.github.com/748222.

There are three tasks: db:download, db:replace and db:restore. db:restore is just a wrapper around the other two.

I'd say you could do something similar for Mysql pretty quickly as well. I just use the latest backup in this case instead of creating it at runtime.

like image 26
cdmwebs Avatar answered Sep 22 '22 13:09

cdmwebs