From 327e160ea30b41f8b9d7c05e3c9d88930208e85e Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:48:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E3=80=81=E7=BD=91=E7=AB=99=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#2266)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_utils.go | 11 +++++++---- backend/app/service/backup_app.go | 16 ++++++++++++---- backend/app/service/cronjob_helper.go | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index db32c8492..82d8d2479 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/cmd" "math" "net/http" "os" @@ -16,6 +15,8 @@ import ( "strconv" "strings" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/i18n" @@ -294,9 +295,11 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f continue } if err := mysqlService.Delete(ctx, dto.MysqlDBDelete{ - ID: database.ID, - ForceDelete: forceDelete, - Database: database.MysqlName, + ID: database.ID, + ForceDelete: forceDelete, + DeleteBackup: true, + Type: re.Key, + Database: database.MysqlName, }); err != nil && !forceDelete { return err } diff --git a/backend/app/service/backup_app.go b/backend/app/service/backup_app.go index 0d823e4f0..f9996cc8b 100644 --- a/backend/app/service/backup_app.go +++ b/backend/app/service/backup_app.go @@ -173,8 +173,15 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback newEnvFile := "" resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID)) for _, resource := range resources { + if resource.From != "local" { + continue + } + resourceApp, err := appInstallRepo.GetFirst(commonRepo.WithByID(resource.LinkId)) + if err != nil { + return err + } if resource.Key == "mysql" || resource.Key == "maraidb" { - mysqlInfo, err := appInstallRepo.LoadBaseInfo(resource.Key, "") + mysqlInfo, err := appInstallRepo.LoadBaseInfo(resource.Key, resourceApp.Name) if err != nil { return err } @@ -183,7 +190,7 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback return err } - newDB, envMap, err := reCreateDB(db.ID, oldInstall.Env) + newDB, envMap, err := reCreateDB(db.ID, resourceApp, oldInstall.Env) if err != nil { return err } @@ -245,10 +252,10 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback return nil } -func reCreateDB(dbID uint, oldEnv string) (*model.DatabaseMysql, map[string]interface{}, error) { +func reCreateDB(dbID uint, app model.AppInstall, oldEnv string) (*model.DatabaseMysql, map[string]interface{}, error) { mysqlService := NewIMysqlService() ctx := context.Background() - _ = mysqlService.Delete(ctx, dto.MysqlDBDelete{ID: dbID, DeleteBackup: true, ForceDelete: true}) + _ = mysqlService.Delete(ctx, dto.MysqlDBDelete{ID: dbID, Database: app.Name, Type: app.App.Key, DeleteBackup: true, ForceDelete: true}) envMap := make(map[string]interface{}) if err := json.Unmarshal([]byte(oldEnv), &envMap); err != nil { @@ -260,6 +267,7 @@ func reCreateDB(dbID uint, oldEnv string) (*model.DatabaseMysql, map[string]inte createDB, err := mysqlService.Create(context.Background(), dto.MysqlDBCreate{ Name: oldName, From: "local", + Database: app.Name, Format: "utf8mb4", Username: oldUser, Password: oldPassword, diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index aaabd50a6..c4bbb6c90 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -232,7 +232,7 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string) error { path = sourceDir } - commands := fmt.Sprintf("tar -zcf --warning=no-file-changed --ignore-failed-read %s %s %s", targetDir+"/"+name, excludeRules, path) + commands := fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path) global.LOG.Debug(commands) stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) if err != nil {