Last active
May 13, 2022 11:50
-
-
Save mkody/1cbac686879ef8f07a188354bb027b5e to your computer and use it in GitHub Desktop.
im-in.space's backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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