feat(backup): 新增 MongoDB 备份与恢复支持 (#87)

通过 mongodump/mongorestore --archive 流式管线接入 MongoDB 数据源,与现有数据库运行器架构一致;注册到 Master 与 Agent,含任务校验、默认端口与前端表单/恢复确认。5 个单测覆盖参数构造、全库、空产物与缺工具分支。
This commit is contained in:
Wu Qing
2026-05-27 18:35:10 +08:00
committed by GitHub
parent 992fc24150
commit f584a0802a
10 changed files with 239 additions and 11 deletions

View File

@@ -198,11 +198,11 @@ export function BackupTaskFormDrawer({ visible, loading, initialValue, storageTa
sourcePath: value === 'file' ? current.sourcePath : '',
sourcePaths: value === 'file' ? current.sourcePaths : [''],
excludePatterns: value === 'file' ? current.excludePatterns : [],
dbHost: value === 'mysql' || value === 'postgresql' || value === 'saphana' ? current.dbHost : '',
dbPort: value === 'mysql' || value === 'postgresql' || value === 'saphana' ? current.dbPort || getDefaultPort(value) : 0,
dbUser: value === 'mysql' || value === 'postgresql' || value === 'saphana' ? current.dbUser : '',
dbPassword: value === 'mysql' || value === 'postgresql' || value === 'saphana' ? current.dbPassword : '',
dbName: value === 'mysql' || value === 'postgresql' || value === 'saphana' ? current.dbName : '',
dbHost: isDatabaseBackupTask(value) ? current.dbHost : '',
dbPort: isDatabaseBackupTask(value) ? current.dbPort || getDefaultPort(value) : 0,
dbUser: isDatabaseBackupTask(value) ? current.dbUser : '',
dbPassword: isDatabaseBackupTask(value) ? current.dbPassword : '',
dbName: isDatabaseBackupTask(value) ? current.dbName : '',
dbPath: value === 'sqlite' ? current.dbPath : '',
// 切换到 SAP HANA 时初始化扩展配置;切换到其他类型时清空
extraConfig: value === 'saphana'

View File

@@ -6,6 +6,7 @@ export const backupTaskTypeOptions = [
{ label: 'SQLite', value: 'sqlite' },
{ label: 'PostgreSQL', value: 'postgresql' },
{ label: 'SAP HANA', value: 'saphana' },
{ label: 'MongoDB', value: 'mongodb' },
] as const
export const backupCompressionOptions = [
@@ -25,6 +26,8 @@ export function getBackupTaskTypeLabel(type: BackupTaskType) {
return 'PostgreSQL'
case 'saphana':
return 'SAP HANA'
case 'mongodb':
return 'MongoDB'
default:
return type
}
@@ -67,7 +70,7 @@ export function isSQLiteBackupTask(type: BackupTaskType) {
}
export function isDatabaseBackupTask(type: BackupTaskType) {
return type === 'mysql' || type === 'postgresql' || type === 'saphana'
return type === 'mysql' || type === 'postgresql' || type === 'saphana' || type === 'mongodb'
}
export function getDefaultPort(type: BackupTaskType) {
@@ -78,6 +81,8 @@ export function getDefaultPort(type: BackupTaskType) {
return 5432
case 'saphana':
return 30015
case 'mongodb':
return 27017
default:
return 0
}

View File

@@ -80,7 +80,7 @@ function renderRestoreTarget(task: BackupTaskDetail) {
if (task.type === 'sqlite') {
return <Typography.Text code>{task.dbPath || '-'}</Typography.Text>
}
if (task.type === 'mysql' || task.type === 'postgresql' || task.type === 'saphana') {
if (task.type === 'mysql' || task.type === 'postgresql' || task.type === 'saphana' || task.type === 'mongodb') {
return (
<Typography.Text>
{task.dbUser}@{task.dbHost}:{task.dbPort} / <Typography.Text code>{task.dbName || '-'}</Typography.Text>

View File

@@ -1,4 +1,4 @@
export type BackupTaskType = 'file' | 'mysql' | 'sqlite' | 'postgresql' | 'saphana'
export type BackupTaskType = 'file' | 'mysql' | 'sqlite' | 'postgresql' | 'saphana' | 'mongodb'
export type BackupTaskStatus = 'idle' | 'running' | 'success' | 'failed'
export type BackupCompression = 'gzip' | 'none'