Restored backup without cache dir, manual removal did not help

I recently restored a backup to a new VPS. This backup did not contain the cache directory. Following Can the cache directory be removed from backups? - #2 by Claire, I first shut down my instance, then, inside RAILS_ENV=production bundle exec rails console, I ran

MediaAttachment.cached.where.not(remote_url: '').each { |f| f.file.destroy; f.thumbnail.destroy; }

Then when I started my instance, most images were missing, as expected, but even when I reloaded individual profiles using the Admin FE, or when I ran RAILS_ENV=production bin/tootctl media refresh --domain mastodon.example, nothing changed :\

What should I do?

For media attachments, I would have expected what you did to be enough. However, note that this Ruby snippet clears media attachments, not account header and avatar, if that’s the issue. Similarly, media refresh --domain mastodon.example would work on media attachments, not account header and avatar.

Something like the following may work:

Account.remote.where.not(avatar_file_name: nil).where.not(avatar_remote_url: '').each { |a| a.avatar.destroy; }
Account.remote.where.not(header_file_name: nil).where.not(header_remote_url: '').each { |a| a.header.destroy; }

Ah! That did it! Now how can I refresh every single remote profile? Or do I not need to?

Hm, there is no tootctl command to do that. Something like the following should help, though it’ll cause quite a bit of traffic:

Account.remote.where(avatar_file_name: nil).where.not(avatar_remote_url: '').each { |a| a.download_avatar! }
Account.remote.where(header_file_name: nil).where.not(header_remote_url: '').each { |a| a.download_header! }

OK, thanks. Ah, and now I have the same issue with remote emojis, but I will try and see if I can’t write up some code to do it myself.

Nevermind :weary: I couldn’t figure out the equivalent of f.file.destroy for CustomEmoji.remote :frowning:

What should I do to delete and re-download remote emojis?

You’d do CustomEmoji.remote.where.not(image_file_name: nil).where.not(image_remote_url: '').each { |emoji| emoji.image.destroy;!; emoji.download_image! } or something like that

1 Like

OK I ran this

but when I re-run it, it still does stuff? Also most remote avatars are still empty. Is it okay to run it while the instance is running?

Also, I ran CustomEmoji.remote.where.not(image_file_name: nil).where.not(image_remote_url: '').each { |emoji| emoji.image.destroy; emoji.image. save; begin emoji.download_image!;! rescue nil end} (while the instance was running) and remote emojis still aren’t loading

oops i think it’s missing an! at the end

i’m running this now Account.remote.where(avatar_file_name: nil).where.not(avatar_remote_url: '').each {|account| account.update!(last_webfingered_at: n il); begin rescue nil end} based on the redownload route in the Admin UI.

OK, that worked! Now, on to the emojis…

I did some more digging on it.
if i run [CustomEmoji.remote.where.not(image_file_name: nil).where.not(image_remote_url: '').where(shortcode: "hug")[0]].each {|emoji| emoji.image.destroy;; emoji.download_image! }
(forgive the extraneous list, ruby is not my native tongue), then the image_file_name is updated, but the actual url linked to when the emoji is used remains unchanged

maybe it would be easier to just clear all remote emojis and let them re-federate lazily?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.