Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FEATURE (config): Suggest read-only user creation when DB config changed

Rostislav Dugin4e4a323cf18c
diff --git a/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
index 23db3ac7..63dec884 100644
--- a/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
+++ b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
@@ -1,4 +1,4 @@
-import { InfoCircleOutlined } from '@ant-design/icons';
+import { DownOutlined, InfoCircleOutlined, UpOutlined } from '@ant-design/icons';
import {
Button,
Checkbox,
@@ -79,6 +79,9 @@ export const EditBackupConfigComponent = ({
const [isShowWarn, setIsShowWarn] = useState(false);
+ const hasAdvancedValues = !!backupConfig?.isRetryIfFailed;
+ const [isShowAdvanced, setShowAdvanced] = useState(hasAdvancedValues);
+
const timeFormat = useMemo(() => {
const is12 = getIs12Hour();
return { use12Hours: is12, format: is12 ? 'h:mm A' : 'HH:mm' };
@@ -155,7 +158,7 @@ export const EditBackupConfigComponent = ({
},
storage: undefined,
storePeriod: Period.THREE_MONTH,
- sendNotificationsOn: [],
+ sendNotificationsOn: [BackupNotificationType.BackupFailed],
isRetryIfFailed: true,
maxFailedTriesCount: 3,
encryption: BackupEncryption.ENCRYPTED,
@@ -363,79 +366,6 @@ export const EditBackupConfigComponent = ({
</div>
)}
- <div className="mt-4 mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
- <div className="mb-1 min-w-[150px] sm:mb-0">Retry backup if failed</div>
- <div className="flex items-center">
- <Switch
- size="small"
- checked={backupConfig.isRetryIfFailed}
- onChange={(checked) => updateBackupConfig({ isRetryIfFailed: checked })}
- />
-
- <Tooltip
- className="cursor-pointer"
- title="Automatically retry failed backups. Backups can fail due to network failures, storage issues or temporary database unavailability."
- >
- <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
- </Tooltip>
- </div>
- </div>
-
- {backupConfig.isRetryIfFailed && (
- <div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
- <div className="mb-1 min-w-[150px] sm:mb-0">Max failed tries count</div>
- <div className="flex items-center">
- <InputNumber
- min={1}
- max={10}
- value={backupConfig.maxFailedTriesCount}
- onChange={(value) => updateBackupConfig({ maxFailedTriesCount: value || 1 })}
- size="small"
- className="w-full max-w-[200px] grow"
- />
-
- <Tooltip
- className="cursor-pointer"
- title="Maximum number of retry attempts for failed backups. You will receive a notification when all tries have failed."
- >
- <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
- </Tooltip>
- </div>
- </div>
- )}
-
- <div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
- <div className="mb-1 min-w-[150px] sm:mb-0">Store period</div>
- <div className="flex items-center">
- <Select
- value={backupConfig.storePeriod}
- onChange={(v) => updateBackupConfig({ storePeriod: v })}
- size="small"
- className="w-full max-w-[200px] grow"
- options={[
- { label: '1 day', value: Period.DAY },
- { label: '1 week', value: Period.WEEK },
- { label: '1 month', value: Period.MONTH },
- { label: '3 months', value: Period.THREE_MONTH },
- { label: '6 months', value: Period.SIX_MONTH },
- { label: '1 year', value: Period.YEAR },
- { label: '2 years', value: Period.TWO_YEARS },
- { label: '3 years', value: Period.THREE_YEARS },
- { label: '4 years', value: Period.FOUR_YEARS },
- { label: '5 years', value: Period.FIVE_YEARS },
- { label: 'Forever', value: Period.FOREVER },
- ]}
- />
-
- <Tooltip
- className="cursor-pointer"
- title="How long to keep the backups? Make sure you have enough storage space."
- >
- <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
- </Tooltip>
- </div>
- </div>
-
<div className="mb-3" />
</>
)}
@@ -485,7 +415,7 @@ export const EditBackupConfigComponent = ({
value={backupConfig.encryption}
onChange={(v) => updateBackupConfig({ encryption: v })}
size="small"
- className="w-full max-w-[200px] grow"
+ className="w-[200px]"
options={[
{ label: 'None', value: BackupEncryption.NONE },
{ label: 'Encrypt backup files', value: BackupEncryption.ENCRYPTED },
@@ -501,6 +431,38 @@ export const EditBackupConfigComponent = ({
</div>
</div>
+ <div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
+ <div className="mb-1 min-w-[150px] sm:mb-0">Store period</div>
+ <div className="flex items-center">
+ <Select
+ value={backupConfig.storePeriod}
+ onChange={(v) => updateBackupConfig({ storePeriod: v })}
+ size="small"
+ className="w-[200px]"
+ options={[
+ { label: '1 day', value: Period.DAY },
+ { label: '1 week', value: Period.WEEK },
+ { label: '1 month', value: Period.MONTH },
+ { label: '3 months', value: Period.THREE_MONTH },
+ { label: '6 months', value: Period.SIX_MONTH },
+ { label: '1 year', value: Period.YEAR },
+ { label: '2 years', value: Period.TWO_YEARS },
+ { label: '3 years', value: Period.THREE_YEARS },
+ { label: '4 years', value: Period.FOUR_YEARS },
+ { label: '5 years', value: Period.FIVE_YEARS },
+ { label: 'Forever', value: Period.FOREVER },
+ ]}
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="How long to keep the backups? Make sure you have enough storage space."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+ </div>
+
{backupConfig.isBackupsEnabled && (
<>
<div className="mt-4 mb-1 flex w-full flex-col items-start sm:flex-row sm:items-start">
@@ -546,9 +508,69 @@ export const EditBackupConfigComponent = ({
</>
)}
+ <div className="mt-4 mb-1 flex items-center">
+ <div
+ className="flex cursor-pointer items-center text-sm text-blue-600 hover:text-blue-800"
+ onClick={() => setShowAdvanced(!isShowAdvanced)}
+ >
+ <span className="mr-2">Advanced settings</span>
+
+ {isShowAdvanced ? (
+ <UpOutlined style={{ fontSize: '12px' }} />
+ ) : (
+ <DownOutlined style={{ fontSize: '12px' }} />
+ )}
+ </div>
+ </div>
+
+ {isShowAdvanced && backupConfig.isBackupsEnabled && (
+ <>
+ <div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
+ <div className="mb-1 min-w-[150px] sm:mb-0">Retry backup if failed</div>
+ <div className="flex items-center">
+ <Switch
+ size="small"
+ checked={backupConfig.isRetryIfFailed}
+ onChange={(checked) => updateBackupConfig({ isRetryIfFailed: checked })}
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="Automatically retry failed backups. Backups can fail due to network failures, storage issues or temporary database unavailability."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+ </div>
+
+ {backupConfig.isRetryIfFailed && (
+ <div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
+ <div className="mb-1 min-w-[150px] sm:mb-0">Max failed tries count</div>
+ <div className="flex items-center">
+ <InputNumber
+ min={1}
+ max={10}
+ value={backupConfig.maxFailedTriesCount}
+ onChange={(value) => updateBackupConfig({ maxFailedTriesCount: value || 1 })}
+ size="small"
+ className="w-full max-w-[200px] grow"
+ />
+
+ <Tooltip
+ className="cursor-pointer"
+ title="Maximum number of retry attempts for failed backups. You will receive a notification when all tries have failed."
+ >
+ <InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
+ </Tooltip>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+
<div className="mt-5 flex">
{isShowBackButton && (
- <Button className="mr-1" onClick={onBack}>
+ <Button className="mr-1" type="primary" ghost onClick={onBack}>
Back
</Button>
)}
diff --git a/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx b/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
index 2be4005a..f24cff9a 100644
--- a/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
+++ b/frontend/src/features/databases/ui/CreateDatabaseComponent.tsx
@@ -137,9 +137,11 @@ export const CreateDatabaseComponent = ({ workspaceId, onCreated, onClose }: Pro
database={database}
onReadOnlyUserUpdated={(database) => {
setDatabase({ ...database });
+ setStep('backup-config');
}}
onGoBack={() => setStep('db-settings')}
- onContinue={() => setStep('backup-config')}
+ onSkipped={() => setStep('backup-config')}
+ onAlreadyExists={() => setStep('backup-config')}
/>
);
}
diff --git a/frontend/src/features/databases/ui/edit/CreateReadOnlyComponent.tsx b/frontend/src/features/databases/ui/edit/CreateReadOnlyComponent.tsx
index 8ac0a869..32e7ebd6 100644
--- a/frontend/src/features/databases/ui/edit/CreateReadOnlyComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/CreateReadOnlyComponent.tsx
@@ -8,7 +8,8 @@ interface Props {
onReadOnlyUserUpdated: (database: Database) => void;
onGoBack: () => void;
- onContinue: () => void;
+ onSkipped: () => void;
+ onAlreadyExists: () => void;
}
const PRIVILEGES_TRUNCATE_LENGTH = 50;
@@ -17,7 +18,8 @@ export const CreateReadOnlyComponent = ({
database,
onReadOnlyUserUpdated,
onGoBack,
- onContinue,
+ onSkipped,
+ onAlreadyExists,
}: Props) => {
const [isCheckingReadOnlyUser, setIsCheckingReadOnlyUser] = useState(false);
const [isCreatingReadOnlyUser, setIsCreatingReadOnlyUser] = useState(false);
@@ -87,7 +89,6 @@ export const CreateReadOnlyComponent = ({
}
onReadOnlyUserUpdated(database);
- onContinue();
} catch (e) {
alert((e as Error).message);
}
@@ -101,7 +102,7 @@ export const CreateReadOnlyComponent = ({
const handleSkipConfirmed = () => {
setShowSkipConfirmation(false);
- onContinue();
+ onSkipped();
};
useEffect(() => {
@@ -110,7 +111,7 @@ export const CreateReadOnlyComponent = ({
const isReadOnly = await checkReadOnlyUser();
if (isReadOnly) {
- onContinue();
+ onAlreadyExists();
}
setIsCheckingReadOnlyUser(false);
@@ -228,7 +229,7 @@ export const CreateReadOnlyComponent = ({
</div>
<div className="flex justify-end">
- <Button className="mr-2" danger onClick={handleSkipConfirmed}>
+ <Button className="mr-2" danger ghost onClick={handleSkipConfirmed}>
Yes, I accept risks
</Button>
diff --git a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
index d893f519..6b12b1d9 100644
--- a/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
+++ b/frontend/src/features/databases/ui/edit/EditDatabaseSpecificDataComponent.tsx
@@ -1,4 +1,8 @@
-import { type Database, DatabaseType } from '../../../../entity/databases';
+import { Modal } from 'antd';
+import { useState } from 'react';
+
+import { type Database, DatabaseType, databaseApi } from '../../../../entity/databases';
+import { CreateReadOnlyComponent } from './CreateReadOnlyComponent';
import { EditMariaDbSpecificDataComponent } from './EditMariaDbSpecificDataComponent';
import { EditMongoDbSpecificDataComponent } from './EditMongoDbSpecificDataComponent';
import { EditMySqlSpecificDataComponent } from './EditMySqlSpecificDataComponent';
@@ -36,19 +40,84 @@ export const EditDatabaseSpecificDataComponent = ({
isShowDbName = true,
isRestoreMode = false,
}: Props) => {
+ const [isShowReadOnlyDialog, setIsShowReadOnlyDialog] = useState(false);
+ const [editingDatabase, setEditingDatabase] = useState<Database>(database);
+
+ const saveDb = async (databaseToSave: Database) => {
+ setEditingDatabase(databaseToSave);
+
+ if (!isSaveToApi) {
+ onSaved(databaseToSave);
+ return;
+ }
+
+ try {
+ const result = await databaseApi.isUserReadOnly(databaseToSave);
+
+ if (result.isReadOnly) {
+ onSaved(databaseToSave);
+ } else {
+ setIsShowReadOnlyDialog(true);
+ }
+ } catch (e) {
+ alert((e as Error).message);
+ }
+ };
+
+ const onReadOnlyUserCreated = (updatedDatabase: Database) => {
+ setEditingDatabase(updatedDatabase);
+ setIsShowReadOnlyDialog(false);
+ };
+
+ const skipReadOnlyUser = () => {
+ setIsShowReadOnlyDialog(false);
+ onSaved(editingDatabase);
+ };
+
+ if (isShowReadOnlyDialog) {
+ return (
+ <Modal
+ title="Create read-only user"
+ footer={<div />}
+ open={isShowReadOnlyDialog}
+ onCancel={() => setIsShowReadOnlyDialog(false)}
+ maskClosable={false}
+ width={450}
+ >
+ <CreateReadOnlyComponent
+ database={editingDatabase}
+ onReadOnlyUserUpdated={(db) => {
+ console.log('onReadOnlyUserUpdated', db);
+ onReadOnlyUserCreated(db);
+ }}
+ onGoBack={() => {
+ setIsShowReadOnlyDialog(false);
+ }}
+ onSkipped={() => {
+ skipReadOnlyUser();
+ }}
+ onAlreadyExists={() => {
+ console.log('onAlreadyExists');
+ onSaved(editingDatabase);
+ }}
+ />
+ </Modal>
+ );
+ }
+
const commonProps = {
- database,
+ database: editingDatabase,
isShowCancelButton,
onCancel,
isShowBackButton,
onBack,
saveButtonText,
isSaveToApi,
- onSaved,
+ onSaved: saveDb,
isShowDbName,
};
- switch (database.type) {
+ switch (editingDatabase.type) {
case DatabaseType.POSTGRES:
return <EditPostgreSqlSpecificDataComponent {...commonProps} isRestoreMode={isRestoreMode} />;
case DatabaseType.MYSQL: