mcdanlj
(Michael K Johnson)
2019 年 11 月 3 日午後 12:02
1
以下のページを読みました:
We have an old Discourse instance (running latest version but initially installed a while back). It’s running under HTTP with all its images stored on an AWS S3 bucket with . (dots) in the name.
We want to move to HTTPS – configuring for Lets Encrypt works a treat but all the images are broken as S3 buckets with (dots) don’t appear to do SSL.
I’m thinking the simplest option would be to migrate all the images to the local instance – as its not an image heavy forum. But I can’t seem to work o…
そこで lib/tasks/uploads.rake:migrate_from_s3 を確認したところ、以下のような記述がありました:
.where("raw LIKE '%.s3%.amazonaws.com/%' OR raw LIKE '%(upload://%'")
しかし、動画のアップロードでは upload:// という擬似プロトコルが raw フィールドに付与されず、ストレージプロバイダー(私の場合は DigitalOcean Spaces)への実際のリンクとして保存されていることに気づきました。
このタスクを成功させるためには、修正が必要なのは明白です。
Amazon への直接参照に代わる、あるいは追加して、SiteSetting.s3_endpoint と SiteSetting.s3_upload_bucket を確認する方が理にかなっているでしょうか?
mcdanlj
(Michael K Johnson)
2019 年 11 月 19 日午前 2:36
2
タスクにテストはありますか?見当たりません。明らかな修正と思われるものはあるのですが、既存のテストを拡張する方法がなく、非破壊的なテストを行う簡単な方法もありません。そのため、不安に感じています…
index 0761c4712a..63f49155f3 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -129,12 +129,12 @@ def migrate_from_s3
Post
.where("user_id > 0")
- .where("raw LIKE '%.s3%.amazonaws.com/%' OR raw LIKE '%(upload://%'")
+ .where("raw LIKE '%.s3%.amazonaws.com/%' OR raw LIKE '%#{SiteSetting.Upload.absolute_base_url}%' OR raw LIKE '%(upload://%'")
.find_each do |post|
begin
updated = false
- post.raw.gsub!(/(\/\/[\w.-]+amazonaws\.com\/(original|optimized)\/([a-z0-9]+\/)+\h{40}([\w.-]+)?)/i) do |url|
+ post.raw.gsub!(/(\/\/[\w.-]+(amazonaws\.com|#{Regexp.quote(SiteSetting.s3_endpoint)})\/(original|optimized)\/([a-z0-9]+\/)+\h{40}([\w.-]+)?)/i) do |url|
begin
if filename = guess_filename(url, post.raw)
file = FileHelper.download("http:#{url}", max_file_size: max_file_size, tmp_file_name: "from_s3", follow_redirect: true)
また、経験から推測すると、これらの画像はすべて最適化されているにもかかわらず、移動時にすべての 50GB の画像(オリジナルと最適化を合わせた合計 96GB)を再最適化する必要があると判断し、その間、サイト全体のメール通知をすべて無効にしてしまう可能性があります。効果的なテスト方法がないため、そのような仕様かどうかお伺いしたいのですが。もしそうであれば、回避策はあるでしょうか。すでに最適化されている画像をそのままコピーする方法があれば知りたいです。
MinIO Client を使えば、すべてのファイルをローカルシステムに簡単にコピーできます。それらの画像を再最適化することなく、単にファイルを適切な場所に配置し、データベースを新しい場所を指すように変更するのは、どのくらい難しいものか気になります…
mcdanlj
(Michael K Johnson)
2020 年 5 月 17 日午後 11:06
3
master ← johnsonm:mkj-s3-clone-uploads-local
closed 12:59PM - 20 Jun 20 UTC
現時点ではテストしていませんが、少なくともメタ投稿ではなく PR として共有されています。
mcdanlj
(Michael K Johnson)
2020 年 6 月 20 日午後 1:00
4
実際の移行プロセスで検証された、さらに多くの関連する修正を新しい PR に追加
master ← johnsonm:mkj-fix-more-urls
closed 09:33PM - 17 Jan 21 UTC
Fix handling of bare URLs to (more) correctly process URLs present
in s3 or a c… lone when migrating to local, including changing to an
`upload:` psuedo-protocol URL, tagging audio and video files, using
the `` syntax, and in the process not creating non-URLs
that point to nothing.
Fix `batch_migrate_from_s3` to take both a max number of posts to
actually modify in a migration (the original but failed intent of
limit) and a limit of total posts to consider for migration (for
cheaper database queries). Because a primary goal of the `max`
limit is debugging, also use it to cause verbose logging output.
Print diagnostic messages for conditions that might require manual
intervention, such as file too large (if upload sizes were reduced
in site settings) or failure to download (which can happen on an
intermittent basis and might require re-running the migration).
Finally, in the case of a truly unexpected error, print the error
and stop processing, so that error cascades do not become hidden
failures stopping a successful migration, but can instead be resolved.