I’ve been running a self-hosted Discourse site for about four and a half years now (since September 2014), and I just received a report of several broken image links on my site. After looking into the issue, I noticed that the paths to all of the offending images were in the format uploads/default/XXX/
, where XXX
is a three-digit number (e.g. uploads/default/240/
and uploads/default/247/
). Sure enough, the corresponding directories under /var/discourse/shared/standalone/uploads/default/
were empty, but the problem was more extensive than I realized: almost all the numbered directories under /var/discourse/shared/standalone/uploads/default
appeared to be empty, as well!
Thankfully, it looks like most of the images had been moved to their corresponding folders in the “tombstone” directory (i.e. /var/discourse/shared/standalone/uploads/tombstone/default/XXX/
) and should thus theoretically be recoverable by following @tgxworld’s instructions:
./launcher enter app
rails c
require_dependency "upload_recovery"
UploadRecovery.new.recover
The call to UploadRecovery.new.recover
completed fairly quickly, but unfortunately it did not restore the uploaded files to their original locations. Running UploadRecovery.new(dry_run: true).recover
did not return any entries, either, so I was left with the impression that there isn’t a problem with the database (though I could be wrong!).
Anyway, after looking around a bit more I noticed that many of the newer files seemed to be uploaded under the uploads/default/original/1X/
or uploads/default/original/2X/
directories rather than uploads/default/XXX/
. I wonder…could it just be that the canonical location for uploads has changed, and Discourse is now simply discarding anything that isn’t stored under uploads/default/original/{1,2}X
?
For what it’s worth, all of the affected directories (i.e. /var/discourse/shared/standalone/uploads/default/XXX/
and /var/discourse/shared/standalone/uploads/tombstone/default/XXX/
) and their files appear to have the same “last-modified” timestamp—11:14 a.m. on January 18—which just so happens to be a few hours after I upgraded to v2.2.0.beta8 (though I couldn’t tell you the exact commit number). Interestingly enough, I don’t see this timestamp on any of the subdirectories of uploads/default/original/{1,2}X/
.
In summary:
-
Is there any reason that images stored in directories like
/var/discourse/shared/standalone/uploads/default/240/
would be automatically moved to the tombstone directory even if they are still being actively referenced by existing posts? -
Is it safe to just copy the missing images from
/var/discourse/shared/standalone/uploads/tombstone/default/XXX/
to/var/discourse/shared/standalone/uploads/default/XXX/
, or is there another command I should run to accomplish this? -
If it isn’t safe to copy the missing images and there isn’t a command to accomplish this, how can I restore the images and/or update all the posts that reference them? (Should I migrate them to
uploads/default/original/{1,2}X/
somehow?)
Thanks!