# Old image uploads become broken images

**URL:** https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236
**Category:** Support
**Created:** [7월 13, 2016, 6:38오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236 "2016-07-13T18:38:57Z")
**Posts on this page:** 20
**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: [7월 13, 2016, 6:38오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/1 "2016-07-13T18:38:57Z")

</div>

For the past week or so (after the most recent upgrade?), I’ve noticed that some users’ uploaded images are broken. It is clear that they are pasting an image, as the code in their post looks like that, but the files are missing.

For example, [this post](https://literatecomputing.com/t/success-with-social-bookmarking/4317) ([raw version](https://literatecomputing.com/raw/4317) has three broken images in it. I cannot imagine what the user could have done to break them. And stranger still, sometimes a post will have some images that work fine, but others that are missing. I’ve done `find` in the uploads directory and the files aren’t there anywhere.

I can’t see any rhyme or reason to it. Has anyone else noticed a similar problem lately?

---

<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: [7월 13, 2016, 10:48오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/2 "2016-07-13T22:48:48Z")

</div>

Lest anyone thinks that this query went unanswered, many thanks to @zogstrip for solving this. It seems that Discourse got confused about whether those uploaded images were being used and moved them for subsequent deletion.

Though you will probably never need it, the fix went something like this:

```plaintext
# copy the "deleted" images from their to-be-deleted staging area
cd /var/discourse
./launcher enter app
rake uploads:recover_from_tombstone

# rebake to see that it doesn't happen again
rake posts:rebake

```

---

<div class="post-metadata">

### Author: ![LeoDavidson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leodavidson/32/119574_2.png) [@LeoDavidson](https://meta.discourse.org/u/LeoDavidson)
#### Post date: [1월 31, 2017, 7:45오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/3 "2017-01-31T19:45:17Z")

</div>

It looks like the first `rake uploads:recover_from_tombstone` command now handles the rebaking done by the `rake posts:rebake` command, after this commit:

[https://github.com/discourse/discourse/commit/333d6f9f10a4a2b62393188a8d4595f44b764242](https://github.com/discourse/discourse/commit/333d6f9f10a4a2b62393188a8d4595f44b764242)

So anyone finding this thread now, you can probably skip the second part (unless I am mistaken! I am new to this).

Since this is the only place I found information about this fix, and the two commands take a very long time to run (over 12 hours here), I wanted to update the thread to help save time for anyone else.

Have some odd problems on my new forum (imported from phpBB), where attachments keep being deleted. Initially, it may have been due to me setting the grace period too low and things being deleted as their corresponding posts were still in the import queue, but a few things still seem to be getting deleted, which I’ve not got to the bottom of yet.

---

<div class="post-metadata">

### Author: ![heaven007](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heaven007/32/121223_2.png) [@heaven007](https://meta.discourse.org/u/heaven007)
#### Post date: [2월 24, 2017, 9:11오전 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/4 "2017-02-24T09:11:31Z")

</div>

Happened to us with 1.8.0.beta6.

While these steps helped:

```ruby
rake uploads:recover_from_tombstone
rake posts:rebake

```

I am still not sure what was the cause.

---

<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: [2월 24, 2017, 9:33오전 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/5 "2017-02-24T09:33:46Z")

</div>

We have seen this happen a few times, immediately after an update.  
Since we found this out, we have been disabling Sidekiq during the upgrade and this issue never happened again.

---

<div class="post-metadata">

### Author: ![imikerussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/imikerussell/32/120806_2.png) [@imikerussell](https://meta.discourse.org/u/imikerussell)
#### Post date: [8월 8, 2017, 5:06오전 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/6 "2017-08-08T05:06:10Z")

</div>

This thread has been very helpful.

A couple of issues I have encountered with broken upload links:

1. My board has a non-traditional file upload enabled (mp3) and Discourse was going through deleting all uploads older than 48 hours. I have resolved this by unchecking _clean up uploads_ in admin.

 ![37](https://global.discourse-cdn.com/meta/original/3X/e/8/e8d4816faa0af246d56f47f0c24f5838ca3a941c.png)

1. If you host uploads on Amazon S3 `rake uploads:recover_from_tombstone` will not work. You get this error instead: `This task only works for internal storages`

Is there a way to keep the remove orphan unreferenced uploads option enabled **and** have it recognise and not delete non-regular files (such as mp3)?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [8월 8, 2017, 9:24오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/7 "2017-08-08T21:24:47Z")

</div>

Uploads that are linked in posts shouldn’t be removed. That setting only helps with uploads that are not linked in any posts.

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 9:49오전 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/8 "2017-09-25T09:49:43Z")

</div>

I have a similar problem (I think) after an update to stable v1.8.7, but the command `rake uploads:recover_from_tombstone` says:

```txt
  1 / 9 ( 11.1%)
Restoring /var/www/discourse/public/uploads/tombstone/default/original/1X/27bf77d1d3f09d13b1f89cf97552a8ae19aa4d98.png...rake aborted!
TypeError: no implicit conversion of Symbol into Integer
/var/www/discourse/lib/upload_creator.rb:190:in `[]'
/var/www/discourse/lib/upload_creator.rb:190:in `should_crop?'
/var/www/discourse/lib/upload_creator.rb:47:in `block in create_for'
/var/www/discourse/lib/distributed_mutex.rb:21:in `synchronize'
/var/www/discourse/lib/distributed_mutex.rb:5:in `synchronize'
/var/www/discourse/lib/upload_creator.rb:34:in `create_for'
/var/www/discourse/lib/tasks/uploads.rake:441:in `block (4 levels) in recover_from_tombstone'
/var/www/discourse/lib/tasks/uploads.rake:440:in `open'
/var/www/discourse/lib/tasks/uploads.rake:440:in `block (3 levels) in recover_from_tombstone'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
/var/www/discourse/lib/tasks/uploads.rake:428:in `block (2 levels) in recover_from_tombstone'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/relation/delegation.rb:46:in `each'
/var/www/discourse/lib/tasks/uploads.rake:424:in `block in recover_from_tombstone'
/var/www/discourse/lib/tasks/uploads.rake:420:in `each'
/var/www/discourse/lib/tasks/uploads.rake:420:in `each_with_index'
/var/www/discourse/lib/tasks/uploads.rake:420:in `recover_from_tombstone'
/var/www/discourse/lib/tasks/uploads.rake:401:in `block (2 levels) in <top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:126:in `block in each_connection'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:124:in `each'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/rails_multisite-1.0.6/lib/rails_multisite/connection_management.rb:124:in `each_connection'
/var/www/discourse/lib/tasks/uploads.rake:401:in `block in <top (required)>'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `<main>'
Tasks: TOP => uploads:recover_from_tombstone
(See full trace by running task with --trace)

```

Is this a bug or a problem with my installation?

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 3:55오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/9 "2017-09-25T15:55:18Z")

</div>

I rebuild the app and restarted the server (as it seems to have a problem with sidekiq) and then I did a hack (?) but it this seems to work for all the broken images:

./launcher enter app  
cp public/uploads/tombstone/default/original/1X/\* public/uploads/default/original/1X/

---

<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: [9월 25, 2017, 3:59오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/10 "2017-09-25T15:59:47Z")

</div>

Here’s what you want to do:

```plaintext
cd /var/discourse
./launcher enter app
bundle exec rake uploads:recover_from_tombstone

```

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 4:57오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/11 "2017-09-25T16:57:51Z")

</div>

Ah, thanks. Should I still do this or is this doing just the cp like I did?

---

<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: [9월 25, 2017, 4:58오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/12 "2017-09-25T16:58:45Z")

</div>

You should do it. My incomplete understanding is that it updates the database so that this won’t happen again.

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 6:33오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/13 "2017-09-25T18:33:08Z")

</div>

> [@pfaffman](#):
>
> bundle exec rake uploads:recover\_from\_tombstone

Hmmh, I do something wrong. It either says:

```plaintext
URGENT: FATAL: Peer authentication failed for user "discourse"
 Failed to initialize site default
rake aborted!
PG::ConnectionBad: FATAL: Peer authentication failed for user "discourse"
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
...

```

or when I do sudo -u discourse it says:

```plaintext
rake aborted!
Errno::EACCES: Permission denied
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/bootsnap-0.3.0/lib/bootsnap/compile_cache/iseq.rb:34:in `fetch'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/bootsnap-0.3.0/lib/bootsnap/compile_cache/iseq.rb:34:in `load_iseq'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/bootsnap-0.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/bootsnap-0.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
...

```

---

<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: [9월 25, 2017, 6:34오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/14 "2017-09-25T18:34:22Z")

</div>

Did you do `./launcher enter app`?

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 6:35오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/15 "2017-09-25T18:35:07Z")

</div>

Yes, and then I end up in the folder /var/www/discourse

---

<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: [9월 25, 2017, 6:39오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/16 "2017-09-25T18:39:16Z")

</div>

Hmm. Try just ` rake uploads:recover_from_tombstone` (without `bundle exec`), but I **just did** the `bundle exec` and it worked.

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 6:41오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/17 "2017-09-25T18:41:42Z")

</div>

I did this in my [original comment](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/8)

---

<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: [9월 25, 2017, 6:46오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/18 "2017-09-25T18:46:57Z")

</div>

> [@karussell](#):
>
> I did this in my original comment

Sorry. And this is a standard Docker install?

---

<div class="post-metadata">

### Author: ![karussell](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/karussell/32/79339_2.png) [@karussell](https://meta.discourse.org/u/karussell)
#### Post date: [9월 25, 2017, 6:58오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/19 "2017-09-25T18:58:36Z")

</div>

Yes. I’ve started using it with a very early version (I think I started with the first docker shipped version) but the upgrades always went without problems, except recently (but was ‘fixable’)

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [9월 25, 2017, 7:39오후 UTC](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236/20 "2017-09-25T19:39:14Z")

</div>

I’m guessing here, but… maybe try running `/var/discourse/launcher rebuild app` first, to make sure you have the latest base image? 🤔

[다음 페이지](https://meta.discourse.org/t/old-image-uploads-become-broken-images/47236.md?page=2)
