Easy Backups for Rails
Posted by Scott Laird Wed, 16 Aug 2006 04:36:14 GMT
I mentioned a few weeks ago that I was trying to add generic database backups to my installer, so I can do database backups before each upgrade. I got backups working a couple releases ago, and they’re useful enough that I’ve extracted them so everyone can use them.
The latest installer release includes a pair of command-line tools that make it easy to use the installer’s backup and restore code without using the rest of the installer. Run rails-backup and it’ll produce a .yml file containing all of your data. Then run rails-restore BACKUPFILENAME and it’ll restore the backup. The dump and restore formats are database-independent, so it should be possible to use these tools to migrate between database engines, but this hasn’t been heavily tested yet.
One warning about the restore–rails-restore doesn’t restore the schema, just the data. So you’ll need a way to build a database with the right schema revision. Look in the .yml file to see which schema version you need (search for schema_info), and then run rake migrate VERSION=xx to move your database to the right schema revision.
To use these, just install the rails-app-installer gem, and they should appear in your path automagically. Report bugs to the rails-app-installer bug tracker.

Excellent tool!! (maybe we can request the integration of the schema checking in the tool itself? – or is it too hairy to implement at this point?
very useful for what I was looking for!
Amr, I’ll see what I can do in the future. In theory,
rake migrate VERSION=...will do the trick, but I need to write a bunch of other code before I can get back to this.This is fantastic! Just what I googled for.
: )
Good work, Thanks a lot!