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
.update(backupSchedulesTable)
.set({ lastBackupStatus: "in_progress", updatedAt: Date.now() })
.set({ lastBackupStatus: "in_progress", updatedAt: Date.now(), lastBackupError: null })
.where(eq(backupSchedulesTable.id, scheduleId));
const abortController = new AbortController();

View File

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