我將我的應用程式從 Vultr 切換到 DigitalOcean。現在我在 Vultr 上配置了一個存盤桶以及以前的服務器。當我嘗試從 DigitalOcean 訪問 Vultr 上的 activestorage 影像時,影像僅加載 10% 的時間,并且大多數請求會導致 502 錯誤。
由于我完全將這個應用程式從 Vultr 移走,我覺得將我的應用程式的影像資產轉移到 DigitalOcean 存盤桶是一個好主意。
我發現了很多帖子和一些帶有遷移腳本的博客,但它們專注于從本地遷移到存盤桶。我沒有發現從一個桶移到另一個桶的任何東西。
我不知道該怎么做,有沒有人從一個桶移到另一個桶?如果是這樣,你是怎么做到的?
uj5u.com熱心網友回復:
我們還想進行從一個 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/454812.html
標籤:轨道上的红宝石 rails-activestorage
上一篇:根據屬性選擇唯一物件
下一篇:如何使用活動記錄存盤多個日期范圍
