fix(backup): updating new settings correctly in the db

This commit is contained in:
DerPenz 2026-04-08 20:12:42 +02:00 committed by Nico
parent b1cd1a4220
commit 0476dcebb8
8 changed files with 19 additions and 8 deletions

View file

@ -2712,6 +2712,8 @@ export type CreateBackupScheduleData = {
oneFileSystem?: boolean;
tags?: Array<string>;
customResticParams?: Array<string>;
maxRetries?: number;
retryDelay?: number;
};
path?: never;
query?: never;
@ -3091,6 +3093,8 @@ export type UpdateBackupScheduleData = {
oneFileSystem?: boolean;
tags?: Array<string>;
customResticParams?: Array<string>;
maxRetries?: number;
retryDelay?: number;
};
path: {
shortId: string;

View file

@ -28,7 +28,7 @@ export const AdvancedSection = ({ form }: AdvancedSectionProps) => {
onChange={(e) => field.onChange(e.target.value ? Number(e.target.value) : undefined)}
/>
</FormControl>
<FormDescription>Maximum number of retry attempts if a backup fails (default: 0).</FormDescription>
<FormDescription>Maximum number of retry attempts if a backup fails (default: 3).</FormDescription>
<FormMessage />
</FormItem>
)}
@ -43,7 +43,7 @@ export const AdvancedSection = ({ form }: AdvancedSectionProps) => {
<Input
{...field}
type="number"
min={0}
min={1}
max={1440}
step={1}
placeholder="e.g., 60"

View file

@ -62,7 +62,7 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
excludeIfPresent,
customResticParams,
maxRetries,
retryDelay: retryDelay ? retryDelay * 60 * 1000 : 3600000,
retryDelay,
});
},
[onSubmit],

View file

@ -44,6 +44,4 @@ export type BackupScheduleFormValues = Omit<
excludeIfPresent?: string[];
includePatterns?: string[];
customResticParams?: string[];
maxRetries?: number;
retryDelay?: number;
};

View file

@ -26,8 +26,8 @@ export const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalF
excludeIfPresentText: schedule.excludeIfPresent?.join("\n") || undefined,
oneFileSystem: schedule.oneFileSystem ?? false,
customResticParamsText: schedule.customResticParams?.join("\n") ?? "",
maxRetries: schedule.maxRetries ?? 5,
retryDelay: schedule.retryDelay ? schedule.retryDelay / (60 * 60 * 1000) : 1, // Convert ms to hours
maxRetries: schedule.maxRetries,
retryDelay: schedule.retryDelay ? schedule.retryDelay / (60 * 1000) : undefined, // Convert ms to minutes
...cronValues,
...schedule.retentionPolicy,
};

View file

@ -75,6 +75,8 @@ export function CreateBackupPage() {
excludeIfPresent: formValues.excludeIfPresent,
oneFileSystem: formValues.oneFileSystem,
customResticParams: formValues.customResticParams,
maxRetries: formValues.maxRetries,
retryDelay: formValues.retryDelay,
},
});
};

View file

@ -130,6 +130,8 @@ export const createBackupScheduleBody = z.object({
oneFileSystem: z.boolean().optional(),
tags: z.array(z.string()).optional(),
customResticParams: z.array(z.string()).optional(),
maxRetries: z.number().optional(),
retryDelay: z.number().optional(),
});
export type CreateBackupScheduleBody = z.infer<typeof createBackupScheduleBody>;
@ -167,6 +169,8 @@ export const updateBackupScheduleBody = z.object({
oneFileSystem: z.boolean().optional(),
tags: z.array(z.string()).optional(),
customResticParams: z.array(z.string()).optional(),
maxRetries: z.number().optional(),
retryDelay: z.number().optional(),
});
export type UpdateBackupScheduleBody = z.infer<typeof updateBackupScheduleBody>;

View file

@ -111,6 +111,8 @@ const createSchedule = async (data: CreateBackupScheduleBody) => {
customResticParams: data.customResticParams ?? [],
nextBackupAt: nextBackupAt,
shortId: generateShortId(),
maxRetries: data.maxRetries,
retryDelay: data.retryDelay ? data.retryDelay * 60 * 1000 : undefined,
organizationId,
})
.returning();
@ -163,10 +165,11 @@ const updateSchedule = async (scheduleIdOrShortId: number | string, data: Update
const cronExpression = data.cronExpression ?? schedule.cronExpression;
const nextBackupAt =
data.cronExpression === "" ? null : data.cronExpression ? calculateNextRun(cronExpression) : schedule.nextBackupAt;
const retryDelay = data.retryDelay ? data.retryDelay * 60 * 1000 : schedule.retryDelay;
const [updated] = await db
.update(backupSchedulesTable)
.set({ ...data, repositoryId: repository.id, nextBackupAt, updatedAt: Date.now() })
.set({ ...data, repositoryId: repository.id, nextBackupAt, updatedAt: Date.now(), retryDelay })
.where(and(eq(backupSchedulesTable.id, schedule.id), eq(backupSchedulesTable.organizationId, organizationId)))
.returning();