eattherich.club

mastodon-snapshot.sh

NAMESPACE=mastodon
Note: this is the same value as the UNIX user and can be used as such.

Ensure the mastodon user is in the snapshot group!

usermod -G snapshot -a $NAMESPACE 

Create /usr/local/bin/$NAMESPACE-snapshot.sh and make it executable. Then follow along with your preferred $EDITOR.

touch /usr/local/bin/$NAMESPACE-snapshot.sh
chmod +x /usr/local/bin/$NAMESPACE-snapshot.sh

Use pg_dump(1) to create a .sql dump of the mastodon_production database:

pg_dump $NAMESPACE_production > /tmp/snapshot/$NAMESPACE/$NAMESPACE_production.sql

Collect the production environment file. This has application secrets which if lost will break 2FA:

cp $HOME/live/.env.production /tmp/snapshot/$NAMESPACE/

Collect relevant system files, specifically the user-uploaded ones:

cp -r $HOME/live/public/system/{accounts,media_attachments,site_uploads} /tmp/snapshot/$NAMESPACE/

Custom emoji files are stored here as well but using tootctl(1) is preferred for this.

https://docs.joinmastodon.org/admin/tootctl/#emoji
tootctl emoji export > /tmp/snapshot/$NAMESPACE/emoji.tar.gz
Note: you'll likely have to setup rbenv and the path to tootctl(1).

Collect the redis dump. This file is regularly created by redis itself and only needs to be copied. The mastodon user will need to be in the redis group:

cp /var/lib/redis/dump.rdb /tmp/snapshot/$NAMESPACE/

Not a big deal if it's lost either, just has the sidekiq queues and scheduled retries of previously failed jobs. The home and list feeds are also stored here but may be recreated with tootctl(1)

Verify the script works by running it and checking the resulting archive in /usr/local/share/snapshots.

sudo -u mastodon mastodon-snapshot.sh 

See the top-level snapshot guide for information on how to create the $NAMESPACE-snapshot.{service,timer}.