Platform backup & restore
Run and verify platform MongoDB backups from Super Admin, then restore with the server runbook (no one-click mongorestore).
Technical Guides · Backup & DR
Ścieżka: Super Admin → Backup & DR
Definicja
Super Admin → Backups → [Run full | Run hourly | Verify | Sync media] → Restore tab prepares plan → CLI restore-mongodb.sh
Platform Backup & DR dumps MongoDB (hourly + daily full), optional config/ops snapshots, and optional R2→secondary media sync. Super Admin can trigger and verify runs. Full database restore is intentionally CLI/runbook-only — the UI prepares and verifies a plan but does not execute in-app mongorestore against production.
Compatibility
- Super Admin role required for UI triggers.
- BACKUP_ENABLED=true (default) and MongoDB Database Tools (mongodump / mongorestore) on the API host.
- BACKUP_DIR must be writable by the API process user (see setup-backup-dir.sh).
- Off-site dump mirror: BACKUP_REMOTE_*. Media secondary: BACKUP_MEDIA_SYNC_ENABLED + secondary bucket credentials.
- Encryption is not implemented — do not set BACKUP_ENCRYPT expecting it to work.
Canonical runbook: docs/BACKUP_DISASTER_RECOVERY.md (backend). Frontend mirror: docs/technical/backup-disaster-recovery.md.
Path & jobs
Super Admin → /super-admin/backups Overview / History / Restore / DR tabs POST /platform/admin/backups/run POST /platform/admin/backups/run-hourly POST /platform/admin/backups/verify POST /platform/admin/backups/sync-media Cron (Asia/Dhaka): :00 hourly mongodump 02:00 full daily + store snapshots + trash purge + verify 03:00 media sync (if enabled) 04:00 config/ops snapshot
Retention defaults: 48 hourly · 30 daily · 12 weekly · 12 monthly (see backup.config).
Behavior
- Successful runs appear in History with path, size, and status.
- Verify checks dump integrity (size + optional staging dry-run when configured).
- Restore tab: select a successful run → optional verify → optional safety full backup → checklist → plan ready.
- Applying the restore uses ./scripts/restore-mongodb.sh on the server (type RESTORE to confirm).
- JSON-only fallback dumps (when mongodump is missing) are not mongorestore-compatible — fix Tools install first.
How to run a platform backup
- Confirm BACKUP_DIR exists and is owned by the API user (setup-backup-dir.sh if EACCES).
- Open Super Admin → Backup & DR.
- Use Hourly now for a quick continuity dump, or Run full for daily-style backup.
- Open History and confirm status = success and path is set.
- Click Verify (latest or selected run) and confirm ok.
- If media DR is configured, run Sync media (R2 → secondary).
- Optionally confirm off-site remote sync is configured for 3-2-1.
Prepare a restore (UI)
- Open Backup & DR → Restore.
- Choose source: History (recommended), and select a successful run.
- Keep Verify on; enable Safety backup unless you already have a fresh dump.
- Review mode (full / database / media / config) — UI documents intent; CLI applies DB restore.
- Click prepare — wait until plan is ready.
- Enable Maintenance mode in Platform Settings before applying a production restore.
- Follow the Disaster Recovery tab / runbook on the server — do not skip staging tests.
Apply restore (CLI runbook)
./scripts/restore-mongodb.sh /var/backups/bonikbiz/daily/YYYYMMDD_HHMMSS npm run backup:verify
- SSH to the API host (or staging host for a test restore).
- For staging: set STAGING_MONGODB_URI / restore target and practice first.
- Run: ./scripts/restore-mongodb.sh /var/backups/bonikbiz/daily/<stamp>
- Type RESTORE when prompted.
- For single collection: pass --ns=db.collection or use mongorestore --nsInclude.
- If images were lost from primary R2, sync secondary → primary per runbook.
- Restart API/PM2, reload Nginx, smoke-test products, orders, uploads, checkout.
- Record actual RTO and issues in the ops wiki.
Examples
Example — permission fix: Super Admin shows EACCES on /var/backups/bonikbiz → run setup-backup-dir.sh as root → Hourly now succeeds.
Example — bad deploy rollback: prefer Git/PM2 rollback; use DB restore only if data was corrupted.
Example — monthly drill: restore latest daily dump into staging Mongo; count users/stores/products/orders.
Common errors
- EACCES mkdir BACKUP_DIR — fix ownership with setup-backup-dir.sh; never leave a root-only path.
- mongodump unavailable — install MongoDB Database Tools; avoid relying on JSON fallback.
- Verify failed — do not restore that run; re-run backup and inspect disk space.
- Restore plan ready but DB unchanged — you still need the CLI script on the server.
- Media still missing after DB restore — configure/run secondary media sync.