Browse Source

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

pull/205/head
ssongliu 2 years ago committed by ssongliu
parent
commit
35098ce79c
  1. 6
      backend/app/service/app_utils.go
  2. 2
      backend/app/service/backup_app.go
  3. 5
      backend/app/service/backup_redis.go

6
backend/app/service/app_utils.go

@ -4,8 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/utils/env"
"math"
"os"
"path"
@ -13,6 +11,9 @@ import (
"strconv"
"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/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)
}
_ = 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
}

2
backend/app/service/backup_app.go

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

5
backend/app/service/backup_redis.go

@ -121,7 +121,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
}
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)
}
} else {
@ -170,7 +170,7 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
}
} else {
itemName := "dump.rdb"
if redisInfo.Version == "6.0.16" {
if appendonly == "yes" && redisInfo.Version == "6.0.16" {
itemName = "appendonly.aof"
}
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 {
return err
}
isOk = true
return nil
}

Loading…
Cancel
Save