What happens if I manually move images out of the tombstone directory?

Recently, I’ve been migrating a bunch of data from an old forum (Google Spaces, actually) to my own Discourse instance. As part of this process, I uploaded a bunch of images through the Discourse API with the intent to reference them later from subsequent posts. I thought I had 30 days to do this, but it turns out that the default for moving things into the tombstone directory is just 2 days, and then they are gone entirely in 30 days. My mistake.

Now, all these images are uploaded to an S3 instance, as I do with all uploaded content. So (because it was late at night and I wasn’t thinking all that straight) I simply went into S3 and moved all the stuff out of the tombstone directory into the normal images directory, and made the content publicly accessible (as the “normal” uploads are). I was then able to refer to them from the posts as intended. After I did this, it occurred to me that perhaps this was not the greatest idea I have ever had.

So my question is:

What horrible thing have I done to Discourse’s internal bookkeeping by manually moving this stuff? Is there some image database that I’ve broken? Is there a task I can run to rebuild it? I’d turned off garbage collection (temporarily, I hope) at that point, and I want to reenable it, but I don’t want Discourse to re-tombstone these images. Any advice would be greatly appreciated.

cd /var/discourse 
./launcher enter app rake uploads:recover_from_tombstone

Should do the trick

1 Like

I did see this, but two things:

  1. The comments/code for this indicated that it would not work on external storage. These images are all being automatically uploaded to an Amazon S3 bucket. Does that not count as external?
  2. I’ve already moved the images from the tombstone directory to the normal images directory. Since they aren’t physically in the tombstone anymore, will this be able to recover them?

Oh, and thanks for such a prompt reply!

EDIT: In other words, the physical images have already been moved. I just don’t know if Discourse has some additional bookkeeping information or database that also has to be updated.

I’m not an expert at this issue, but I’m pretty sure that your moving the stuff back to where you’re linking to them does pretty much what that rake task would do.

There’s certainly no harm in trying.

My guess is that it’ll be just fine unless Discourse still thinks they’re bad and deletes them again.

1 Like

No, there’s also an entry in the database that needs to be recovered.

3 Likes

Right. So will running the Rake task restore the database if the images have already been moved and they’re being stored in an S3 bucket? Again, the code indicates that the recover_from_tombstone function won’t work on external storage. It simply bails if this is the case.

1 Like

Was there ever a solution to this John? I’m having the same problem now.

We are working on a rake task here, at the moment the recover from tombstone task explicitly checks for s3 and exits if s3 is enabled.

2 Likes

Oh man, it’s been a while since I did this, so I can’t recall exactly how I solved it.

I don’t think there was a solution that worked out of the box. I think I modified the rake task to patch the local database without have to reupload the images? There were definitely a few points during my migration where I had to execute some custom tasks. This may have been one of them.

I’m really sorry. I wish I could remember what I did. All I remember is that I had to engineer a solution myself.