public
Description: A database import/export front end
Homepage:
Clone URL: git://github.com/Adman65/Snapshot.git
name age message
file MIT-LICENSE Mon Jun 29 11:08:24 -0700 2009 Initial commit [Adman65]
file README.markdown Mon Jul 06 01:20:06 -0700 2009 Added support for SQLite3. [Adman65]
file Rakefile Mon Jun 29 11:08:24 -0700 2009 Initial commit [Adman65]
file init.rb Tue Jun 30 01:01:01 -0700 2009 Version 0.2 Reworked the rake task to feel like... [Adman65]
file install.rb Mon Jun 29 11:08:24 -0700 2009 Initial commit [Adman65]
directory lib/ Mon Jul 06 01:20:06 -0700 2009 Added support for SQLite3. [Adman65]
directory tasks/ Tue Jun 30 01:23:19 -0700 2009 Added some much needed error handling [Adman65]
directory test/ Mon Jun 29 11:08:24 -0700 2009 Initial commit [Adman65]
file uninstall.rb Mon Jun 29 11:08:24 -0700 2009 Initial commit [Adman65]
README.markdown

SnapShot

SnapShot is a plugin that takes snapshots of your database and stores them so you can load them later.

I wrote SnapShot for a few purposes. While developing my apps, I found myself reseting my db all the time. After that, going through and reconstructing the data from importing xml & yml files, creating some users etc, I found that I needed snapshot I could load. I needed some ruby magic around mysqldump and importing. Of course you can use it for other things. It makes a handy backup utility as well.

Requirements

SnapShot only supports mysql & sqlite3 at the momement. I plan to add support for Postgres & SQLite soon. Commands are execute inside a shell, so be sure you have mysqldump,mysql & sqlite3 in $PATH. I've not tested SnapShot on windows, so if you use windows, good luck. Let me know how it goes. SnapShot has no other outside requirements.

Install

Step 1

    ./script/plugin install git://github.com/Adman65/SnapShot.git

Step2

    rake snapshots:setup

Step3

    rake -T to see how to use snapshots

Usage

Taking a SnapShot

A snapshot is a dump of your database. If you're using mysql, snapshot uses mysqldump. Taking a snapshot is easy. Use rake and pass it a file name to store

        rake snapshots:take name="ALotOfProducts"

Voilla, you've just taken your first snapshot. This creates file in db/snaphots/all_users.snapshot Your snapshot is also tied to a schema version. You can only load snapshots when the snapshot schema and the current schema are the same. So if you want to load a snapshot from the past, migrate down.

Loading a SnapShot

Loading a snapshot is easy as well. Use the rake task with an argument. Forgot what snapshots you have?

        rake snapshots:list

Now load with

        rake snapshots:load name="ALotOfProducts"

Your database is restored in the exact state it was before. All ID's, records, and associations are present again.

Deleting a SnapShot

You may want to delete a snapshot. Use:

        rake snapshots:destroy name="ALotOfProducts"

This will delete the file in db/snapshots

You may also want to delete all snapshots.

        rake snapshots:destroy:all

Backups

You may also uses SnapShot for backing up your database. It provides you with tools to backup your db, then restore it from the most recent snapshot. Back up your production database like this

    rake snapshots:backups:take RAILS_ENV=production

This creates a timestamped snapshot in app/db/snapshots/backups. You can view all your backups by doing:

    rake snapshots:backups:list

SnapShot places no limit to how many backups there are. You are only limited by your hard drive space.

Oh no! You lost your database, but you've been regularly backing up your database. No prob, SnapShot to the resuce. SnapShot's restore capability drops the database, then creates a blank slate, migrates up the latests snapshot's version, and repopulates the db. Nice huh?

    rake snapshots:backups:restore RAILS_ENV=production

And you're back in action! Painless.

Customizing SnapShot

You may want to change the way SnapShot works. Say for example, you don't want to store your snapshots with your app, but have a different folder else where. Simply create a symlink to snapshots

    ln -s /var/snapshots me/my/app/db/snapshots

You may also want to save your backup snapshots in a different directory. This can be accomplished by symlinking as well

    ln -s /var/myapp/backups /my/app/db/snapshots/backups

Some Caveats

SnapShot only saves things in your database. It doesn't save things like file uploads or other things you may have created outside of the database. It is up to you to handle those scenarios.

TODO

  1. Add Support for Postgres
  2. Add S3 support

Copyright (c) 2009 Adam Hawkins, released under the MIT license