# S3 assets broken after moving forum

**URL:** https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627
**Category:** Support
**Created:** [September 28, 2021, 8:48am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627 "2021-09-28T08:48:56Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 28, 2021, 8:48am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/1 "2021-09-28T08:48:56Z")

</div>

Hi,

I had to move an abandoned Discourse forum. Luckily, we had multiple admins, so it was possible to do and download a backup. We used a S3 bucked for our assets, which was kind of a problem. I’ll make a feature request at this point:

Make it possible to include S3 assets into backups

I found out (not sure if it was before or after rebaking the posts), that S3 asset URLs got rewritten to internal ones. So I extracted all `original` and `optimized` S3 URLs out of the database file and downloaded them (kind of) manually. After moving them to the right place, all missing images got displayed. … It would be great to have an automatic feature for that.

So far, I encountered three bugs:

1. Broken preview images, working enlarged images

- Old Forum: [https://discuss.openhdfpv.com/t/asus-usb-ac56-wiring-antennas-etc/103](https://discuss.openhdfpv.com/t/asus-usb-ac56-wiring-antennas-etc/103)
- New Forum: [https://forum.openhdfpv.org/t/asus-usb-ac56-wiring-antennas-etc/103](https://forum.openhdfpv.org/t/asus-usb-ac56-wiring-antennas-etc/103)

1. Working preview images, no mouse over for enlarging images

- /t/microlongrange-openhd-edition/379 _… I can only do 2 links on my first post_

1. Gravatars are broken (maybe unrelated):  
- ![grafik](https://global.discourse-cdn.com/meta/original/3X/d/6/d620fddef0356925be5320411ef08a64c4d15ddb.png)

I found no problems on new posts.

Thanks for this great project,  
Limitless Green

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [September 28, 2021, 9:56am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/2 "2021-09-28T09:56:48Z")

</div>

> [@LimitlessGreen](#):
>
> I found out (not sure if it was before or after rebaking the posts), that S3 asset URLs got rewritten to internal ones.

That sounds like a misconfiguration, not a bug. Did you configure the same S3 bucket on the new host before restoring?

---

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 28, 2021, 10:00am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/3 "2021-09-28T10:00:08Z")

</div>

I restored the backup, which also contains the configuration. After doing that (and force https) I don’t got pictures from the S3 bucket at all.

Now I removed the S3 configuration completely.

Isn’t it a complete configuration overwrite?

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [September 28, 2021, 10:42am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/4 "2021-09-28T10:42:51Z")

</div>

> [@LimitlessGreen](#):
>
> which also contains the configuration.

Except the S3 configuration, if it was previously configured using ENV vars in `app.yml` …

---

<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: [September 28, 2021, 10:47am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/5 "2021-09-28T10:47:30Z")

</div>

> [@LimitlessGreen](#):
>
> Make it possible to include S3 assets into backups

There is a hidden setting that does just that. Cdck turns it on for customers that they know plan to plan their hosting.

S3 configuration is best done in environment variables as described in [Using Object Storage for Uploads (S3 & Clones)](https://meta.discourse.org/t/using-object-storage-for-uploads-s3-clones/148916).

---

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 28, 2021, 10:47am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/6 "2021-09-28T10:47:52Z")

</div>

After restoring, I had set configs in: `s3 upload bucket` and `s3 cdn url`.  
I don’t have access to the `app.yml` (of the old server).

---

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 28, 2021, 10:59am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/7 "2021-09-28T10:59:11Z")

</div>

> [@pfaffman](#):
>
> There is a hidden setting that does just that.

Oh, nice! 😀 Where?  
The only suitable option in the `backup` section I fond was:  
 ![grafik](https://global.discourse-cdn.com/meta/original/3X/d/7/d7794586c87a11a5ae2f4df683afd191d00dc761.png)  
(which was ticked)

I’m not sure if it’s clear: I don’t want S3 for now. And I had to get the assets from there. No one knows, how long this server will stay. 😅

---

<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: [September 28, 2021, 11:27am UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/8 "2021-09-28T11:27:13Z")

</div>

If you don’t have access to the server via ssh you can’t change the hidden setting.

---

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 29, 2021, 4:14pm UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/9 "2021-09-29T16:14:04Z")

</div>

Alright. And what should be done now in a case like mine?  
What can lead to this broken image preview?

---

<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: [September 29, 2021, 5:29pm UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/10 "2021-09-29T17:29:33Z")

</div>

If it’s not too late (that is, there’s traffic on the forum that’s happened and you don’t want to lose) and you have the S3 credentials, then I’d probably put the s3 credentials in the `app.yml` and re-run the restore. From there, you could probably set the hidden setting, do a backup, and restore it on a server without S3.

But I think that’s not the case. And it’s not clear just what the issues might be since even you don’t remember exactly what you did when.

If stuff is missing (and you have s3 credentials), I might try using some S3 tool to pull down all of the uploads and then hack at the database to get it to point to them. But I am not good enough at that to explain here how to do it.

---

<div class="post-metadata">

### Author: ![LimitlessGreen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/limitlessgreen/32/235212_2.png) [@LimitlessGreen](https://meta.discourse.org/u/LimitlessGreen)
#### Post date: [September 29, 2021, 7:03pm UTC](https://meta.discourse.org/t/s3-assets-broken-after-moving-forum/204627/11 "2021-09-29T19:03:12Z")

</div>

Yeah, sadly I don’t have the S3 credentials ☹

I can reproduce the steps:

1. Installed a new Discourse Forum with discourse\_docker behind Traefik
2. Did a backup of the old forum (including some old assets)
3. Restored the backup on the new forum
4. Forced HTTPS
5. Got asset URLs out of the `dump.sql` (from the backup)

- `egrep -o 'discuss-openhdfpv.eu-central-1.linodeobjects.com\/original\/1X\/[0-9a-z_]{0,}\.[0-9a-zA-Z]{0,}' ./dump.sql >> original.txt`
- `egrep -o 'discuss-openhdfpv.eu-central-1.linodeobjects.com\/optimized\/1X\/[0-9a-z_]{0,}\.[0-9a-zA-Z]{0,}' ./dump.sql >> optimized.txt`

1. Downloaded the assets: `cat optimized.txt | parallel --gnu "wget -nc -P ./optimized/1X/ {}"` (same with original)
2. Removed the S3 configurations
3. `rake posts:rebake`

I can do SQL stuff at the database, when I know what to look for.
