1. Oct 13th, 2009

    MySQL backups with EBS snapshots

    .@csharpfritz, @jptoto If you are using EC2 EBS volumes and not taking regular snapshots, you are not being backed up…

    ShlomoSwidler

    Amazon EBS snapshots are awesome. You can take snapshots to backup your database, quickly move data between staging and production, run analytics on the latest data, resize volumes and much more.

    For Apartly, I’m using MySQL, storing data and log files on a mounted EBS volume. EBS offers persistent, reliable storage (with replication for fault tolerance). Still, nothing can prevent data from disappearing, hence backups.

    The current setup uses a cron task that runs hourly and creates a snapshot of the EBS volume. It’s a simple procedure involving flushing, locking, and synching, and you can read all about it here. If the database goes catastrophical, I can always go back in history.

    Since you don’t want to accumulate snapshots until the end of time (storage is not free), the script keeps hourly snapshots from the past 24 hours and daily snapshots from the past week, and discards the rest.

    It’s a very simple script, based on Eric Hammond‘s excellent ec2-consistent-snapshot. Notable differences:

    • Using Ruby (tested for 1.9.1 only) instead of Perl. (Mind you, they’re both Unix)
    • Discards old snapshots, only keep hourly from last 24 hours and daily for past 7 days.
    • Get it: wget http://bit.ly/PTR9K
    • Edit settings, then drop into /etc/cron.hourly

    Enjoy.

    1. Oct 13th, 2009

      Wes Winham

      One thing to note about the current gist is that it assumes your DB volume is mounted at /vol, which is probably true for most people. If you have it mounted somewhere else, you’ll want to change lines 21 and 23.

      I wrote something similar for those of the Python/Django persuasion based on the same Eric Hammond script. http://github.com/winhamwr/django-ec2tools

      EBS snapshots are awesome :)

    2. Oct 13th, 2009

      Assaf

      Good point. I updated the Gist to use a constant instead, so it’s easier to change where the volume is mounted.

    3. Oct 17th, 2009

      Yoav Shapira

      Really useful, Assaf. Thank you for sharing ;)

    Your comment, here ⇓