Every repository with this icon (
Every repository with this icon (
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
- Add Support for Postgres
- Add S3 support
Copyright (c) 2009 Adam Hawkins, released under the MIT license







