Skip to content

Instantly share code, notes, and snippets.

@ixs
Created November 10, 2022 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ixs/c8a0b7895b512ac838f0fd5d38ae05b7 to your computer and use it in GitHub Desktop.
Save ixs/c8a0b7895b512ac838f0fd5d38ae05b7 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Dockerized Mastodon Database Backup Script
#
DIR=$(date +%d-%m-%y)
DEST="./db_backups/$DIR"
mkdir -p "$DEST"
MASTODON_ENV=$(basename "${PWD}")
. database.env
HOST=$(docker inspect "${MASTODON_ENV}-postgresql-1" | jq -r ".[].NetworkSettings.Networks[\"${MASTODON_ENV}_internal_network\"].IPAddress")
docker-compose run --env PGPASSWORD="$POSTGRES_PASSWORD" --rm postgresql \
pg_dump \
--inserts \
--column-inserts \
--username="$POSTGRES_USER" \
--host="$HOST" \
--port="$DB_PORT" "$POSTGRES_DB" | gzip -c -9 > "${DEST}/dbbackup.sql.gz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment