1
mirror of https://github.com/jakejarvis/mastodon-utils.git synced 2025-04-26 03:25:22 -04:00

add simple backup script

This commit is contained in:
Jake Jarvis 2022-12-08 09:51:20 -05:00
parent 6fee7c0298
commit 1fb34a86b4
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
2 changed files with 42 additions and 2 deletions

42
scripts/backup.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
# exit when any step fails
set -euo pipefail
# default paths
MASTODON_ROOT=/home/mastodon
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]
then
echo "⚠️ Mastodon is currently running."
echo "We'll start the backup anyways, but if it's a critical one, stop all Mastodon"
echo "services first with 'systemctl stop mastodon-*' and run this again."
echo ""
fi
if [ ! -d "$MASTODON_ROOT/backups" ]
then
sudo mkdir -p "$MASTODON_ROOT/backups"
sudo chown -R mastodon:mastodon "$MASTODON_ROOT/backups"
fi
TEMP_DIR=$(sudo -u mastodon mktemp -d)
echo "Backing up Postgres..."
sudo -u mastodon pg_dump -Fc mastodon_production -f "$TEMP_DIR/postgres.dump"
echo "Backing up Redis..."
sudo cp /var/lib/redis/dump.rdb "$TEMP_DIR/redis.rdb"
echo "Backing up secrets..."
sudo cp "$MASTODON_ROOT/live/.env.production" "$TEMP_DIR/env.production"
echo "Compressing..."
ARCHIVE_DEST="$MASTODON_ROOT/backups/$(date "+%Y.%m.%d-%H.%M.%S").tar.gz"
sudo tar --owner=0 --group=0 -czvf "$ARCHIVE_DEST" -C "$TEMP_DIR" .
sudo chown mastodon:mastodon "$ARCHIVE_DEST"
sudo rm -rf --preserve-root "$TEMP_DIR"
echo "Saved to $ARCHIVE_DEST"
echo "🎉 done! (keep this archive safe!)"

View File

@ -10,5 +10,3 @@ set -e
tootctl media remove --days 7
tootctl preview_cards remove --days 90
curl -X GET 'https://betteruptime.com/api/v1/heartbeat/EZYUHRmbatzh4tBfTvzX22go'