Being too occupied with the work for previous two months left me with absolutely no time for server maintenance. Especially the kind of maintenance that needs some thought or research before being being done properly.
One of the things that got neglected this way is the VPS free space monitoring. In case some application eats up too much space, it can lead to problems. I mean, with most VPS providers, an additional space is usually just a clicks away, but unless it is a business-critical decision, it is better avoided. Especially when the need for a most spacious storage is due to some data that are potentially worthless, i.e. cache data.
Checking the server
With some space time today I checked the server where my Mastodon instance is residing and found out that the mastodon folder is taking a whopping 92 GB of storage! I have almost fell down from the chair. I have set it up just 4 months earlier. How could it grow so large? I have not even been using it so much since. When I was running Pleroma before, it did manage to grow to around 16 GB over eight months, so clearly there was something strange happening.
Checking the bulk of the size led me to the folder
public/system/cache/attachments with the size of 65 GB. Learning more I
was led to believe that the server caches all the federated media all the
users (in this case just me) on the instance follow. It looks like the
server keeps these media attachments as a cache indefinitely, which cause
Tootctl to the rescue!
The simplest solution I have found is to simply remove the attachments via
tootctl media remove
To prevent re-downloading every media attachment, making the user experience snappier and saving some network bandwidth, we can prune only media attachments older than, let's say a week:
tootctl media remove --days=7
I am running my Mastodon instance as a Docker container, so the command need a little more tweaking:
docker exec -it mastodon_web_1 tootctl media remove --days=7
On your setup, the
mastodon_web_1 could be something different, consult
docker ps for instance. The command above freed up over 60 GB on my
machine without any obvious errors.
There is more to prune potentially safely with
docker exec -it mastodon_web_1 tootctl preview_cards remove --days=7
Although the savings here were pretty tiny, just over 1 GB. Note that both these tasks could be set-up as a cron job, one potential example is in the links below.