Backup and Restore
Postgram supports PostgreSQL logical backups via CLI with optional GPG encryption.
What this page covers
Section titled “What this page covers”How to create reliable backups and restore into a fresh database for migration or recovery.
Core workflow
Section titled “Core workflow”- Create an encrypted backup:
export DATABASE_URL=postgres://postgram:postgram@postgres:5432/postgramexport PGM_BACKUP_PASSPHRASE=testpasspgm backup --encrypt --output /tmp/postgram-backups/ --json- Decrypt locally:
gpg --batch --yes --pinentry-mode loopback \ --passphrase "$PGM_BACKUP_PASSPHRASE" \ -o /tmp/postgram-backups/restore.dump \ -d /tmp/postgram-backups/<backup-file>.dump.gpg- Restore with
pg_restoreinto a fresh DB:
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 --encryptis the recommended safety path.- On low-privilege hosts, use the validated
docker composefallback forpg_dumpavailability.