kurucu / mastodon-backup

Backup your essential Mastodon files with rsync!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mastodon-backup: Backup your essential Mastodon files using rsync!

A small package to of scripts and a cronjob to create rsync backups for your mastodon instance.

This set of scripts was created to automate some of the basic maintenance that I would normally use to cleanup and make backups of my mastodon instance, based on HasHooves' version for S3.

Prerequisites

These scripts assume that you have access to an rsync-enabled account, with snapshots enabled.

As such, the files will not be timestamped or rotated - they will just be periodically copied to the destination. You can browse your snapshots to recover from an earlier point in time.

Install these scripts

On your Mastodon server, log on and move to /opt (or your preferred location) and clone this repo

sudo su
cd /opt
git clone https://github.com/kurucu/mastodon-backup.git
cd mastodon-backup

Configure the credentials and details

  • Install rsync on the server, if you don't already have it
  • Place a copy of your Mastodon instance root public key in ~/.ssh/authorized_keys on the rsync server
  • Copy example_config.sh to config/config.sh, and then fill it out with your details
cp example_config.sh config/config.sh
nano config/config.sh

Update, as a minimum, the rsync_destination variable, and then press ctrl-o to save and ctrl-x to exit.

Prepare the script files

  • Set the two files as executable:
chmod +x backup.sh
chmod +x config/config.sh

Cronjobs

Setting up automated backups

Add this line to the crontab for your root user, to run the backup daily and to generate a log.

0 3 * * * /opt/mastodon-backup/backup.sh > /opt/mastodon-backup/logs/backup.log 2>&1

This, optional, one restarts your server weekly at midnight on a Sunday.

0 0 * * 0 /sbin/shutdown -r now

Note: The 3 in the first one is for 3am. Assuming the time on your server is UTC, you may want to adjust this for where you are. For example, mine runs at 17 (i.e. 5pm), which is around 3am in Australia/Melbourne, depending on the time of year. You can use timedatectl to check the time and date on your server.

Automatic media cleanup

If you have followed the mastodon installation instructions, you have two cron jobs running already. One removes old media, and the other removes old preview cards.

Ensure these are installed now.

Restart Cron

  • After making changes to crontab, restart the cron service:
sudo service cron restart

About

Backup your essential Mastodon files with rsync!

License:MIT License


Languages

Language:Shell 100.0%