Created
September 23, 2014 23:51
-
-
Save betesh/d60afa5f456024a3ddf0 to your computer and use it in GitHub Desktop.
Migrating paperclip attachments from file storage to s3 storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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