fix(backup): only keep last line of stdout in memory

This commit is contained in:
Nicolas Meienberger
2025-11-08 23:41:29 +01:00
parent 5f620b4c45
commit 3e80850396
2 changed files with 7 additions and 8 deletions

View File

@@ -197,7 +197,7 @@ const executeBackup = async (scheduleId: number, manual = false) => {
await db await db
.update(backupSchedulesTable) .update(backupSchedulesTable)
.set({ lastBackupStatus: "in_progress", updatedAt: Date.now() }) .set({ lastBackupStatus: "in_progress", updatedAt: Date.now(), lastBackupError: null })
.where(eq(backupSchedulesTable.id, scheduleId)); .where(eq(backupSchedulesTable.id, scheduleId));
const abortController = new AbortController(); const abortController = new AbortController();

View File

@@ -156,14 +156,14 @@ const backup = async (
}); });
let stdout = ""; let stdout = "";
let stderr = "";
child.stdout.on("data", (data) => { child.stdout.on("data", (data) => {
stdout += data.toString(); stdout = data.toString();
logger.info(data.toString());
}); });
child.stderr.on("data", (data) => { child.stderr.on("data", (data) => {
stderr += data.toString(); logger.error(data.toString());
}); });
child.on("error", async (error) => { child.on("error", async (error) => {
@@ -186,14 +186,13 @@ const backup = async (
} }
if (code !== 0) { if (code !== 0) {
logger.error(`Restic backup failed with exit code ${code}: ${stderr}`); logger.error(`Restic backup failed with exit code ${code}`);
reject(new Error(`Restic backup failed: ${stderr}`)); reject(new Error(`Restic backup failed`));
return; return;
} }
try { try {
const outputLines = stdout.trim().split("\n"); const lastLine = stdout.trim();
const lastLine = outputLines[outputLines.length - 1];
const resSummary = JSON.parse(lastLine ?? "{}"); const resSummary = JSON.parse(lastLine ?? "{}");
const result = backupOutputSchema(resSummary); const result = backupOutputSchema(resSummary);