I’ve addressed this successfully on the site I’m managing by using an adapted version of the same logic that recovers incorrectly tombstoned images in posts: discourse/lib/upload_recovery.rb at main · discourse/discourse · GitHub.
@Jeremie_Leroy Part of the reason I posted those steps above is that there are various possible causes of missing avatars. To know if this is going to work for you, you first have to confirm that there are incorrectly tombstoned avatars, i.e. what the cause of the issue in your case is.
I also understand that undertaking that analysis is very hard if you’re not familiar with the technical aspects of Discourse. I’ve put the solution I used into a plugin which you can try on your own site. See instructions below.
@Pad_Pors If you’re ok just asking people to re-upload avatars I would just do that and not attempt this fix.
Instructions
Please note that this is a fix for missing avatars when:
- Uploads are stored in s3
- Avatars are missing because they are incorrectly tombstoned
- The upload record of the avatar still exists
Do this at a time of low activity on your forum and perform a full backup first.
Install this plugin
https://github.com/angusmcleod/discourse-s3-avatar-recovery
The plugin adds recover_avatars to UploadRecovery, and uses an adapted version of the same restore method used by the main recover method used to recover missing uploads in posts.
This will keep a copy of the “recovered” avatars in the tombstone folder for redundancy. These copies will be removed by the purge_deleted_uploads background job which runs according to the period set by the purge_deleted_uploads_grace_period_days site setting.
Enter the rails console
To use the method you need to first ssh into your server, enter the docker instance and start a rails console:
./launcher enter app
rails c
Do a test run
To see which uploads the method is going to try and recover from tombstone, first do a test run:
UploadRecovery.new(dry_run: true, stop_on_error: false).recover_avatars
This will give you a list of usernames and s3 file links. These are the avatar files the method will attempt to move out of tombstone on a real run:
Example output
user1 tombstone/original/2X/b/bc84397936074854226f1c6e9016099b7fc0aca7.jpeg
user2 tombstone/original/2X/b/b8588e7e45804406f2cbe86f2362c2ccf7f13155.jpg
user3 tombstone/original/2X/8/81a4e3b70cdc35e8f61bca87d276d0253152804a.jpeg
Compare this with the users missing avatars on your site.
Do a real run
Change dry_run to true to do a real run
UploadRecovery.new(dry_run: false, stop_on_error: false).recover_avatars
Check
Once the job is complete check your live site in a new incognito window (to avoid caching issues). Once you’re done make sure you close down the active ssh conection to your server. You don’t want to accidentially enter the wrong thing in the open rails console.