Skip to content

Instantly share code, notes, and snippets.

@betesh
Created September 23, 2014 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betesh/d60afa5f456024a3ddf0 to your computer and use it in GitHub Desktop.
Save betesh/d60afa5f456024a3ddf0 to your computer and use it in GitHub Desktop.
Migrating paperclip attachments from file storage to s3 storage
require 'aws-sdk'
require 'bcdatabase'
config = Bcdatabase.load[:secrets, :paperclip_s3]
AWS.config(config)
BUCKET = AWS::S3.new.buckets[config['bucket']]
require 'find'
Find.find('public/system/') { |f|
unless f.match(/\/\..+$/) || File.directory?(f)
name = f.split('public/system/')[1]
puts name
File.open(f, 'r') do |r|
BUCKET.objects[name].write(r.read, acl: :public_read)
end
end
}
BUNDLE_GEMFILE=../releases/2014..../Gemfile bundle exec ruby migrate.rb
# Put 'migrate.rb' in your shared_path and run the above command from there
# The trick is to run this while capistrano is still deploying, as soon as bundle install is complete, before the deploy:restart task
# That way, by the time the application restarts, your files have all been copied (assuming this script is shorter than the rest of your deployment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment