diff --git a/lib/backup.ts b/lib/backup.ts index 2356df4..b05f59a 100644 --- a/lib/backup.ts +++ b/lib/backup.ts @@ -14,7 +14,10 @@ async function runBackup(): Promise { return; } const [, sshHost, remotePath] = match; - const keyPath = process.env.BACKUP_SSH_KEY_PATH || '/app/.ssh/id_rsa'; + const rawKeyPath = process.env.BACKUP_SSH_KEY_PATH || '/app/.ssh/id_rsa'; + const keyPath = rawKeyPath.startsWith('~') + ? rawKeyPath.replace('~', process.env.HOME || '/root') + : rawKeyPath; const ts = new Date().toISOString().replace('T', '_').replace(/:/g, '-').slice(0, 19); const filename = `sternwarte_${ts}.sql.gz`; @@ -48,6 +51,10 @@ async function runBackup(): Promise { dump.stderr.on('data', (d: Buffer) => { dumpErr += d.toString(); }); ssh.stderr.on('data', (d: Buffer) => { sshErr += d.toString(); }); + dump.on('error', reject); + gzip.on('error', reject); + ssh.on('error', reject); + dump.on('close', (code) => { if (code !== 0) gzip.stdin.end(); }); gzip.on('close', () => ssh.stdin.end()); @@ -66,6 +73,7 @@ async function runBackup(): Promise { ...sshOpts, sshHost, `find ${remotePath} -name 'sternwarte_*.sql.gz' -mtime +30 -delete`, ]); + ssh.on('error', (e) => { console.error('[backup] Cleanup spawn-Fehler:', e.message); resolve(); }); ssh.on('close', (code) => { if (code !== 0) console.error('[backup] Cleanup fehlgeschlagen (exit ' + code + ')'); resolve();