Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Backup and Restore

Postgram supports PostgreSQL logical backups via CLI with optional GPG encryption.

How to create reliable backups and restore into a fresh database for migration or recovery.

  1. Create an encrypted backup:
Terminal window
export DATABASE_URL=postgres://postgram:postgram@postgres:5432/postgram
export PGM_BACKUP_PASSPHRASE=testpass
pgm backup --encrypt --output /tmp/postgram-backups/ --json
  1. Decrypt locally:
Terminal window
gpg --batch --yes --pinentry-mode loopback \
--passphrase "$PGM_BACKUP_PASSPHRASE" \
-o /tmp/postgram-backups/restore.dump \
-d /tmp/postgram-backups/<backup-file>.dump.gpg
  1. Restore with pg_restore into a fresh DB:
Terminal window
docker compose exec -T postgres sh -lc "cat - > /tmp/restore.dump" \
< /tmp/postgram-backups/restore.dump
docker compose exec -T postgres sh -lc \
"createdb -U postgram postgram_restore; \
pg_restore -U postgram -d postgram_restore /tmp/restore.dump;"
  • Encrypted backups use PGM_BACKUP_PASSPHRASE.
  • pgm backup --encrypt is the recommended safety path.
  • On low-privilege hosts, use the validated docker compose fallback for pg_dump availability.