fix: 解决删除应用时,未删除备份记录的问题

This commit is contained in:
ssongliu 2023-03-13 18:37:15 +08:00 committed by ssongliu
parent 5a3a123be7
commit 35098ce79c
3 changed files with 8 additions and 5 deletions

View file

@ -4,8 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/utils/env"
"math" "math"
"os" "os"
"path" "path"
@ -13,6 +11,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/utils/env"
"github.com/1Panel-dev/1Panel/backend/app/dto/response" "github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/buserr"
@ -159,6 +160,7 @@ func deleteAppInstall(ctx context.Context, install model.AppInstall, deleteBacku
global.LOG.Infof("delete app %s-%s backups successful", install.App.Key, install.Name) global.LOG.Infof("delete app %s-%s backups successful", install.App.Key, install.Name)
} }
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), backupRepo.WithByDetailName(install.Name)) _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), backupRepo.WithByDetailName(install.Name))
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(install.App.Key))
return nil return nil
} }

View file

@ -103,7 +103,7 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro
} }
resource, _ := appInstallResourceRepo.GetFirst(appInstallResourceRepo.WithAppInstallId(install.ID)) resource, _ := appInstallResourceRepo.GetFirst(appInstallResourceRepo.WithAppInstallId(install.ID))
if resource.ID != 0 { if resource.ID != 0 && resource.ResourceId != 0 {
mysqlInfo, err := appInstallRepo.LoadBaseInfo(constant.AppMysql, "") mysqlInfo, err := appInstallRepo.LoadBaseInfo(constant.AppMysql, "")
if err != nil { if err != nil {
return err return err

View file

@ -121,7 +121,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
} }
if appendonly == "yes" { if appendonly == "yes" {
if !strings.HasSuffix(recoverFile, ".tar.gz") || !strings.HasSuffix(recoverFile, ".aof") { if !strings.HasSuffix(recoverFile, ".tar.gz") && !strings.HasSuffix(recoverFile, ".aof") {
return buserr.New(constant.ErrTypeOfRedis) return buserr.New(constant.ErrTypeOfRedis)
} }
} else { } else {
@ -170,7 +170,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
} }
} else { } else {
itemName := "dump.rdb" itemName := "dump.rdb"
if redisInfo.Version == "6.0.16" { if appendonly == "yes" && redisInfo.Version == "6.0.16" {
itemName = "appendonly.aof" itemName = "appendonly.aof"
} }
input, err := ioutil.ReadFile(recoverFile) input, err := ioutil.ReadFile(recoverFile)
@ -184,5 +184,6 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
if _, err := compose.Up(composeDir + "/docker-compose.yml"); err != nil { if _, err := compose.Up(composeDir + "/docker-compose.yml"); err != nil {
return err return err
} }
isOk = true
return nil return nil
} }