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.
Add this line to your application's Gemfile:
gem 'paperclip-backup'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paperclip-backup
Paperclip configured with storage on Amazon S3.
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.
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
backup_attached_file :avatar
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
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.
Paperclip::Backup.backup_all_models!
To backup all avatars of the model User changed since the last backup.
User.backup_paperclip_avatar!
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.
TODO
TODO
- Fork it ( https://github.com/micred/paperclip-backup/fork )
- 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 a new Pull Request