Skip to content

Easy backup of Paperclip attachments in the cloud with Amazon Glacier.

License

Notifications You must be signed in to change notification settings

micred/paperclip-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Paperclip::Backup

paperclip-backup do incremental backups of Paperclip attachments in Amazon Glacier (long-term/infrequently accessed storage). It is meant to be a low-cost disaster recovery solution of your Paperclip attachments.

Installation

Add this line to your application's Gemfile:

gem 'paperclip-backup'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paperclip-backup

Compatibility

Paperclip configured with storage on Amazon S3.

How it works

It will zip all attachments changed since last backup and store them in Amazon Glacier. It will make just one zip archive with all files changed since last backup, to avoid putting to Glacier many single small archives and to make easier (and cheaper) to restore attachments in case of disaster recovery. It will backup only original Paperclip attachments. Other styles (e.g. thumb and medium) will be regenerated by Paperclip during restore.

Usage

Enable backup for Paperclip attachment

has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"                  
backup_attached_file :avatar

Create migrations

class AddPaperclipBackupColumns < ActiveRecord::Migration
  def change
    add_column :users, :avatar_last_backup_at, :datetime
    add_column :users, :avatar_backup_archives, :string, array: true, default: []

    add_index :users, :avatar_last_backup_at
    add_index :users, :avatar_updated_at
  end
end

Set AWS credentials

Add to config/initializers/paperclip-backup.rb

Paperclip::Backup.configuration do |config|
  # AWS Glacier configuration
  config.aws_access_key_id = ENV['aws_access_key_id']
  config.aws_secret_access_key = ENV['aws_secret_access_key']
  config.glacier_region = ENV['glacier_region']
  config.glacier_vault = ENV['glacier_vault']
end

Set the correct AWS credentials and Glacier vault (via ENV variables, with Figaro, or in plain text). Notice: AmazonGlacierFullAccess policy must be attached to this AWS user.

Launch backup of all models

Paperclip::Backup.backup_all_models!

Launch backup for a single Paperclip attachment

To backup all avatars of the model User changed since the last backup.

User.backup_paperclip_avatar!

Schedule backups

You can use the gem https://github.com/javan/whenever to schedule backups.

Set daily backups:

every 1.day, :at => '4:30 am' do
  runner "Paperclip::Backup.backup_all_models!"
end

Or set weekly backups:

every :sunday, :at => '4:30 am' do
  runner "Paperclip::Backup.backup_all_models!"
end

Set it and forget it.

Restoring

TODO

Cleaning up

TODO

Contributing

  1. Fork it ( https://github.com/micred/paperclip-backup/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Easy backup of Paperclip attachments in the cloud with Amazon Glacier.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages