Robot Has No Heart

Xavier Shay blogs here

A robot that does not have a heart

Backup MySQL to S3 with Rails

UPDATE: This code is too old. Use db2fog instead. It does the same thing but better.

Here is some code I wrote over the weekend – db2s3. It’s a rails plugin that provides rake tasks for backing up your database and storing it on Amazon’s S3 cloud storage. S3 is a trivially cheap offsite backup solution – for small databases it costs about 4 cents per month, even if you’re sending full backups every hour.

There are many scripts around that do this already, but they fail to address the biggest actual problem. The aws-s3 gem provides a really nice ruby interface to S3, and dumping a backup then storing it really isn’t that hard. The real problem is that I really hate system administration. I want to spend as little time as possible and I want things to Just Work.

A script is great but there’s still too many things for me to do. Where does it go in my project? How do I set my credentials? How do I call it?

That’s why a plugin was needed. It’s as little work as possible for a rails developer to backup their database, so they can get back to making their app awesome.

db2s3. Check it out.

  1. antonjenkins.myopenid.com says:

    This sounds really neat! I share your pain with sys admin tasks. It's always a chore.

    It would be quite interesting if it was possible to hack this to work for other storage methods as well. Say, for example, using scp to push the backups onto another server or something similar. Basically making it storage agnostic.

    That would be great because when used in an enterprise environment you'll most likely want to backup to another server rather than S3. I'll check it out and have a tinker.

    Cheers

    Anton

  2. Alex says:

    Nice one. Personally, I'd rather copy from my site to my random Dreamhost server to backup. I can pay you in good karma.

  3. Xavier Shay says:

    Have a look at the source - the S3 stuff is abstracted into an S3Store class. It wouldn't be hard to create an SCPStore - it only needs to support store and retrieve. Please, fork away!

  4. SteveForkin says:

    Has this gem/plugin been tested with Rails 3 and Ruby 1.9.2..? I would like to use it and if required make the changes to make it Rails 3 compatible. Thanks

    Steve

  5. Xavier Shay says:

    aws-s3 wasn't 1.9.2 compatible last time I checked, surely someone would have patched it by now though. Works fine on rails 3.

  6. Xavier Shay says:

    Steve, use the db2fog gem instead, it's ready to go.

Post a comment


(lesstile enabled - surround code blocks with ---)

A pretty flower Another pretty flower