mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
fix(backup): only keep last line of stdout in memory
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user