# Herstellen of opschonen van kapotte links en assets na een herstel

**URL:** https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835
**Category:** Support
**Created:** [13 juni 2022 om 17:20 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835 "2022-06-13T17:20:48Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [13 juni 2022 om 17:20 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/1 "2022-06-13T17:20:48Z")

</div>

We had a server crash and had to create a new server and restore from a backup. It was a harrowing process, [details for what happened and how we restored it here](https://meta.discourse.org/t/help-restoring-system-hung-at-midnight/229486/).

Now after restoring (the key was to disable S3 uploads), all the links to attachments in posts are broken (404 error). I’ve searched the forum and can’t find a solution and hoping someone can point me in the right direction.

I have two options

1. Can I fix these broken `short-url` links which link to attachments embedded in posts (all the broken links are for attachments in posts; embedded images render fine, other internal link work fine)?

For example, the URL to the attachment on a post on the forum shows as `https://XYZ.com/uploads/short-url/phu1HOLvkE8LWpkKYfnMPSWsvHh.zip` This is what I’m seeing in the logs when I click on an attachment link in a post (which leads to a 404).

> Message (5 copies reported)
> 
> Failed to process hijacked response correctly : Errno::ENOENT : No such file or directory @ rb\_sysopen - /XXXXX.s3.dualstack.us-east-1.amazonaws.com/optimized/1X/46728e07f9819907d1b18387bf02ea7fc25c7981\_2\_32x32.ico
> 
> Backtrace
> 
> /var/www/discourse/app/controllers/static\_controller.rb:160:in `read' /var/www/discourse/app/controllers/static_controller.rb:160:in `block (2 levels) in favicon’  
> /var/www/discourse/lib/distributed\_memoizer.rb:16:in `block in memoize' /var/www/discourse/lib/distributed_mutex.rb:33:in `block in synchronize’  
> /var/www/discourse/lib/distributed\_mutex.rb:29:in `synchronize' /var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize’  
> /var/www/discourse/lib/distributed\_mutex.rb:14:in `synchronize' /var/www/discourse/lib/distributed_memoizer.rb:12:in `memoize’  
> /var/www/discourse/app/controllers/static\_controller.rb:138:in `block in favicon' /var/www/discourse/lib/hijack.rb:56:in `instance\_eval’

I’m really hoping there’s a way to fix these `short-url` links after disabling the S3 upload option while restoring the server from a backup. A post re-bake did not fix it.

1. If for someone reason this is a dead-end and cannot be fixed en mass, now I’ve had thousands of orphaned attachments on the S3 cloud, is there a way to clean them up and free up the space? Is there a way Discourse can go through it’s S3 upload bucket and clear out all orphaned assets?

---

<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: [13 juni 2022 om 20:16 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/2 "2022-06-13T20:16:27Z")

</div>

It might be, or might have been, possible to figure out how to fix up those links, but figuring out how is beyond the scope of what’s feasible in a forum.

```plaintext
Upload.sha1_from_short_url('phu1HOLvkE8LWpkKYfnMPSWsvHh.zip')
=> "b13050bdcd2d58924ba6ab3e7608b16bfc3cd1b7"

```

See if you have a file called `b13050bdcd2d58924ba6ab3e7608b16bfc3cd1b7.zip` somewhere in your uploads and/or s3 bucket. If so, then it should be possible, though not easy, to fix things up.

Since you didn’t include the actual forum or bucket names, we can’t tell here.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [13 juni 2022 om 21:00 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/3 "2022-06-13T21:00:42Z")

</div>

Yes, I did find that under:

> original/2X/b/b13050bdcd2d58924ba6ab3e7608b16bfc3cd1b7.zip

Happy to PM you the links/details

What’s very funny is that just the attachments (like files) are broken. Any embedded images display just fine.

---

<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: [13 juni 2022 om 21:18 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/4 "2022-06-13T21:18:39Z")

</div>

> [@RBoy](#):
>
> Yes, I did find tha

Then the stuff is all there, you just need to re-write the posts somehow. Not sure why it’s not working, but the files are there.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [13 juni 2022 om 21:34 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/5 "2022-06-13T21:34:20Z")

</div>

> [@pfaffman](#):
>
> you just need to re-write the posts somehow

Is there a way to run this en mass from the console or the UI or “download” these files from S3 to local?

---

<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: [13 juni 2022 om 23:45 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/6 "2022-06-13T23:45:56Z")

</div>

I believe so, but I think that someone who’s familiar with discourse and rails will need to write it. I’m not aware of an existing solution to your problem. There are a few topics about moving between S3 buckets that might offer some clues, but I don’t think that your particular problem has been solved before.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [14 juni 2022 om 00:48 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/7 "2022-06-14T00:48:08Z")

</div>

> [@RBoy](#):
>
> fix these `short-url` links after disabling the S3 upload option while restoring the server from a backup

After restoring, you should have re-enabled the S3 upload option. It sounds like you did not do that?

---

<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: [14 juni 2022 om 01:07 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/8 "2022-06-14T01:07:50Z")

</div>

And it’s hard to do since it got set on the app.yml that might do it.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [14 juni 2022 om 01:12 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/9 "2022-06-14T01:12:03Z")

</div>

Would that fix the issue? Just wondering it’s safe to try.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [14 juni 2022 om 01:12 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/10 "2022-06-14T01:12:56Z")

</div>

Well, yes, it’s what I recommended you to do in the first place…  
If you don’t re-enable S3 uploads then the `short-url` function will look for those uploads locally, but they are on S3.

---

<div class="post-metadata">

### Author: ![RBoy](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@RBoy](https://meta.discourse.org/u/RBoy)
#### Post date: [14 juni 2022 om 01:14 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/11 "2022-06-14T01:14:23Z")

</div>

I’ll try it but on the other hand when I enabled it it broke the restore (see my other topic). With Jays help I had to figure out how to disable the upload to eventually restore it. Have you been able to successfully restore a server with the option enabled?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [14 juni 2022 om 01:15 UTC](https://meta.discourse.org/t/fixing-or-cleaning-up-broken-links-and-assets-after-a-restore/229835/12 "2022-06-14T01:15:44Z")

</div>

You need to

- Disable the setting
- Restore
- Enable the setting

As I described in our PM exchange last week
