Bash scripts for backup/restore of Mastodon
Go to file
DecaTec 73a738b7b4 Added gitignore 2023-03-02 22:22:59 +00:00
.gitignore Added gitignore 2023-03-02 22:22:59 +00:00
LICENSE Initial commit 2022-11-13 00:10:22 +01:00 Delete temporary Redis dump 2022-11-14 12:23:01 +01:00
MastodonBackupRestore.conf.sample Init 2022-11-14 12:12:52 +01:00 Typo in path 2022-11-14 12:25:29 +01:00 Readme 2022-11-14 13:33:29 +01:00 Init 2022-11-14 12:12:52 +01:00



This repository contains bash scripts for backup/restore of Mastodon.

General information

For a complete backup of any Mastodon instance, you'll have to backup these items:

  • The PostgreSQL database
  • The configuration file .env.production
  • User uploaded data (usually /home/mastodon/live/public/system)
  • The Redis database (optional)

The scripts take care of these items to backup automatically. For the ease of use, the whole Mastodon directory (/home/mastodon/live) is backed up.


  • pigz ( when using backup compression. If not installed already, it can be installed with apt install pigz (Debian/Ubuntu). If not available, you can use another compression algorithm (e.g. gzip)

Important notes about using the scripts

  • After cloning or downloading the scripts, these need to be set up by running the script (see below).
  • If you do not want to use the automated setup, you can also use the file MastodonBackupRestore.conf.sample as a starting point. Just make sure to rename the file when you are done (cp MastodonBackupRestore.conf.sample MastodonBackupRestore.conf)
  • The configuration file MastodonBackupRestore.conf has to be located in the same directory as the scripts for backup/restore.


  1. Clone the repository: git clone
  2. Set permissions:
    • chown -R root Mastodon-Backup-Restore
    • cd Mastodon-Backup-Restore
    • chmod +x *.sh
  3. Call the (interactive) script for automated setup (this will create a file MastodonBackupRestore.conf containing the desired configuration): ./
  4. Important: Check this configuration file if everything was set up correctly (see TODO in the configuration files's comments)
  5. Start using the scripts: See sections Backup and Restore below

Keep in mind that the configuration file MastodonBackupRestore.conf hast to be located in the same directory as the scripts for backup/restore, otherwise the configuration will not be found.


In order to create a backup, simply call the script on your Mastodon machine. If this script is called without parameter, the backup is saved in a directory with the current time stamp in your main backup directory: As an example, this would be /media/hdd/mastodon_backup/20221012_132703. The backup script can also be called with a parameter specifiying the main backup directory, e.g. ./ /media/hdd/mastodon_backup. In this case, the directory specified will be used as main backup directory.

You can also call this script by cron. Example (at 2am every night, with log output):

0 2 * * * /path/to/scripts/Mastodon-Backup-Restore/ > /path/to/logs/Mastodon-Backup-$(date +\%Y\%m\%d\%H\%M\%S).log 2>&1


For restore, just call This script expects at least one parameter specifying the name of the backup to be restored. In our example, this would be 20221012_132703 (the time stamp of the backup created before). The full command for a restore would be ./ 20221012_132703. You can also specify the main backup directory with a second parameter, e.g. ./ 20221012_132703 /media/hdd/mastodon_backup.