PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FEATURE (backups): Simplify WAL range rows down to the type, a gap status and a from/to window with the segment count, so the list shows what matters for restore instead of archive internals
Rostislav Duginc05a682a2830
diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsxindex d8f7e16c..815218ce 100644--- a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsx+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.test.tsx@@ -1,3 +1,4 @@+import type { JSX } from 'react';import { renderToStaticMarkup } from 'react-dom/server';import { describe, expect, it, vi } from 'vitest';@@ -7,7 +8,10 @@ import {PhysicalBackupType,} from '../../../../entity/backups/physical';import { LocaleProvider } from '../../../../shared/i18n';-import { PhysicalBackupTypeCellComponent } from './PhysicalBackupTypeCellComponent';+import {+ PhysicalBackupTypeCellComponent,+ WalRangeSegmentsComponent,+} from './PhysicalBackupTypeCellComponent';// The entity's public API imports its API client, and the client's config// module reads window at import time. The tests run in node, so they supply@@ -39,49 +43,51 @@ const createWalRange = (change: Partial<PhysicalBackupListItem>): PhysicalBackup...change,});-const renderCell = (backup: PhysicalBackupListItem) =>- renderToStaticMarkup(- <LocaleProvider>- <PhysicalBackupTypeCellComponent backup={backup} />- </LocaleProvider>,- );+const renderWithLocale = (element: JSX.Element) =>+ renderToStaticMarkup(<LocaleProvider>{element}</LocaleProvider>);describe('PhysicalBackupTypeCellComponent', () => {- it('shows the segment count and the first and last segment of a WAL range', () => {- const markup = renderCell(createWalRange({}));+ it('shows only the type badge for a WAL range', () => {+ const markup = renderWithLocale(+ <PhysicalBackupTypeCellComponent backup={createWalRange({})} />,+ );- expect(markup).toContain('Segments: 240');- expect(markup).toContain(FIRST_SEGMENT);- expect(markup).toContain(LAST_SEGMENT);- expect(markup).not.toContain('Gap before this range');+ expect(markup).toContain('WAL');+ expect(markup).not.toContain(FIRST_SEGMENT);+ expect(markup).not.toContain('Segments:');});- it('marks a WAL range that follows a gap', () => {- const markup = renderCell(createWalRange({ hasGapBefore: true }));+ it('shows only the type badge for a backup', () => {+ const markup = renderWithLocale(+ <PhysicalBackupTypeCellComponent+ backup={createWalRange({+ type: PhysicalBackupType.FULL,+ fromWalFilename: undefined,+ toWalFilename: undefined,+ walSegmentsCount: undefined,+ })}+ />,+ );- expect(markup).toContain('Gap before this range');+ expect(markup).toContain('Full');});+});- it('shows one segment name for a single-segment range', () => {- const markup = renderCell(- createWalRange({ toWalFilename: FIRST_SEGMENT, walSegmentsCount: 1 }),- );+describe('WalRangeSegmentsComponent', () => {+ it('shows the first and last segment of a range', () => {+ const markup = renderWithLocale(<WalRangeSegmentsComponent backup={createWalRange({})} />);- expect(markup.split(FIRST_SEGMENT)).toHaveLength(2);- expect(markup).toContain('Segments: 1');+ expect(markup).toContain(FIRST_SEGMENT);+ expect(markup).toContain(LAST_SEGMENT);});- it('shows only the type badge for a backup', () => {- const markup = renderCell(- createWalRange({- type: PhysicalBackupType.FULL,- fromWalFilename: undefined,- toWalFilename: undefined,- walSegmentsCount: undefined,- }),+ it('shows one segment name for a single-segment range', () => {+ const markup = renderWithLocale(+ <WalRangeSegmentsComponent+ backup={createWalRange({ toWalFilename: FIRST_SEGMENT, walSegmentsCount: 1 })}+ />,);- expect(markup).toContain('Full');- expect(markup).not.toContain('Segments:');+ expect(markup.split(FIRST_SEGMENT)).toHaveLength(2);});});diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsxindex 243cde4b..48ba9287 100644--- a/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsx+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupTypeCellComponent.tsx@@ -40,6 +40,24 @@ const renderTypeBadge = (type: PhysicalBackupType, t: TFunction): JSX.Element =>);};+// The segment names are only needed when investigating the archive, so they+// stay in the badge tooltip instead of the row.+export const WalRangeSegmentsComponent = ({ backup }: Props): JSX.Element => {+ const isSingleSegment = backup.fromWalFilename === backup.toWalFilename;++ return (+ <div className="flex flex-wrap items-center gap-1 font-mono text-xs">+ {backup.fromWalFilename}+ {!isSingleSegment && (+ <>+ <ArrowRightOutlined className="text-[10px]" />+ {backup.toWalFilename}+ </>+ )}+ </div>+ );+};+export const PhysicalBackupTypeCellComponent = ({ backup }: Props): JSX.Element => {const { t } = useTranslation();@@ -49,34 +67,9 @@ export const PhysicalBackupTypeCellComponent = ({ backup }: Props): JSX.Elementreturn typeBadge;}- const isSingleSegment = backup.fromWalFilename === backup.toWalFilename;-return (- <div className="space-y-1">- <div className="flex items-center gap-2">- {typeBadge}- <span className="text-xs text-gray-500 dark:text-gray-400">- {t('backups.physical.list.walRange.segments', { count: backup.walSegmentsCount })}- </span>- </div>-- <div className="flex flex-wrap items-center gap-1 font-mono text-xs text-gray-600 dark:text-gray-300">- {backup.fromWalFilename}- {!isSingleSegment && (- <>- <ArrowRightOutlined className="text-[10px]" />- {backup.toWalFilename}- </>- )}- </div>-- {backup.hasGapBefore && (- <Tooltip title={t('backups.physical.list.walRange.gapBeforeTooltip')}>- <span className="inline-flex items-center rounded bg-amber-500/15 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-amber-500/40 ring-inset dark:text-amber-300">- {t('backups.physical.list.walRange.gapBefore')}- </span>- </Tooltip>- )}- </div>+ <Tooltip title={<WalRangeSegmentsComponent backup={backup} />}>+ <span className="cursor-help">{typeBadge}</span>+ </Tooltip>);};diff --git a/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx b/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsxindex b8cb7b82..e269158e 100644--- a/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx+++ b/frontend/src/features/backups/physical/ui/PhysicalBackupsComponent.tsx@@ -1,5 +1,4 @@import {- ArrowRightOutlined,CloseCircleOutlined,CloudUploadOutlined,DeleteOutlined,@@ -56,11 +55,32 @@ const formatSize = (sizeMb: number, formatNumber: LocaleContextValue['formatNumbreturn `${formatNumber(Number((sizeMb ?? 0).toFixed(2)))} MB`;};+// A missing segment before a WAL range is its health state, so it takes the+// place of the status badge, styled like the other broken-chain warning.+const renderGapBadge = (t: TFunction): JSX.Element => {+ const badgeStyle = PHYSICAL_BACKUP_STATUS_BADGE_STYLES[PhysicalBackupStatus.CHAIN_BROKEN];++ return (+ <Tooltip title={t('backups.physical.list.walRange.gapBeforeTooltip')}>+ <span+ className={`inline-flex cursor-help items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium whitespace-nowrap ring-1 ring-inset ${badgeStyle.pillClasses}`}+ >+ <span className={`h-1.5 w-1.5 rounded-full ${badgeStyle.dotClasses}`} />+ {t('backups.physical.list.walRange.gap')}+ </span>+ </Tooltip>+ );+};+const renderStatusBadge = (backup: PhysicalBackupListItem,onShowError: (backup: PhysicalBackupListItem) => void,t: TFunction,): JSX.Element => {+ if (backup.hasGapBefore) {+ return renderGapBadge(t);+ }+const badgeStyle = PHYSICAL_BACKUP_STATUS_BADGE_STYLES[backup.status];const label = t(PHYSICAL_BACKUP_STATUS_LABEL_KEYS[backup.status]);@@ -270,6 +290,12 @@ export const PhysicalBackupsComponent = ({);const renderDuration = (record: PhysicalBackupListItem): string => {+ // A WAL range's end is the receive time of its last segment, not the end+ // of a backup run, so it has no duration to show.+ if (record.type === PhysicalBackupType.WAL) {+ return '-';+ }+if (record.completedAt) {return formatDuration(dayjs(record.completedAt).diff(dayjs(record.createdAt)));}@@ -283,21 +309,46 @@ export const PhysicalBackupsComponent = ({};const renderCreatedAt = (backup: PhysicalBackupListItem): JSX.Element => {- const isWalRange = backup.type === PhysicalBackupType.WAL && backup.completedAt !== undefined;- const latestAt = isWalRange ? backup.completedAt : backup.createdAt;+ const timeFormat = getUserTimeFormat().format;+ const createdAt = dayjs.utc(backup.createdAt).local();++ if (backup.type === PhysicalBackupType.WAL && backup.completedAt) {+ const lastReceivedAt = dayjs.utc(backup.completedAt).local();++ return (+ <div className="grid grid-cols-[auto_1fr] gap-x-2">+ <span className="text-gray-500 dark:text-gray-400">+ {t('backups.physical.list.walRange.from')}+ </span>+ <span>+ {createdAt.format(timeFormat)}{' '}+ <span className="text-gray-500 dark:text-gray-400">+ ({formatRelativeTime(createdAt)})+ </span>+ </span>++ <span className="text-gray-500 dark:text-gray-400">+ {t('backups.physical.list.walRange.to')}+ </span>+ <span>+ {lastReceivedAt.format(timeFormat)}{' '}+ <span className="text-gray-500 dark:text-gray-400">+ ({formatRelativeTime(lastReceivedAt)})+ </span>+ </span>++ <span className="text-gray-500 dark:text-gray-400">+ {t('backups.physical.list.walRange.segments')}+ </span>+ <span>{backup.walSegmentsCount}</span>+ </div>+ );+ }return (<div>- {dayjs.utc(backup.createdAt).local().format(getUserTimeFormat().format)}- {isWalRange && (- <div className="flex items-center gap-1">- <ArrowRightOutlined className="text-[10px]" />- {dayjs.utc(latestAt).local().format(getUserTimeFormat().format)}- </div>- )}- <div className="text-gray-500 dark:text-gray-400">- ({formatRelativeTime(dayjs.utc(latestAt).local())})- </div>+ {createdAt.format(timeFormat)}+ <div className="text-gray-500 dark:text-gray-400">({formatRelativeTime(createdAt)})</div></div>);};@@ -425,7 +476,7 @@ export const PhysicalBackupsComponent = ({</Button></div>- <div className="mt-5 w-full md:max-w-[850px]">+ <div className="mt-5 w-full md:max-w-[890px]">{/* Mobile card view */}<div className="md:hidden">{isBackupsLoading ? (diff --git a/frontend/src/shared/i18n/locales/en.ts b/frontend/src/shared/i18n/locales/en.tsindex 5d0680ff..d3186518 100644--- a/frontend/src/shared/i18n/locales/en.ts+++ b/frontend/src/shared/i18n/locales/en.ts@@ -1535,8 +1535,10 @@ export const en = {restoreFromThisBackup: 'Restore from this backup',pointInTimeRestoreTitle: 'Point-in-time restore',walRange: {- segments: 'Segments: {{count}}',- gapBefore: 'Gap before this range',+ from: 'From',+ to: 'To',+ segments: 'Segments',+ gap: 'Gap',gapBeforeTooltip:'WAL segments are missing between this range and the previous one. Point-in-time restore cannot replay across the gap.',},diff --git a/frontend/src/shared/i18n/locales/es.ts b/frontend/src/shared/i18n/locales/es.tsindex 3da98f71..39497b34 100644--- a/frontend/src/shared/i18n/locales/es.ts+++ b/frontend/src/shared/i18n/locales/es.ts@@ -1563,8 +1563,10 @@ export const es: typeof en = {restoreFromThisBackup: 'Restaurar desde esta copia',pointInTimeRestoreTitle: 'Restauración a un punto en el tiempo',walRange: {- segments: 'Segmentos: {{count}}',- gapBefore: 'Hueco antes de este rango',+ from: 'Desde',+ to: 'Hasta',+ segments: 'Segmentos',+ gap: 'Hueco',gapBeforeTooltip:'Faltan segmentos WAL entre este rango y el anterior. La restauración a un punto en el tiempo no puede pasar por encima del hueco.',},diff --git a/frontend/src/shared/i18n/locales/fr.ts b/frontend/src/shared/i18n/locales/fr.tsindex 31cb28cb..99575833 100644--- a/frontend/src/shared/i18n/locales/fr.ts+++ b/frontend/src/shared/i18n/locales/fr.ts@@ -1572,8 +1572,10 @@ export const fr: typeof en = {restoreFromThisBackup: 'Restaurer depuis cette sauvegarde',pointInTimeRestoreTitle: 'Restauration à un instant donné',walRange: {- segments: 'Segments : {{count}}',- gapBefore: 'Trou avant cette plage',+ from: 'Début',+ to: 'Fin',+ segments: 'Segments',+ gap: 'Trou',gapBeforeTooltip:'Des segments WAL manquent entre cette plage et la précédente. La restauration à un instant donné ne peut pas franchir ce trou.',},diff --git a/frontend/src/shared/i18n/locales/pt.ts b/frontend/src/shared/i18n/locales/pt.tsindex 2501d5ab..d79fae08 100644--- a/frontend/src/shared/i18n/locales/pt.ts+++ b/frontend/src/shared/i18n/locales/pt.ts@@ -1555,8 +1555,10 @@ export const pt: typeof en = {restoreFromThisBackup: 'Restaurar a partir deste backup',pointInTimeRestoreTitle: 'Restauração point-in-time',walRange: {- segments: 'Segmentos: {{count}}',- gapBefore: 'Lacuna antes deste intervalo',+ from: 'De',+ to: 'Até',+ segments: 'Segmentos',+ gap: 'Lacuna',gapBeforeTooltip:'Faltam segmentos WAL entre este intervalo e o anterior. A restauração point-in-time não consegue atravessar a lacuna.',},diff --git a/frontend/src/shared/i18n/locales/ru.ts b/frontend/src/shared/i18n/locales/ru.tsindex b50833be..269634fb 100644--- a/frontend/src/shared/i18n/locales/ru.ts+++ b/frontend/src/shared/i18n/locales/ru.ts@@ -1538,8 +1538,10 @@ export const ru: typeof en = {restoreFromThisBackup: 'Восстановить из этого бекапа',pointInTimeRestoreTitle: 'Восстановление на момент времени',walRange: {- segments: 'Сегментов: {{count}}',- gapBefore: 'Разрыв перед диапазоном',+ from: 'Начало',+ to: 'Конец',+ segments: 'Сегменты',+ gap: 'Разрыв',gapBeforeTooltip:'Между этим диапазоном и предыдущим не хватает сегментов WAL. Восстановление на момент времени не может пройти через этот разрыв.',},diff --git a/frontend/src/shared/i18n/locales/zh.ts b/frontend/src/shared/i18n/locales/zh.tsindex 1e349a90..f746baff 100644--- a/frontend/src/shared/i18n/locales/zh.ts+++ b/frontend/src/shared/i18n/locales/zh.ts@@ -1478,8 +1478,10 @@ export const zh: typeof en = {restoreFromThisBackup: '从此备份恢复',pointInTimeRestoreTitle: '时间点恢复',walRange: {- segments: '段数:{{count}}',- gapBefore: '此范围前存在缺口',+ from: '开始',+ to: '结束',+ segments: '段数',+ gap: '缺口',gapBeforeTooltip: '此范围与上一个范围之间缺少 WAL 段,时间点恢复无法跨越该缺口。',},deleteFullConfirmation: