# migrate\_from\_s3 的奇怪问题

**URL:** https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337
**Category:** Development
**Created:** [2018 年4 月 27 日 19:49 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337 "2018-04-27T19:49:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2018 年4 月 27 日 19:49 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337/1 "2018-04-27T19:49:18Z")

</div>

I was migrating from S3 and had some strange problems. First, shouldn’t the rake task be looking at `cooked`, and not `raw`? Or maybe this is a vestige of the old way images were put into `raw`?

> <https://github.com/discourse/discourse/blob/main/lib/tasks/uploads.rake#L126>

The rest of this is a bizarre story. I don’t know whether it will help anyone. It’s another story that ends with “it got fixed by rebooting.”

But I decided to take matters into my own hands. The images had already been downloaded from S3 and manually put into `uploads`, so I fixed up the uploads like this:

```ruby
bads=Upload.where("url like '//xxx-discourse%'")

bads.each do |up|
  up.url.gsub!(/\/\/xxx-discourse.s3-ap-southeast-1.amazonaws.com\//,'/uploads/default/')
  up.save
end 

```

and then rebaked the posts like this:

```ruby
bps = Post.where("cooked like '%//xxx-discourse%'")
bps.each do |post|
  post.rebake!
  post.save
end

```

But this didn’t fix all of them, somehow. After that, I still had a bunch of posts that still pointed to S3. I tried rebaking, but still there were some `upload://serfsfsef.jpg` that would rebake to the old S3 URL no matter what I did. And THEN I pasted that same URL into a new post, and it generated the **right** (not S3) URL. And then, I fixed up cook myself like this:

```ruby
bps = Post.where("cooked like '%//xxx-discourse%'")
bps.each do |post|
  post.cooked.gsub!(/\/\/xxx-discourse.s3-ap-southeast-1.amazonaws.com\//,'/uploads/default/')
  post.save
end

```

And then, if I rebaked the post, it would still revert to the S3 URL.

And then, I rebooted the container, and it rebaked correctly. I guess something got cached somewhere, somehow.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2018 年5 月 2 日 13:14 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337/2 "2018-05-02T13:14:10Z")

</div>

> [@pfaffman](#):
>
> Or maybe this is a vestige of the old way images were put into `raw`?

That’s your answer right there 😉

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2018 年5 月 2 日 15:22 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337/3 "2018-05-02T15:22:56Z")

</div>

So perhaps we should change this:

> <https://github.com/discourse/discourse/blob/main/script/import_scripts/base/uploader.rb#L38>

And, perhaps, matters are made worse because when the post is created the code doesn’t it’s embedding the old way so it’s not getting tagged as version 0 (1?), so the task that would run to fix it doesn’t know to? (I’ve not looked at that version code closely enough to know what I’m talking about, much less describe it cogently).

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2018 年12 月 26 日 16:45 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337/5 "2018-12-26T16:45:58Z")

</div>



---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2018 年12 月 26 日 16:46 UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337/6 "2018-12-26T16:46:04Z")

</div>


