fix: run forget on mirrors in the background (#136)
This commit is contained in:
parent
7619612b1b
commit
8a5d45cbfb
1 changed files with 12 additions and 13 deletions
|
|
@ -289,10 +289,12 @@ const executeBackup = async (scheduleId: number, manual = false) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schedule.retentionPolicy) {
|
if (schedule.retentionPolicy) {
|
||||||
void runForget(schedule.id);
|
void runForget(schedule.id).catch((error) => {
|
||||||
|
logger.error(`Failed to run retention policy for schedule ${scheduleId}: ${toMessage(error)}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
copyToMirrors(scheduleId, repository, schedule.retentionPolicy).catch((error) => {
|
void copyToMirrors(scheduleId, repository, schedule.retentionPolicy).catch((error) => {
|
||||||
logger.error(`Background mirror copy failed for schedule ${scheduleId}: ${toMessage(error)}`);
|
logger.error(`Background mirror copy failed for schedule ${scheduleId}: ${toMessage(error)}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -421,7 +423,7 @@ const stopBackup = async (scheduleId: number) => {
|
||||||
abortController.abort();
|
abortController.abort();
|
||||||
};
|
};
|
||||||
|
|
||||||
const runForget = async (scheduleId: number) => {
|
const runForget = async (scheduleId: number, repositoryId?: string) => {
|
||||||
const schedule = await db.query.backupSchedulesTable.findFirst({
|
const schedule = await db.query.backupSchedulesTable.findFirst({
|
||||||
where: eq(backupSchedulesTable.id, scheduleId),
|
where: eq(backupSchedulesTable.id, scheduleId),
|
||||||
});
|
});
|
||||||
|
|
@ -435,7 +437,7 @@ const runForget = async (scheduleId: number) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const repository = await db.query.repositoriesTable.findFirst({
|
const repository = await db.query.repositoriesTable.findFirst({
|
||||||
where: eq(repositoriesTable.id, schedule.repositoryId),
|
where: eq(repositoriesTable.id, repositoryId ?? schedule.repositoryId),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!repository) {
|
if (!repository) {
|
||||||
|
|
@ -443,7 +445,7 @@ const runForget = async (scheduleId: number) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`running retention policy (forget) for schedule ${scheduleId}`);
|
logger.info(`running retention policy (forget) for schedule ${scheduleId}`);
|
||||||
const releaseLock = await repoMutex.acquireExclusive(repository.id, `forget:manual:${scheduleId}`);
|
const releaseLock = await repoMutex.acquireExclusive(repository.id, `forget:${scheduleId}`);
|
||||||
try {
|
try {
|
||||||
await restic.forget(repository.config, schedule.retentionPolicy, { tag: schedule.id.toString() });
|
await restic.forget(repository.config, schedule.retentionPolicy, { tag: schedule.id.toString() });
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -575,14 +577,11 @@ const copyToMirrors = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retentionPolicy) {
|
if (retentionPolicy) {
|
||||||
const releaseForget = await repoMutex.acquireExclusive(mirror.repository.id, `forget:mirror:${scheduleId}`);
|
void runForget(scheduleId, mirror.repository.id).catch((error) => {
|
||||||
|
logger.error(
|
||||||
try {
|
`Failed to run retention policy for mirror repository ${mirror.repository.name}: ${toMessage(error)}`,
|
||||||
logger.info(`[Background] Applying retention policy to mirror repository: ${mirror.repository.name}`);
|
);
|
||||||
await restic.forget(mirror.repository.config, retentionPolicy, { tag: scheduleId.toString() });
|
});
|
||||||
} finally {
|
|
||||||
releaseForget();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await db
|
await db
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue