Adventures in Mastodon Self-Hosting: Clean Media Storage with tootctl
Mastodon 4.1.0rc1 has new flags to tootctl media remove
to help prune old
storage of profile avatars and header images. Each account you encounter, either
via follow, boost, or reply to a post that was followed or boosted, hits your
instance and caches an avatar (profile pic) and header image (banner image).
This can take up a lot of space!
Get a base line data usage
mastodon@mastodon:~/live$ bundle exec bin/tootctl media usage
Attachments: 353 MB (1.57 MB local)
Custom emoji: 49 MB (0 Bytes local)
Preview cards: 10.6 MB
Avatars: 2.16 GB (28.9 KB local)
Headers: 4.56 GB (0 Bytes local)
Backups: 0 Bytes
Imports: 0 Bytes
Settings: 0 Bytes
So theres 4.56GB of header images, none of which are from local accounts (live on my instance, which is just me).
Theres 2.16 GB of avatar images, only 28.9KB are from my single local account.
Attachments is fairly low because I have configured mastodon to delete those when they’re older than 3 days. This can be done in the admin portal.
That doesnt seem like a lot, but remember this is a $6/mo droplet with 25 total gigabytes of space. I’m usually sitting at 98% disk usage, and outside of this folder, I’m not sure what else I can clean off.
Do a dry-run to see what will happen deleting profile media from accounts I havent seen in 7 days or more
mastodon@mastodon:~/live$ bundle exec bin/tootctl media remove --days 7 --prune-profiles --dry-run
23771/23771 |==============================================================| Time: 00:00:58
Visited 23771 accounts and removed profile media totaling 5.98 GB (DRY RUN)
Wow, I could run this in a cron-job and I might not need to move to S3.
The docs on the command indicate the seven days is days since the account was last looked up via “webfinger”. I think this happens when a post from that user lands on the instance. So this should remove media from users who are not directly followed and who’s posts have not been federated to me in less than 7 days.
I follow less than a 100 people, so I should only need long term storage avatars and header images for them.
My instance has seen a lot of one-off users: people who get federated into my server via a boost or reply, who I very infrequently ever see a second time, if at all!. Each of them brings along a header image and profile picture.
Apparently theres like 23k of them? That seems extremely high.
Run the real purge
mastodon@mastodon:~/live$ bundle exec bin/tootctl media remove --days 7 --prune-profiles
23772/23772 |=====================================================| Time: 00:08:49
Visited 23772 accounts and removed profile media totaling 5.98 GB
Check usage now
mastodon@mastodon:~/live$ bundle exec bin/tootctl media usage
Attachments: 359 MB (1.57 MB local)
Custom emoji: 49 MB (0 Bytes local)
Preview cards: 10.6 MB
Avatars: 243 MB (28.9 KB local)
Headers: 508 MB (0 Bytes local)
Backups: 0 Bytes
Imports: 0 Bytes
Settings: 0 Bytes
I’ve now got 7GB free on my droplet instead of 1.5. Breathing room!