Merge pull request #2060 from Dokploy/2043-running-manual-backup-on-service-does-not-remove-outdated-backups-over-keep-latest

feat(backup): implement keepLatestNBackups function to manage backup …
This commit is contained in:
Mauricio Siu
2025-06-22 04:16:51 +02:00
committed by GitHub

View File

@@ -22,6 +22,7 @@ import {
findPostgresByBackupId, findPostgresByBackupId,
findPostgresById, findPostgresById,
findServerById, findServerById,
keepLatestNBackups,
removeBackupById, removeBackupById,
removeScheduleBackup, removeScheduleBackup,
runMariadbBackup, runMariadbBackup,
@@ -197,6 +198,8 @@ export const backupRouter = createTRPCRouter({
const backup = await findBackupById(input.backupId); const backup = await findBackupById(input.backupId);
const postgres = await findPostgresByBackupId(backup.backupId); const postgres = await findPostgresByBackupId(backup.backupId);
await runPostgresBackup(postgres, backup); await runPostgresBackup(postgres, backup);
await keepLatestNBackups(backup, postgres?.serverId);
return true; return true;
} catch (error) { } catch (error) {
const message = const message =
@@ -217,6 +220,7 @@ export const backupRouter = createTRPCRouter({
const backup = await findBackupById(input.backupId); const backup = await findBackupById(input.backupId);
const mysql = await findMySqlByBackupId(backup.backupId); const mysql = await findMySqlByBackupId(backup.backupId);
await runMySqlBackup(mysql, backup); await runMySqlBackup(mysql, backup);
await keepLatestNBackups(backup, mysql?.serverId);
return true; return true;
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({
@@ -233,6 +237,7 @@ export const backupRouter = createTRPCRouter({
const backup = await findBackupById(input.backupId); const backup = await findBackupById(input.backupId);
const mariadb = await findMariadbByBackupId(backup.backupId); const mariadb = await findMariadbByBackupId(backup.backupId);
await runMariadbBackup(mariadb, backup); await runMariadbBackup(mariadb, backup);
await keepLatestNBackups(backup, mariadb?.serverId);
return true; return true;
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({
@@ -249,6 +254,7 @@ export const backupRouter = createTRPCRouter({
const backup = await findBackupById(input.backupId); const backup = await findBackupById(input.backupId);
const compose = await findComposeByBackupId(backup.backupId); const compose = await findComposeByBackupId(backup.backupId);
await runComposeBackup(compose, backup); await runComposeBackup(compose, backup);
await keepLatestNBackups(backup, compose?.serverId);
return true; return true;
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({
@@ -265,6 +271,7 @@ export const backupRouter = createTRPCRouter({
const backup = await findBackupById(input.backupId); const backup = await findBackupById(input.backupId);
const mongo = await findMongoByBackupId(backup.backupId); const mongo = await findMongoByBackupId(backup.backupId);
await runMongoBackup(mongo, backup); await runMongoBackup(mongo, backup);
await keepLatestNBackups(backup, mongo?.serverId);
return true; return true;
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({