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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With