fix: 应用备份目录从设置中读取

pull/56/head
zhengkunwang223 2022-12-01 17:14:39 +08:00 committed by zhengkunwang223
parent 459fc5ba45
commit 098b735c7a
3 changed files with 22 additions and 6 deletions

View File

@ -243,8 +243,28 @@ func updateInstall(installId uint, detailId uint) error {
func backupInstall(ctx context.Context, install model.AppInstall) error {
var backup model.AppInstallBackup
appPath := install.GetPath()
backupDir := path.Join(constant.BackupDir, install.App.Key, install.Name)
backupAccount, err := backupRepo.Get(commonRepo.WithByType("LOCAL"))
if err != nil {
return err
}
varMap := make(map[string]interface{})
if err := json.Unmarshal([]byte(backupAccount.Vars), &varMap); err != nil {
return err
}
dir, ok := varMap["dir"]
if !ok {
return errors.New("load local backup dir failed")
}
baseDir, ok := dir.(string)
if !ok {
return errors.New("load local backup dir failed")
}
backupDir := path.Join(baseDir, "apps", install.App.Key, install.Name)
fileOp := files.NewFileOp()
if !fileOp.Stat(backupDir) {
_ = fileOp.CreateDir(backupDir, 0775)
}
now := time.Now()
day := now.Format("20060102150405")
fileName := fmt.Sprintf("%s_%s%s", install.Name, day, ".tar.gz")

View File

@ -10,6 +10,4 @@ var (
ResourceDir = path.Join(DefaultDataDir, "resource")
AppResourceDir = path.Join(ResourceDir, "apps")
AppInstallDir = path.Join(DefaultDataDir, "apps")
BackupDir = path.Join(DefaultDataDir, "backup")
AppBackupDir = path.Join(BackupDir, "apps")
)

View File

@ -13,10 +13,8 @@ func Init() {
constant.ResourceDir = path.Join(constant.DefaultDataDir, "resource")
constant.AppResourceDir = path.Join(constant.ResourceDir, "apps")
constant.AppInstallDir = path.Join(constant.DefaultDataDir, "apps")
constant.BackupDir = path.Join(constant.DefaultDataDir, "backup")
constant.AppBackupDir = path.Join(constant.BackupDir, "apps")
dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, constant.BackupDir, constant.AppBackupDir}
dirs := []string{constant.DefaultDataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir}
fileOp := files.NewFileOp()
for _, dir := range dirs {