feat(backup): .picpeak portable export (engine-neutral logical snapshot)

First half of the GUI-only backup roundtrip. Adds a self-describing
".picpeak" archive that can be downloaded from one instance and (later)
re-uploaded to another via the web UI only.

- picpeakExportService.createPicpeak(): dumps every table as NDJSON
  (tables introspected at runtime — no hardcoded list, won't rot), plus
  a manifest (format version, app version, DB engine, latest migration,
  per-table row counts + checksums, includePhotos, contains_secrets),
  plus files/ (business-docs + uploads always; original gallery photos
  only when includePhotos). NDJSON is engine-neutral so the target
  rebuilds schema via migrations then loads rows — enabling pg↔pg /
  sqlite↔sqlite and forward-only auto-migrate.
- GET /admin/backup/picpeak/export?includePhotos= streams the file and
  sets X-Picpeak-Contains-Secrets (the file holds plaintext SMTP pass,
  admin hashes, API keys — the UI must warn).
- Purely additive: no existing backup/restore path is touched.

Integration test proves the archive shape, knex-table exclusion, and
row-count/NDJSON consistency (85 tables on the seed schema).
This commit is contained in:
Luca
2026-07-02 19:13:58 +02:00
parent 24c287d051
commit 38b3aef63d
3 changed files with 349 additions and 0 deletions
+27
View File
@@ -131,6 +131,33 @@ router.post('/run', adminAuth, requirePermission('backup.create'), async (req, r
}
});
// Generate + download a portable ".picpeak" export — an engine-neutral logical
// snapshot (DB rows as NDJSON + PDFs/business-docs) that can be re-uploaded to
// another instance via the web UI. `?includePhotos=true` also bundles original
// gallery photos (larger); otherwise the admin re-uploads them per gallery.
//
// SECURITY: the file contains plaintext secrets (SMTP password, admin password
// hashes, API keys). The download UI must warn before offering it. We surface
// the flag as a response header too so the client can double-confirm.
router.get('/picpeak/export', adminAuth, requirePermission('backup.create'), async (req, res) => {
const fsSync = require('fs');
try {
const includePhotos = req.query.includePhotos === 'true' || req.query.includePhotos === '1';
const { createPicpeak } = require('../services/picpeakExportService');
const { filePath } = await createPicpeak({ includePhotos });
const filename = path.basename(filePath);
res.setHeader('X-Picpeak-Contains-Secrets', 'true');
res.download(filePath, filename, (err) => {
// Best-effort cleanup of the temp .picpeak (and its temp dir) after send.
fsSync.rm(path.dirname(filePath), { recursive: true, force: true }, () => {});
if (err) logger.error('[picpeak-export] download failed', { error: err.message });
});
} catch (error) {
logger.error('[picpeak-export] failed to create export', { error: error.message });
if (!res.headersSent) res.status(500).json({ error: 'Failed to create .picpeak export' });
}
});
// Get backup run details
router.get('/runs/:id', adminAuth, requirePermission('backup.view'), async (req, res) => {
try {