Last active
December 21, 2018 17:53
-
-
Save mbklein/d81c5b11a5fc01b8f380e349b65be045 to your computer and use it in GitHub Desktop.
Move old DONUT pyramids to new names
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
def move_old_pyramids | |
bucket = Settings.aws.buckets.pyramids | |
FileSet.find_each do |fs| | |
begin | |
file_id = fs.original_file.id | |
old_file_id = file_id.split(%r{/files/}).last | |
new_file_id = file_id.split(%r{/files/}).first | |
old_key = IiifDerivativeService.s3_key_for(old_file_id) | |
new_key = IiifDerivativeService.s3_key_for(new_file_id) | |
old_location = Aws::S3::Object.new(bucket_name: bucket, key: old_key) | |
if old_location.exists? | |
new_location = Aws::S3::Object.new(bucket_name: bucket, key: new_key) | |
new_location.copy_from(copy_source: "#{bucket}/#{old_key}") | |
if new_location.etag == old_location.etag | |
old_location.delete | |
end | |
end | |
rescue | |
end | |
$stderr.print '.' | |
end | |
$stderr.puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment