Skip to content

Instantly share code, notes, and snippets.

@mkody
Last active May 13, 2022 11:50
Show Gist options
  • Save mkody/1cbac686879ef8f07a188354bb027b5e to your computer and use it in GitHub Desktop.
Save mkody/1cbac686879ef8f07a188354bb027b5e to your computer and use it in GitHub Desktop.
im-in.space's backup script
#!/bin/bash
# Welcome to im-in.space's backup script!
PIDFILE="/tmp/backup.pid"
BUCKETNAME="[your bucket name here]"
if [ -f "$PIDFILE" ]; then
echo "Already running"
exit 1
fi
echo "STARTING BACKUP"
date
echo "=========="
echo $$ > "$PIDFILE"
mkdir -p /tmp/backups/mastodon
chmod 777 /tmp/backups/mastodon
set -e
# ==== Mastodon
echo "[Mastodon] => Dumping DB"
su - mastodon -c "pg_dump -Fc -b mastodon_production -f /tmp/backups/mastodon/mastodon_production.dump"
echo "[Mastodon] => Copying .env.production and Redis DB"
cp /home/mastodon/live/.env.production /tmp/backups/mastodon/.env.production
cp /var/lib/redis/dump.rdb /tmp/backups/mastodon/dump.rdb
# ==== Sync
echo "[Sync] => Syncing DBs and configs"
/usr/local/bin/b2 sync --noProgress --keepDays 7 --replaceNewer \
/tmp/backups/ b2://$BUCKETNAME/backups/
echo "[Sync] => Syncing Mastodon uploads"
/usr/local/bin/b2 sync --noProgress --delete --compareVersions none \
--excludeDirRegex '.*preview_cards' --excludeDirRegex '.*cache' \
/opt/system/ b2://$BUCKETNAME/data/mastodon/system/
rm -r /tmp/backups/mastodon
echo "=========="
echo "BACKUP DONE"
date
rm -f "$PIDFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment