From ef8fd7228fb47c81b5366a523856bdd1aaf9a21c Mon Sep 17 00:00:00 2001 From: Nico <47644445+nicotsx@users.noreply.github.com> Date: Wed, 10 Dec 2025 21:18:10 +0100 Subject: [PATCH] fix(mirrors): keep last copy state (#125) --- app/server/modules/backups/backups.service.ts | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/server/modules/backups/backups.service.ts b/app/server/modules/backups/backups.service.ts index f76bbcf2..a95fc738 100644 --- a/app/server/modules/backups/backups.service.ts +++ b/app/server/modules/backups/backups.service.ts @@ -502,15 +502,32 @@ const updateMirrors = async (scheduleId: number, data: UpdateScheduleMirrorsBody } } + const existingMirrors = await db.query.backupScheduleMirrorsTable.findMany({ + where: eq(backupScheduleMirrorsTable.scheduleId, scheduleId), + }); + + const existingMirrorsMap = new Map( + existingMirrors.map((m) => [ + m.repositoryId, + { lastCopyAt: m.lastCopyAt, lastCopyStatus: m.lastCopyStatus, lastCopyError: m.lastCopyError }, + ]), + ); + await db.delete(backupScheduleMirrorsTable).where(eq(backupScheduleMirrorsTable.scheduleId, scheduleId)); if (data.mirrors.length > 0) { await db.insert(backupScheduleMirrorsTable).values( - data.mirrors.map((mirror) => ({ - scheduleId, - repositoryId: mirror.repositoryId, - enabled: mirror.enabled, - })), + data.mirrors.map((mirror) => { + const existing = existingMirrorsMap.get(mirror.repositoryId); + return { + scheduleId, + repositoryId: mirror.repositoryId, + enabled: mirror.enabled, + lastCopyAt: existing?.lastCopyAt ?? null, + lastCopyStatus: existing?.lastCopyStatus ?? null, + lastCopyError: existing?.lastCopyError ?? null, + }; + }), ); }