Make a snapshot of your staging environment and pull back on your dev machine.
Add this line to your application's Gemfile:
gem 'snapshotar'
And then execute:
$ bundle
Or install it yourself as:
$ gem install snapshotar
Run install generator:
$ rails generate snapshotar:install
Lookup config/initializers/snapshotar.rb and configure snapshotar.
- serializing your rails models to json
- handling carrierwave attachments
- storing serialized dataset locally or to amazon s3
- listing available snapshots
- deserialize snapshot and load back to database
instead of...
- database backup? Because image attachments causing trouble!!
- fixtures/factories/fakers? Because this requires coding. Don't spend time coding test data - it's boring.
- For testing and development!!
- definitely NOT for production backups
- Ruby >= 1.9.3
- tested with Mongoid, but ActiveRecord should work as well.
rake snapshotar:create # create snapshots
rake snapshotar:delete # delete snapshots
rake snapshotar:list # list available snapshots
rake snapshotar:load # load snapshots
You can also integrate snapshotar into your administration backend and let app users create snapshots. A sample controller is provided below
app/controllers/admin/snapshots_controller.rb
class Admin::SnapshotsController < Admin::AdminController
def index
@snapshots = Snapshotar.list
end
def load
Mongoid.purge!
Snapshotar.load(params[:name])
redirect_to admin_snapshots_path
end
def new
end
def create
Snapshotar.create
redirect_to admin_snapshots_path
end
def delete
Snapshotar.delete(params[:name])
redirect_to admin_snapshots_path
end
end
config/initializers/snapshotar.rb
Snapshotar.configure do |config|
config.storage_type = :s3
# serialization
config.models << [<ModelName>, <Attribute1 Symbol>, <Attribute2 Symbol>, :id, :name]
# shorter ...
config.models << ([User] + User.fields.keys.map { |x| x.to_sym })
end
For AWS S3, you have to provide the following ENV variables provisioning your S3 bucket. For development environments look at this wonderful dot-env gem https://github.com/bkeepers/dotenv.
AWS_ACCESS_KEY_ID: <your id>
AWS_SECRET_ACCESS_KEY: <your secret>
AWS_SNAPSHOTAR_BUCKET: <a bucket name>
AWS_REGION: <e.g. eu-central-1>
Files
config.storage_type = :file
Snapshots are stored in the rails tmp/ directory
This repository is under continuous integration testing on travis-ci.org.
Amazon S3 related functionalities are not tested in CI as an official account at amazon would be required. AWS S3 tests can be run locally by providing a .env file in the projects root directory with the following keys:
AWS_ACCESS_KEY_ID: <your id>
AWS_SECRET_ACCESS_KEY: <your secret>
AWS_SNAPSHOTAR_BUCKET: <a bucket name>
AWS_REGION: <e.g. eu-central-1>
RACK_ENV: test
S3_ENABLED: true
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request