Files
fizzy/script/copy-blobs-to-pure.rb
T
Mike Dalessio 704e215eca Production mirrors Active Storage to :purestorage
Also include a script to copy existing blobs to Pure.

Local is still the primary.

Beta will keep using local disk service for Active Storage because I
think there are constraints on source IPs for the Pure cluster.
2025-05-31 14:37:35 -04:00

43 lines
1.1 KiB
Ruby
Executable File

#! /usr/bin/env ruby
require_relative "../config/environment"
def migrate(source_service_name, target_service_name)
ApplicationRecord.with_each_tenant do |tenant|
puts "\n## #{tenant}"
report = { updated: 0, skipped: 0, errors: 0 }
if ActiveStorage::Blob.count == 0
puts "No blobs found, skipping."
next
end
ActiveStorage::Blob.service = source_service = ActiveStorage::Blob.services.fetch(source_service_name)
target_service = ActiveStorage::Blob.services.fetch(target_service_name)
ActiveStorage::Blob.find_each do |blob|
if target_service.exist?(blob.key)
report[:skipped] += 1
putc "S"
else
begin
blob.open do |stream|
target_service.upload(blob.key, stream, checksum: blob.checksum)
end
report[:updated] += 1
putc "."
rescue ActiveStorage::FileNotFoundError
report[:errors] += 1
putc "E"
end
end
# blob.update_attribute :service_name, target_service_name
end
puts
pp report
end
end
migrate :local, :purestorage