A bash script to backup mastodon server data, when running it with docker compose
Find a file
2025-12-10 18:26:14 -05:00
backup.sh Initial Commit 2025-12-10 18:24:44 -05:00
README.md Adding markdown extension to README 2025-12-10 18:26:14 -05:00

Mastodon backup.sh

This is a shell script that can be dropped into folder for a mastodon server, running inside of docker compose.

Setup

Before you use this script, you will need to fill out a few variables at the top of the script.

  • pod: the name for the folder that the script is in, and that docker compose uses for the machine names

You'll also need to create the following directories:

  • backups: the folder where all of the local backups will be stored
    • backups/daily: used for daily backups, stores 7 backups, or one week
    • backups/manual: used for manual backups, whenever you run the script
    • backups/monthly: used for monthly backups, stores 12 backups, or one year
    • backups/weekly: used for weekly backups, stores 5 backups, or one month
    • backups/working: used as the working directory for current operation

Running

Add to Crontab

Add the following line to your crontab, replacing /home/developer/containers/mastodon/pandapla.net with the location of your container data.

0 4 * * * cd /home/developer/containers/mastodon/pandapla.net && ./backup.sh

Running Manually

If you'd like to make a manual backup, just go to the directory and run the script with ./backup.sh. When run manually, the backup is stored in the backups/manual folder, and are kept until you remove them.