Skip to content

Instantly share code, notes, and snippets.

@hughrun
Created July 29, 2022 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughrun/0d545740c706bd5973f6060868919677 to your computer and use it in GitHub Desktop.
Save hughrun/0d545740c706bd5973f6060868919677 to your computer and use it in GitHub Desktop.
crontab for pruning unused media from mastodon servers
# This should be set in the `mastodon` user's crontab, not `root`, otherwise ruby/rails may not work correctly.
# Make sure your environment settings are correct
# You need to set PATH because otherwise cron uses root's PATH
RAILS_ENV=production
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/mastodon/.rbenv/shims
# This should remove media files cached from remote servers older than 7 days
@daily cd /home/mastodon/live && bin/tootctl media remove --days=7
# This removes files that have become detached from posts e.g. when deleted by ephemetoot
@daily cd /home/mastodon/live && bin/tootctl media remove-orphans
# This should reset counters for total tweets etc when they get out of sync
@weekly cd /home/mastodon/live && bin/tootctl cache recount accounts
# This removes preview cards from links etc on toots older than 180 days
@weekly cd /home/mastodon/live && bin/tootctl preview_cards remove
# 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.
# Only applies to posts older than 90 days
@weekly cd /home/mastodon/live && bin/tootctl statuses remove
# Remove remote accounts that no longer exist. This takes quite a while as it pings every account to check.
@weekly cd /home/mastodon/live && bin/tootctl accounts cull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment