Skip to content

Instantly share code, notes, and snippets.

@mbklein
Last active December 21, 2018 17:53
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 mbklein/d81c5b11a5fc01b8f380e349b65be045 to your computer and use it in GitHub Desktop.
Save mbklein/d81c5b11a5fc01b8f380e349b65be045 to your computer and use it in GitHub Desktop.
Move old DONUT pyramids to new names
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