Skip to content

EVEREST-1838 | disable PITR after no schedules or backups are left #1252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4fe8859
feat: disable PITR after no schedules or backups are left
fabio-silva Mar 20, 2025
a5aebcc
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
fabio-silva Mar 24, 2025
0458d3f
chore: remove unused arg
fabio-silva Mar 24, 2025
d0860e4
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Mar 24, 2025
8c5e5dd
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Mar 25, 2025
8c35ace
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Mar 25, 2025
520ee84
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Mar 26, 2025
becd8f8
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Mar 27, 2025
8e17fbe
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
fabio-silva Apr 9, 2025
4f808fa
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 9, 2025
654f554
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 9, 2025
7803376
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 10, 2025
f5da4f8
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 10, 2025
8b9001d
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 10, 2025
d0f5a1d
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 10, 2025
994c549
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 14, 2025
99cba03
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
percona-robot Apr 16, 2025
574506b
Merge branch 'main' into EVEREST-1838-disable-PITR-on-empty-backups
fabio-silva Apr 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { PG_SLOTS_LIMIT } from 'consts';
export const Messages = {
deleteDialog: {
header: 'Delete backup',
content: (backupName: string, dbType: DbEngineType) => (
content: (
backupName: string,
dbType: DbEngineType,
willDisablePITR: boolean
) => (
<>
{dbType === DbEngineType.POSTGRESQL ? (
<>
Expand All @@ -17,6 +21,8 @@ export const Messages = {
backup?
</>
)}
{willDisablePITR &&
' This will disable point-in-time recovery, as it requires a full backup.'}
</>
),
alertMessage:
Expand Down Expand Up @@ -45,4 +51,6 @@ export const Messages = {
restoreToNewDb: 'Create new DB',
pgMaximum: (slotsInUse: number) =>
`Note: There is a maximum of 3 backup schedules for PostgreSQL. You are using ${slotsInUse} out of ${PG_SLOTS_LIMIT} available storages.`,
pitrToBeDisabled:
'This will disable point-in-time recovery, as it requires a full backup.',
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ import {
useDbBackups,
useDbClusterPitr,
useDeleteBackup,
} from 'hooks/api/backups/useBackups';
useUpdateDbClusterWithConflictRetry,
} from 'hooks';
import { MRT_ColumnDef } from 'material-react-table';
import { Alert, Typography } from '@mui/material';
import { RestoreDbModal } from 'modals/index.ts';
import { useContext, useMemo, useState } from 'react';
import { Backup, BackupStatus } from 'shared-types/backups.types';
import {
Backup,
BackupStatus,
GetBackupsPayload,
} from 'shared-types/backups.types';
import { ScheduleModalContext } from '../backups.context.ts';
import { BACKUP_STATUS_TO_BASE_STATUS } from './backups-list.constants';
import { Messages } from './backups-list.messages';
Expand Down Expand Up @@ -57,16 +62,19 @@ export const BackupsList = () => {
setOpenOnDemandModal,
} = useContext(ScheduleModalContext);

const { mutate: deleteBackup, isPending: deletingBackup } = useDeleteBackup(
dbCluster?.metadata.namespace
);
const { data: backups = [] } = useDbBackups(
dbCluster.metadata.name,
dbCluster.metadata.namespace,
{
refetchInterval: 10 * 1000,
}
);
const { mutate: updateCluster } = useUpdateDbClusterWithConflictRetry(
dbCluster,
{
onSuccess: () => handleCloseDeleteDialog(),
}
);
const { data: pitrData } = useDbClusterPitr(
dbCluster.metadata.name!,
dbCluster.metadata.namespace,
Expand All @@ -78,6 +86,16 @@ export const BackupsList = () => {
dbCluster?.metadata.namespace
);
const dbType = dbCluster.spec?.engine.type;
const pitrEnabled = !!dbCluster.spec?.backup?.pitr?.enabled;
const willDisablePITR =
(dbCluster.spec?.backup?.schedules || []).length === 0 &&
pitrEnabled &&
backups.length === 1;

const { mutate: deleteBackup, isPending: deletingBackup } = useDeleteBackup(
dbCluster?.metadata.namespace
);

const { storagesToShow, uniqueStoragesInUse } =
getAvailableBackupStoragesForBackups(
backups,
Expand Down Expand Up @@ -168,13 +186,42 @@ export const BackupsList = () => {
{ backupName: backupName, cleanupBackupStorage: cleanupBackupStorage },
{
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [
if (willDisablePITR) {
updateCluster({
...dbCluster,
spec: {
...dbCluster.spec,
backup: {
...dbCluster.spec.backup,
pitr: {
enabled: false,
backupStorageName:
dbCluster.spec.backup?.pitr?.backupStorageName || '',
},
},
},
});
}
queryClient.setQueryData(
[
BACKUPS_QUERY_KEY,
dbCluster.metadata.namespace,
dbCluster.metadata.name,
],
});
(oldData: GetBackupsPayload) => ({
items: oldData.items.map((backup) =>
backup.metadata.name === backupName
? {
...backup,
status: {
...backup.status,
state: BackupStatus.DELETING,
},
}
: backup
),
})
);
handleCloseDeleteDialog();
},
}
Expand Down Expand Up @@ -222,6 +269,7 @@ export const BackupsList = () => {
onNowClick={handleManualBackup}
onScheduleClick={handleScheduledBackup}
noStoragesAvailable={noStoragesAvailable}
backups={backups}
/>
)}
enableRowActions
Expand Down Expand Up @@ -253,7 +301,8 @@ export const BackupsList = () => {
confirmationInput={false}
dialogContent={Messages.deleteDialog.content(
selectedBackup,
dbCluster.spec.engine.type
dbCluster.spec.engine.type,
willDisablePITR
)}
alertMessage={Messages.deleteDialog.alertMessage}
submitMessage={Messages.deleteDialog.confirmButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ export const Messages = {
schedule: 'Schedule',
deleteModal: {
header: 'Delete schedule',
content: (scheduleName: string) => (
content: (scheduleName: string, willDisablePITR: boolean) => (
<>
Are you sure you want to permanently delete schedule{' '}
<b>{scheduleName}</b>?
<b>{scheduleName}</b>?{' '}
{willDisablePITR &&
' This will disable point-in-time recovery, as it requires a full backup.'}
</>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import ScheduledBackupsList from './scheduled-backups-list';
import { BackupListTableHeaderProps } from './backups-list-table-header.types';
import { Messages } from './backups-list-table-header.messages';
import { useRBACPermissions } from 'hooks/rbac';
import { BackupStatus } from 'shared-types/backups.types';

const BackupListTableHeader = ({
onNowClick,
onScheduleClick,
noStoragesAvailable,
backups,
}: BackupListTableHeaderProps) => {
const [showSchedules, setShowSchedules] = useState(false);
const { dbCluster } = useContext(ScheduleModalContext);
Expand Down Expand Up @@ -142,7 +144,14 @@ const BackupListTableHeader = ({
</MenuButton>
)}
</Box>
{schedulesNumber > 0 && showSchedules && <ScheduledBackupsList />}
{schedulesNumber > 0 && showSchedules && (
<ScheduledBackupsList
emptyBackups={
backups.length === 0 ||
backups.every((b) => b.state === BackupStatus.DELETING)
}
/>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Backup } from 'shared-types/backups.types';

export type BackupListTableHeaderProps = {
onNowClick: () => void;
onScheduleClick: () => void;
noStoragesAvailable?: boolean;
backups: Backup[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
import { useUpdateDbClusterWithConflictRetry } from 'hooks';
import { WizardMode } from 'shared-types/wizard.types';

const ScheduledBackupsList = () => {
type Props = {
emptyBackups: boolean;
};

const ScheduledBackupsList = ({ emptyBackups }: Props) => {
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
const [selectedSchedule, setSelectedSchedule] = useState<string>('');
const {
Expand All @@ -30,7 +34,8 @@ const ScheduledBackupsList = () => {
onSuccess: () => handleCloseDeleteDialog(),
});
const [schedules, setSchedules] = useState<ManageableSchedules[]>([]);

const pitrEnabled = !!dbCluster.spec?.backup?.pitr?.enabled;
const willDisablePITR = emptyBackups && schedules.length === 1 && pitrEnabled;
const handleDelete = (scheduleName: string) => {
setSelectedSchedule(scheduleName);
setOpenDeleteDialog(true);
Expand All @@ -41,7 +46,9 @@ const ScheduledBackupsList = () => {
};

const handleConfirmDelete = (scheduleName: string) => {
updateCluster(deleteScheduleFromDbCluster(scheduleName, dbCluster));
updateCluster(
deleteScheduleFromDbCluster(scheduleName, dbCluster, willDisablePITR)
);
};

const handleEdit = (scheduleName: string) => {
Expand Down Expand Up @@ -157,7 +164,7 @@ const ScheduledBackupsList = () => {
handleConfirm={handleConfirmDelete}
disabledButtons={updatingCluster}
>
{Messages.deleteModal.content(selectedSchedule)}
{Messages.deleteModal.content(selectedSchedule, willDisablePITR)}
</ConfirmDialog>
)}
</Stack>
Expand Down
11 changes: 10 additions & 1 deletion ui/apps/everest/src/utils/db.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ export const changeDbClusterPITR = (

export const deleteScheduleFromDbCluster = (
scheduleName: string,
dbCluster: DbCluster
dbCluster: DbCluster,
disablePITR: boolean
): DbCluster => {
const schedules = dbCluster?.spec?.backup?.schedules || [];
const filteredSchedulesWithCronCorrection = schedules.reduce(
Expand All @@ -270,6 +271,14 @@ export const deleteScheduleFromDbCluster = (
...dbCluster?.spec,
backup: {
...dbCluster.spec.backup,
...(disablePITR && {
pitr: {
...dbCluster.spec.backup?.pitr,
backupStorageName:
dbCluster.spec.backup?.pitr?.backupStorageName || '',
enabled: false,
},
}),
schedules:
filteredSchedulesWithCronCorrection.length > 0
? filteredSchedulesWithCronCorrection
Expand Down
Loading