Skip to content

Instantly share code, notes, and snippets.

@geronimod
Created August 4, 2016 18:31
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 geronimod/0c9571df843b2da8697788ccb0e462c9 to your computer and use it in GitHub Desktop.
Save geronimod/0c9571df843b2da8697788ccb0e462c9 to your computer and use it in GitHub Desktop.
Move s3 assets
bucket = 'intergi-phoenix'
files = S3Util.storage.directories.get(bucket, prefix: '12917/videos/').files
files.each do |file|
path = file.key
video_id = path[/videos\/(\d+)\//, 1].to_i
if video_id < 3270839
puts "skip #{video_id}"
next
end
new_path = path.sub /^12917\//, '1015630/'
puts path
puts new_path
# Skip objects that map to folders, including the top-level one.
next if path.ends_with?('/')
begin
S3Util.storage.copy_object(bucket, path, bucket, path,
'x-amz-metadata-directive' => 'REPLACE',
'Content-Type' => files.head(path).content_type,
'x-amz-storage-class' => 'STANDARD',
'x-amz-acl' => 'public-read')
S3Util.storage.copy_object(bucket, path, bucket, new_path,
'x-amz-metadata-directive' => 'REPLACE',
'Content-Type' => files.head(path).content_type,
'x-amz-storage-class' => 'STANDARD',
'x-amz-acl' => 'public-read')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment