diff --git a/app/server/modules/backups/backups.service.ts b/app/server/modules/backups/backups.service.ts index 98ad981c..a9672758 100644 --- a/app/server/modules/backups/backups.service.ts +++ b/app/server/modules/backups/backups.service.ts @@ -425,15 +425,6 @@ const stopBackup = async (scheduleId: number) => { throw new NotFoundError("Backup schedule not found"); } - await db - .update(backupSchedulesTable) - .set({ - lastBackupStatus: "error", - lastBackupError: "Backup was stopped by user", - updatedAt: Date.now(), - }) - .where(eq(backupSchedulesTable.id, scheduleId)); - const abortController = runningBackups.get(scheduleId); if (!abortController) { throw new ConflictError("No backup is currently running for this schedule"); @@ -442,6 +433,15 @@ const stopBackup = async (scheduleId: number) => { logger.info(`Stopping backup for schedule ${scheduleId}`); abortController.abort(); + + await db + .update(backupSchedulesTable) + .set({ + lastBackupStatus: "warning", + lastBackupError: "Backup was stopped by user", + updatedAt: Date.now(), + }) + .where(eq(backupSchedulesTable.id, scheduleId)); }; const runForget = async (scheduleId: number, repositoryId?: string) => { diff --git a/app/server/utils/errors.ts b/app/server/utils/errors.ts index 22379a36..3aefd1c1 100644 --- a/app/server/utils/errors.ts +++ b/app/server/utils/errors.ts @@ -26,6 +26,7 @@ const resticErrorCodes: Record = { 11: "Failed to lock repository: Unable to acquire a lock on the repository. Try to run doctor on the repository.", 12: "Wrong repository password: The provided password for the repository is incorrect.", 130: "Backup interrupted: The backup process was interrupted.", + 999: "The backup was stopped by the user.", }; export class ResticError extends Error { diff --git a/app/server/utils/restic.ts b/app/server/utils/restic.ts index a4e076f5..024edb69 100644 --- a/app/server/utils/restic.ts +++ b/app/server/utils/restic.ts @@ -345,6 +345,11 @@ const backup = async ( logger.error(`Restic backup failed: ${res.stderr.toString()}`); logger.error(`Command executed: restic ${args.join(" ")}`); + if (options?.signal?.aborted) { + logger.error("Restic backup was aborted by signal."); + throw new ResticError(999, "Backup operation stopped by user."); + } + throw new ResticError(res.exitCode, res.stderr.toString()); }