Skip to content

Instantly share code, notes, and snippets.

@ktwrd
Created December 19, 2022 05:33
Show Gist options
  • Save ktwrd/7c612de69f3298cbf072e2eeaefd3ac9 to your computer and use it in GitHub Desktop.
Save ktwrd/7c612de69f3298cbf072e2eeaefd3ac9 to your computer and use it in GitHub Desktop.
Backup PostgreSQL database running with Docker
#!/bin/bash
TIMESTAMP=$(date +"%Y%m%d_%H%M%s")
FILENAME="/var/lib/postgresql/data-backup/$TIMESTAMP.bak"
_ROLE="postgres"
_ENCODING="UTF8"
_DBNAME="mastodon"
docker exec -it mastodon_db_1 \
pg_dump --username "postgres" \
--no-password \
--file "$FILENAME" \
--role "$_ROLE" \
--format=c \
--blobs \
--compress "3" \
--section=pre-data \
--section=data \
--section=post-data \
--encoding "$_ENCODING" \
"$_DBNAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment