Remove remote media attachments from Mastodon instance.

Inspect media usage.

$ RAILS_ENV=production /home/mastodon/live/bin/tootctl media usage
Attachments:    51.1 GB (4.14 MB local)
Custom emoji:   458 MB (9.58 KB local)
Preview cards:  1.76 GB
Avatars:        556 MB (22.7 KB local)
Headers:        1.44 GB (357 KB local)
Backups:        0 Bytes
Imports:        0 Bytes
Settings:       0 Bytes

Start rails cnsole.

$ RAILS_ENV=production bundle exec rails console
Chewy console strategy is `urgent`
Loading production environment (Rails 6.1.7.4)
irb(main):001:0> MediaAttachment.first

Inspect MediaAttachment object.

=>
#

Remove media attachments from remote locations.

irb(main):001:0> MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).each { |f| f.file.destroy; f.save }
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/344/666/722/941/776/original/5e867753884d6263.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/344/666/722/941/776/small/5e867753884d6263.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/417/221/530/300/397/original/d115f901218f9233.jpeg
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/417/221/530/300/397/small/d115f901218f9233.jpeg
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/423/845/117/856/417/original/e00595601e4ca455.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/423/845/117/856/417/small/e00595601e4ca455.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/493/264/310/839/262/original/e9ac08d790023dbc.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/493/264/310/839/262/small/e9ac08d790023dbc.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/593/932/387/996/611/original/08418086bc410260.jpeg
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/593/932/387/996/611/small/08418086bc410260.jpeg
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/628/225/757/330/083/original/4eff7cbec35965f9.webp
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/628/225/757/330/083/small/4eff7cbec35965f9.webp
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/697/081/966/126/775/original/5e17c34e93f28e7c.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/697/081/966/126/775/small/5e17c34e93f28e7c.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/793/692/802/159/322/original/4b899f6483d4649b.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/793/692/802/159/322/small/4b899f6483d4649b.png
[paperclip] deleting /home/mastodon/live/public/system/cache/media_attachments/files/109/887/026/099/732/003/original/0f44be62ca386bb3.jpg
[...]

Count media attachments that got here in the meantime.

irb(main):002:0> MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).count
=> 11

Inspect media usage.

$ RAILS_ENV=production /home/mastodon/live/bin/tootctl media usage
Attachments:    13.7 MB (4.14 MB local)
Custom emoji:   458 MB (9.58 KB local)
Preview cards:  1.76 GB
Avatars:        557 MB (22.7 KB local)
Headers:        1.44 GB (357 KB local)
Backups:        0 Bytes
Imports:        0 Bytes
Settings:       0 Bytes

Problem solved.

ko-fi