For my Mastodon instance, I use Cloudflare R2; mainly for two reasons:
- Storage was growing quickly (~80Gb during its peak); I am hosting my instance on a RPi4 (w/ 8Gb RAM) and the SSD was filling up rapidly,
- I wanted something speedy to serve (big and cacheable) content (i.e. a CDN).
While I didn’t care much about storage any more, I still wanted to make sure it was kept in check, also for two reasons:
- Mastodon downloads a copy of all content it says on the Fediverse, and keeps it until purged. So every instance has all the content from other instances. This could theoretically lead to you hosting illegal content and getting in trouble for it,
- Cloudflare used to be my employer, and I have free access to R2. However, there’s always a risk they’ll disable my employee benefits one day and get me to pay for my used storage.
I run my Mastodon in a Docker instance, so your commands may vary (basically tootctl X Y
is what matters). I run most of these commands once a week using systemd (except the media remover, that runs every day).
This will clear:
- accounts (you never interacted with)
- header files (big picture every account can upload)
- profile pictures
- link preview cards
- orphaned media (uploaded media but not posted)
- media (from other accounts)
- statuses (from other accounts)
- and as a bonus include updating Elasticsearch indices (which sound run every once in a while to optimise search)
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl accounts prune
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl media remove --remove-headers --days 15
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl media remove--prune-profiles --days 30
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl preview_cards remove --days 15
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl media remove-orphans
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl media remove --days 30
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl statuses remove --days 30
/usr/bin/docker compose -f /srv/mastodon/docker-compose.yml run --rm shell tootctl search deploy
Note that you should play with the --days X
to find something that works for you (i.e.: you can scroll back in the history and still see posts/media, but not overload your storage).
I’ve included all the systemd files that’s needed here. Again, will only work in a Docker environment using the same paths as me.
The systemd files will need to be activated using something similar to this (but again, don’t blindly run these commands as it’ll likely not work):
cp *.service *.timer /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now *.timer
systemctl list-timers | grep masto
Oh, and this is not specific to R2. This works even when storing everything locally.
I’ve written before on how to use Cloudflare CDN to protect/speed up your instance.
Leave a Reply…