Mastodon's built-in CLI gives you the availability to clean attachments and previews from remote accounts, purging the disk cache. This is fantastic and you couldn't possibly survive with out it.
crontab that runs every 3 hours:
0 */3 * * * /bin/bash /home/mastodon/purge-media.shCode language: Bash (bash)
As of Mastodon 4.1.0, we have new available commands. Here's the content of my
#!/bin/bash # Prune remote accounts that never interacted with a local user RAILS_ENV=production /home/mastodon/live/bin/tootctl accounts prune; # Remove remote statuses that local users never interacted with older than 4 days RAILS_ENV=production /home/mastodon/live/bin/tootctl statuses remove --days 4; # Remove media attachments older than 4 days RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --days 4; # Remove all headers (including people I follow) RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --remove-headers --include-follows --days 0; # Remove link previews older than 4 days RAILS_ENV=production /home/mastodon/live/bin/tootctl preview_cards remove --days 4; # Remove files not linked to any post RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove-orphans;Code language: PHP (php)
⚠️ If you've never run these commands before I'd suggest running them one by one (not in a cronjob) as they might take several hours (or days) to run each. The size of the cached media and database will depend on how many people you follow, how many are on your instance, how many relays you have added to your instance, etc.
Having like 10 relays added to my single-user instance with the bash script above I'm around 30Gb in my Object Storage S3.
Do you have any other tips on how to keep a Mastodon instance lean?
👋 Don't miss the follow up post: Scaling Mastodon: moving media assets to Object Storage