Is there a rake task for backing up the data in your database?
I already have my schema backed up, but I want to make a backup of the data. It's a small MySQL database.
Is there a rake task for backing up the data in your database?
I already have my schema backed up, but I want to make a backup of the data. It's a small MySQL database.
There are a few solutions already on google. I am going to guess that you are using activerecord as your orm?
If you are running rails, then you can looks at the Rakefile that it uses for activerecord in \ruby\lib\ruby\gems\1.8\gems\rails-2.0.2-\lib\tasks\database.rake. That gave me a lot of information on how to extend the generic Rakefile.
You could take the capistrano tasks that thelsdj provides, and add it to your rake file. Then modify it a bit so that it uses the activerecord connection to the database.
There is my rake task to backup mysql, and rotate backups cyclically.
Just in case people are still surfing for solutions, we currently use the ar_fixtures plugin to backup our db, well as part of the solution anyway.
It provides the rake
db:fixtures:dump
tasks. This spits out everythin in YAML into test/fixtures, so it can be loaded in again usingdb:fixtures:load
.We use this to backup before every feature push to production. We also used this when migrating from sqlite3 to Postgres - which is subtlety very useful as incompatibilities between SQL dialects are, for the most part, hidden.
All the best, D
The below script is a simplified version taken from eycap, specifically from this file.
Edit: Yeah, I guess I missed the point that you were looking for a rake task and not a capistrano task, but I don't have a rake one on hand, sorry.
I don't have a rake task for backing up my MySQL db, but I did write a script in Ruby to do just that for my WordPress DB:
You should be able to take this and do some mild pruning of it to put in your username/password/dbname to get it up and working for you. I put it in my crontab to run everyday as well, and it shouldn't be too much work to convert this to run as a rake task since it's already Ruby code (might be a good learning exercise as well).
Tell us how it goes!
There's a plugin out there called "mysql tasks", just google for it. It's just a rakefile -- I've found it very easy to use.