Friday, January 17, 2014

Quick local database saves and restores with postgres

I recently added this rake task to our project. It performs fast database saves and restores using another postgres database. This is a very handy rake task to have around if you need to quickly go back to a previous version of your database and the normal create/restore process is too slow (for instances, restoring using a scrubbed database backup hosted on S3)




There is a lot going on here, but it is more or less wrapping this command, which creates a database from another

with some helpers to cut existing connections and automate the backup.

I've used this for quite some time, but with a flash drive, I can restore an 8.7 gig database in about 25 seconds instead of about 8 1/2 minutes from a local postgres backup.

To use it, it is simply:

Its a handy command to have in the toolbox. Whats in your toolbox?

No comments:

Post a Comment