Backups & Upgrades
This guide is for operators managing backups, upgrades, and disaster recovery.
Recommended Backup Schedule
Section titled “Recommended Backup Schedule”- PostgreSQL (
pg_dump): Nightly compressed custom-format dump (-Fc), plus a pre-upgrade snapshot. - MinIO data directory: Nightly incremental sync (
rsyncorrobocopy) of/var/lib/minio/data(or./.minio-datain development). .envsecrets: Back up.envsecurely (especiallyTOKEN_ENCRYPTION_KEY,SESSION_SECRET, andCSRF_SECRET).
Backup & Restore Commands
Section titled “Backup & Restore Commands”pg_dump -Fc -U postgres patchwork > patchwork-$(Get-Date -Format yyyy-MM-dd).dump# Restore:pg_restore -d patchwork --clean --if-exists -U postgres patchwork-YYYY-MM-DD.dumpsudo -u postgres pg_dump -Fc patchwork > /var/backups/patchwork-$(date +%F).dumpsudo rsync -a --delete /var/lib/minio/data/ /var/backups/minio-data/
# Restore:sudo -u postgres pg_restore -d patchwork --clean --if-exists /var/backups/patchwork-YYYY-MM-DD.dumpUpgrade Procedure
Section titled “Upgrade Procedure”- Back up PostgreSQL and
.env. - Pull the new release and install dependencies:
Terminal window npm cinpm run db:migratenpm run build - Restart Patchwork (
sudo systemctl restart patchwork.serviceon Linux, ornpm run stopthennpm run start).
Disaster Recovery
Section titled “Disaster Recovery”- Provision PostgreSQL 16+ and restore your latest
.dumpwithpg_restore. - Restore the MinIO data directory before starting MinIO.
- Restore
.envwith restricted permissions (chmod 600 .envon Linux;icaclson Windows). - Run
node scripts/setup.mjs --checkand verify/api/health.
Related Pages
Section titled “Related Pages”Easy Mode Backups
Section titled “Easy Mode Backups”In Easy mode, all persistent state lives in .env, ./data/postgres/, and ./data/minio/:
- While Patchwork is running (
npm run start), dump PostgreSQL using the bundledpg_dump(orpsql) fromnode_modules/@embedded-postgres/*/native/bin/pg_dumpagainstDATABASE_URLin.env. - Stop the stack (
npm run stop) and copy./data/minio/and.envto a safe backup directory. - Running
npm run setup -- --action=resetalso offers an automaticpg_dump+./data/miniobackup into./backups/before wiping data.
Moving from Easy Mode to Advanced Mode
Section titled “Moving from Easy Mode to Advanced Mode”- Dump the Easy-mode database while running:
pg_dump "<easy-DATABASE_URL>" > patchwork-backup.sql - Stop the Easy-mode supervisor (
npm run stop). - Provision your external PostgreSQL 16+ database and restore:
psql "<advanced-DATABASE_URL>" < patchwork-backup.sql - Copy
./data/minio/to your external MinIO data directory (or point your external MinIO server at the copied directory). - Update
.env(PATCHWORK_INSTALL_MODE=advanced,DATABASE_URL,S3_ENDPOINT,MINIO_PUBLIC_URL,S3_ACCESS_KEY,S3_SECRET_KEY), then start withnpm run start.