Awesomeness: database backups
At Collective Idea, we have a plugin called awesomeness that is…well, awesome. It’s a collection of things that we use in almost every project that aren’t generic enough to go into individual plugins (although some things may have evolved enough to be worthy of plugin status).
A while ago, I blogged a little snippet for backing up your remote database. Well, that snippet as evolved quite a bit, into it’s own set of rake and Capistrano tasks.
First, the rake tasks. You Can easily create a new local backup:
$ rake db:backup:create
This creates a
backups directory in your project, with a subdirectory for each backup based on the timestamp. A backup consists of the
schema.rb file and then a fixture for each table to hold the data. Why fixtures? Good question. Because we wanted the backups to be database independent.
You can easily restore your local database to the latest backup, or a specific version:
$ rake db:backup:restore VERSION=20080427214315
That’s nice, but what good are local backups? That’s where Capistrano comes in. Just add this to your
This adds some nifty remote backup support. Now, whenever
cap deploy:migrations is run, a backup of your remote database will automagically be created and stored in the shared directory on the server. You can also have them transferred to your local machine by adding a callback in your
after “backup:create”, “backup:download”
Sometimes, you just want to take a snapshot of the server and plop it into your local database.
$ cap backup:mirror
How do I get this backup awesomeness?
Awesomeness now lives on Github (like the rest of the world). Fork it and let us know what you think.