From ed288368ea17bda7eef6892227b00b8ebc46d27e Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:01:05 +0800 Subject: [PATCH] fix: Fixed issue with recover mysql-cluster with backup files (#9707) --- agent/app/api/v2/backup.go | 4 ++-- agent/utils/mysql/client/local.go | 9 +++++++-- frontend/src/components/upload/index.vue | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/agent/app/api/v2/backup.go b/agent/app/api/v2/backup.go index e008c0fab..31c6bee9a 100644 --- a/agent/app/api/v2/backup.go +++ b/agent/app/api/v2/backup.go @@ -466,12 +466,12 @@ func (b *BaseApi) RecoverByUpload(c *gin.Context) { } switch req.Type { - case "mysql", "mariadb": + case "mysql", "mariadb", constant.AppMysqlCluster: if err := backupService.MysqlRecoverByUpload(req); err != nil { helper.InternalServer(c, err) return } - case constant.AppPostgresql: + case constant.AppPostgresql, constant.AppPostgresqlCluster: if err := backupService.PostgresqlRecoverByUpload(req); err != nil { helper.InternalServer(c, err) return diff --git a/agent/utils/mysql/client/local.go b/agent/utils/mysql/client/local.go index 268500713..ec89a9e6b 100644 --- a/agent/utils/mysql/client/local.go +++ b/agent/utils/mysql/client/local.go @@ -253,7 +253,12 @@ func (r *Local) Backup(info BackupInfo) error { func (r *Local) Recover(info RecoverInfo) error { fi, _ := os.Open(info.SourceFile) defer fi.Close() - cmd := exec.Command("docker", "exec", "-i", r.ContainerName, r.Type, "-uroot", "-p"+r.Password, "--default-character-set="+info.Format, info.Name) + mysqlCli := r.Type + if mysqlCli == "mysql-cluster" { + mysqlCli = "mysql" + } + + cmd := exec.Command("docker", "exec", "-i", r.ContainerName, mysqlCli, "-uroot", "-p"+r.Password, "--default-character-set="+info.Format, info.Name) if strings.HasSuffix(info.SourceFile, ".gz") { gzipFile, err := os.Open(info.SourceFile) if err != nil { @@ -271,7 +276,7 @@ func (r *Local) Recover(info RecoverInfo) error { } stdout, err := cmd.CombinedOutput() stdStr := strings.ReplaceAll(string(stdout), "mysql: [Warning] Using a password on the command line interface can be insecure.\n", "") - if err != nil || strings.HasPrefix(string(stdStr), "ERROR ") { + if err != nil || strings.HasPrefix(stdStr, "ERROR ") { return errors.New(stdStr) } diff --git a/frontend/src/components/upload/index.vue b/frontend/src/components/upload/index.vue index 34339d5eb..143f0dcd5 100644 --- a/frontend/src/components/upload/index.vue +++ b/frontend/src/components/upload/index.vue @@ -188,6 +188,8 @@ const acceptParams = async (params: DialogProps): Promise => { case 'mysql': case 'mariadb': case 'postgresql': + case 'mysql-cluster': + case 'postgresql-cluster': title.value = name.value + ' [ ' + detailName.value + ' ]'; if (detailName.value) { baseDir.value = `${pathRes.data}/uploads/database/${type.value}/${name.value}/${detailName.value}/`;