# مشاكل غريبة مع migrate\_from\_s3

**URL:** <https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337>\
**Category:** Development\
**Created:** [27 أبريل 2018، 7:49م UTC](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337 "2018-04-27T19:49:17Z")\
**Posts on this page:** 1\
**Showing post:** 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:** [27 أبريل 2018، 7: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.

---

_[View the full topic](https://meta.discourse.org/t/bizarre-problems-with-migrate-from-s3/86337)._
