Created
August 4, 2016 18:31
-
-
Save geronimod/0c9571df843b2da8697788ccb0e462c9 to your computer and use it in GitHub Desktop.
Move s3 assets
This file contains hidden or 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
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