Skip to content

Instantly share code, notes, and snippets.

@ThomasLeister
Created February 21, 2019 19:07
Show Gist options
  • Save ThomasLeister/aa1c500eedeff19551f3bb8238533854 to your computer and use it in GitHub Desktop.
Save ThomasLeister/aa1c500eedeff19551f3bb8238533854 to your computer and use it in GitHub Desktop.
How to automatically remove cached media files older that 7 days from your Mastodon instance
This is how to automatically delete cached image previews from your Mastodon instance if they are older than 7 days.
Log in as your "mastodon" User or log in as root and then change to the "mastodon" user, who runs Mastodon:
# su - mastodon
Open crontab:
$ crontab -e
... and add these lines to your crontab:
SHELL=/bin/bash
PATH=/home/mastodon/.rbenv/shims:/home/mastodon/.rbenv/bin:/usr/local/bin:/usr/bin:/bin
###
### Mastodon cronjobs for media cache purging
###
RAILS_ENV=production
@daily cd /home/mastodon/live && bin/tootctl media remove
Edit the editor. The new Cron Job will be accepted.
This script assumes that your Mastodon Sourcecode lives in /home/mastodon/live (as suggested by the official setup guide).
@redfast00
Copy link

If you're running Mastodon in a docker container, run docker exec -it mastodon_web_1 tootctl media remove --days=7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment