gre*_*ide 2 ruby-on-rails rails-activestorage
我将我的应用程序从 Vultr 切换到 DigitalOcean。现在我在 Vultr 上配置了一个存储桶以及以前的服务器。当我尝试从 DigitalOcean 访问 Vultr 上的 activestorage 映像时,映像仅加载 10% 的时间,并且大多数请求都会导致 502 错误。
由于我完全将这个应用程序从 Vultr 中移走,我觉得将我的应用程序的图像资产转移到 DigitalOcean 存储桶是一个好主意。
我发现了很多带有迁移脚本的帖子和一些博客,但它们的重点是从本地迁移到存储桶。我还没有发现从一个桶移动到另一个桶的任何事情。
我不知道该怎么做,有没有人从一个桶移到另一个桶?如果是这样,你是怎么做到的?
我们还希望进行从一个 ActiveStorage 后端到另一个的在线增量迁移,这是为我们处理它的一些提取代码。
它迭代每个 blob,复制文件并更新 blob 以引用新服务。它会完好无损地保留原始文件,以防出现问题时需要切换回来。
我们没有费心复制任何变体,而是选择让它们根据需要重新生成,但复制它们的代码可能是相似的。
source_service = ActiveStorage::Blob.services.fetch(:service_a)
destination_service = ActiveStorage::Blob.services.fetch(:service_b)
# :service_a/b above should be top-level keys from `config/storage.yml`
ActiveStorage::Blob.where(service_name: source_service.name).find_each do |blob|
key = blob.key
raise "I can't find blob #{blob.id} (#{key})" unless source_service.exist?(key)
unless destination_service.exist?(key)
source_service.open(blob.key, checksum: blob.checksum) do |file|
destination_service.upload(blob.key, file, checksum: blob.checksum)
end
end
blob.update_columns(service_name: destination_service.name)
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1068 次 |
| 最近记录: |