|
||
---|---|---|
.gitignore | ||
LICENSE | ||
MastodonBackup.sh | ||
MastodonBackupRestore.conf.sample | ||
MastodonRestore.sh | ||
README.md | ||
setup.sh |
README.md
Mastodon-Backup-Restore
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.
Requirements
- pigz (https://zlib.net/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
setup.sh
(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.
Setup
- Clone the repository:
git clone https://codeberg.org/DecaTec/Mastodon-Backup-Restore.git
- Set permissions:
chown -R root Mastodon-Backup-Restore
cd Mastodon-Backup-Restore
chmod +x *.sh
- Call the (interactive) script for automated setup (this will create a file
MastodonBackupRestore.conf
containing the desired configuration):./setup.sh
- Important: Check this configuration file if everything was set up correctly (see TODO in the configuration files's comments)
- 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.
Backup
In order to create a backup, simply call the script MastodonBackup.sh 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. ./MastodonBackup.sh /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/MastodonBackup.sh > /path/to/logs/Mastodon-Backup-$(date +\%Y\%m\%d\%H\%M\%S).log 2>&1
Restore
For restore, just call MastodonRestore.sh. 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 ./MastodonRestore.sh 20221012_132703. You can also specify the main backup directory with a second parameter, e.g. ./MastodonRestore.sh 20221012_132703 /media/hdd/mastodon_backup.