Mastodon cleanup scripts

Comments and improvement suggestions welcomed!

Anything to improve is good! I have been running this script with days 5. All of this may update frequently, so check back.

This script is adapted from Hosting your own Mastodon server.

Currently running unmodified Mastodon v4.1.2 on Ubuntu 20.04.
With 16 users, disk space used averages around 34GB.
All files are in /home/mastodon/maint/


# Once a day cleanup Monday-Sunday 2:45AM CST (7:45 UTC)
45 7 * * * /home/mastodon/maint/ > /home/mastodon/maint/cleanup-daily.log



# This does the heavy lifting and removes locally cached copies of
# media attachments, avatars and headers from other servers
# By default it's set to delete media older than 7 days
# Adjust days with --days, eg --days 3 for a more aggressive setting.
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --days 5
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --prune-profiles --days 5
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --remove-headers --days 5

# New instead of above + --include-follows --dryrun --verbose ***
# RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --attachments --avatars --headers --days 5

# Remove local thumbnails for preview cards (the thumbnail when links are shared, etc)
# The default is 180 days and under 14 days is not recommended as they will not be refetched
RAILS_ENV=production /home/mastodon/live/bin/tootctl preview_cards remove --days 90

# Deletes remote accounts that never interacted with local accounts
# Removes many avatar and header images as part of this
RAILS_ENV=production /home/mastodon/live/bin/tootctl accounts prune

# Removes files that do not belong to existing media attachments
# For example if you attached a file to a post composer but never posted it
# This command and the one after it are slow to run, so I like to keep them for last
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove-orphans

# Remove unreferenced statuses from the database, such as statuses that
# came from relays or from users who are no longer followed by any local accounts,
# and have not been replied to or otherwise interacted with (90 days default)
RAILS_ENV=production /home/mastodon/live/bin/tootctl statuses remove --days 90


*** Note it appears tootctl media remove is going to have an update to flags, re: Issue 23628


Updated periodically – About
Updated periodically – Migrating to
Updated periodically – Introduction to Settler Colonialism
Updated periodically – Decolonization is not a metaphor
Updated periodically – Mvskoke History & Resources

Follow on Mastodon –

This page is subject to content updates/additions. If you think any content should be updated or added, please leave a private comment on Mastodon –