feat: automatische geplante Backups mit Rotation

Phase 1.3 - Automatische Backups:
- Cron-basierter Scheduler (Standard: täglich 2 Uhr)
- Konfigurierbar über .env (Zeitplan, Verzeichnis, Anzahl)
- Automatische Rotation: behält nur letzte N Backups (Standard: 7)
- UI in Settings → Backup: Status-Anzeige und manueller Trigger
- Tests: 7 erfolgreiche Tests für Scheduler-Funktionalität

Neue Umgebungsvariablen:
- BACKUP_ENABLED (Standard: true)
- BACKUP_SCHEDULE (Standard: 0 2 * * *)
- BACKUP_DIR (Standard: ./backups)
- BACKUP_KEEP (Standard: 7)
- TZ (für Zeitzone)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ulas Kalayci
2026-05-04 07:02:38 +02:00
parent 99a2280c02
commit 9b29d1847c
11 changed files with 484 additions and 3 deletions
+13
View File
@@ -11,6 +11,7 @@ import fs from 'node:fs/promises';
import { backupToFile, currentVersion, restoreFromFile } from '../db.js';
import { requireAdmin } from '../auth.js';
import { createLogger } from '../logger.js';
import { getStatus as getSchedulerStatus, triggerBackup } from '../services/backup-scheduler.js';
const router = express.Router();
const log = createLogger('Backup');
@@ -22,10 +23,12 @@ function backupFileName() {
}
router.get('/status', requireAdmin, (req, res) => {
const schedulerStatus = getSchedulerStatus();
res.json({
data: {
schema_version: currentVersion(),
restore_upload_limit: RESTORE_LIMIT,
scheduler: schedulerStatus,
},
});
});
@@ -87,6 +90,16 @@ router.post(
}
);
router.post('/trigger', requireAdmin, async (req, res) => {
try {
const result = await triggerBackup();
res.json({ data: result });
} catch (err) {
log.error('Manual backup trigger failed:', err);
res.status(500).json({ error: 'Backup trigger failed.', code: 500 });
}
});
router.use((err, req, res, next) => {
if (err?.type === 'entity.too.large') {
return res.status(413).json({ error: `Backup file is too large. Maximum upload size is ${RESTORE_LIMIT}.`, code: 413 });