From 2fdb1700e5b42d03432bcd4804b58e8a60bc3464 Mon Sep 17 00:00:00 2001
From: ssongliu <73214554+ssongliu@users.noreply.github.com>
Date: Mon, 15 Dec 2025 18:40:37 +0800
Subject: [PATCH] feat: Database restore supports timeout settings (#11338)
---
agent/app/dto/backup.go | 1 +
agent/app/service/backup_mysql.go | 11 ++++++++++-
agent/app/service/backup_postgresql.go | 11 ++++++++++-
agent/app/task/task.go | 3 +++
frontend/src/components/backup/index.vue | 21 ++++++++++++++++++++-
frontend/src/components/upload/index.vue | 21 ++++++++++++++++++++-
frontend/src/lang/modules/en.ts | 1 +
frontend/src/lang/modules/es-es.ts | 2 ++
frontend/src/lang/modules/ja.ts | 1 +
frontend/src/lang/modules/ko.ts | 1 +
frontend/src/lang/modules/ms.ts | 1 +
frontend/src/lang/modules/pt-br.ts | 1 +
frontend/src/lang/modules/ru.ts | 1 +
frontend/src/lang/modules/tr.ts | 1 +
frontend/src/lang/modules/zh-Hant.ts | 1 +
frontend/src/lang/modules/zh.ts | 1 +
16 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/agent/app/dto/backup.go b/agent/app/dto/backup.go
index af6789de1..b0d97f131 100644
--- a/agent/app/dto/backup.go
+++ b/agent/app/dto/backup.go
@@ -83,6 +83,7 @@ type CommonRecover struct {
Secret string `json:"secret"`
TaskID string `json:"taskID"`
BackupRecordID uint `json:"backupRecordID"`
+ Timeout int `json:"timeout"`
}
type RecordSearch struct {
diff --git a/agent/app/service/backup_mysql.go b/agent/app/service/backup_mysql.go
index d77f2e9ad..f003c75e7 100644
--- a/agent/app/service/backup_mysql.go
+++ b/agent/app/service/backup_mysql.go
@@ -193,7 +193,16 @@ func handleMysqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback
return recoverDatabase(parentTask)
}
- itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
+ var timeout time.Duration
+ switch req.Timeout {
+ case -1:
+ timeout = 0
+ case 0:
+ timeout = 3 * time.Hour
+ default:
+ timeout = time.Duration(req.Timeout) * time.Second
+ }
+ itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
go func() {
_ = itemTask.Execute()
}()
diff --git a/agent/app/service/backup_postgresql.go b/agent/app/service/backup_postgresql.go
index 2051f4d36..4d4489d39 100644
--- a/agent/app/service/backup_postgresql.go
+++ b/agent/app/service/backup_postgresql.go
@@ -187,7 +187,16 @@ func handlePostgresqlRecover(req dto.CommonRecover, parentTask *task.Task, isRol
return recoverDatabase(parentTask)
}
- itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
+ var timeout time.Duration
+ switch req.Timeout {
+ case -1:
+ timeout = 0
+ case 0:
+ timeout = 3 * time.Hour
+ default:
+ timeout = time.Duration(req.Timeout) * time.Second
+ }
+ itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
go func() {
_ = itemTask.Execute()
}()
diff --git a/agent/app/task/task.go b/agent/app/task/task.go
index d3431e5ab..58374ba64 100644
--- a/agent/app/task/task.go
+++ b/agent/app/task/task.go
@@ -226,6 +226,9 @@ func (s *SubTask) Execute() error {
s.RootTask.Log(i18n.GetWithName("TaskRetry", strconv.Itoa(i)))
}
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
+ if s.Timeout == 0 {
+ ctx, cancel = context.WithCancel(context.Background())
+ }
defer cancel()
done := make(chan error)
diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue
index 65ac84644..706c9896f 100644
--- a/frontend/src/components/backup/index.vue
+++ b/frontend/src/components/backup/index.vue
@@ -110,6 +110,22 @@
+
+
+
+
+
+
+
+
+
+
+ {{ $t('database.recoverTimeoutHelper') }}
+
@@ -133,7 +149,7 @@