mirror of https://github.com/1Panel-dev/1Panel
fix: 解决应用备份失败的问题 (#1828)
parent
e30546102e
commit
43e1ec0244
|
@ -104,8 +104,9 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resource, _ := appInstallResourceRepo.GetFirst(appInstallResourceRepo.WithAppInstallId(install.ID))
|
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
|
||||||
if resource.ID != 0 && resource.ResourceId != 0 {
|
for _, resource := range resources {
|
||||||
|
if resource.Key == "mysql" {
|
||||||
db, err := mysqlRepo.Get(commonRepo.WithByID(resource.ResourceId))
|
db, err := mysqlRepo.Get(commonRepo.WithByID(resource.ResourceId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -114,6 +115,7 @@ func handleAppBackup(install *model.AppInstall, backupDir, fileName string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil {
|
if err := handleTar(tmpDir, backupDir, fileName, ""); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -169,8 +171,9 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
|
||||||
}
|
}
|
||||||
|
|
||||||
newEnvFile := ""
|
newEnvFile := ""
|
||||||
resource, _ := appInstallResourceRepo.GetFirst(appInstallResourceRepo.WithAppInstallId(install.ID))
|
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
|
||||||
if resource.ID != 0 && install.App.Key != "mysql" {
|
for _, resource := range resources {
|
||||||
|
if resource.Key == "mysql" {
|
||||||
mysqlInfo, err := appInstallRepo.LoadBaseInfo(resource.Key, "")
|
mysqlInfo, err := appInstallRepo.LoadBaseInfo(resource.Key, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -197,12 +200,13 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
|
||||||
if err := handleMysqlRecover(dto.CommonRecover{
|
if err := handleMysqlRecover(dto.CommonRecover{
|
||||||
Name: newDB.MysqlName,
|
Name: newDB.MysqlName,
|
||||||
DetailName: newDB.Name,
|
DetailName: newDB.Name,
|
||||||
File: tmpPath + "/" + fmt.Sprintf("%s/%s.sql.gz", tmpPath, install.Name),
|
File: fmt.Sprintf("%s/%s.sql.gz", tmpPath, install.Name),
|
||||||
}, true); err != nil {
|
}, true); err != nil {
|
||||||
global.LOG.Errorf("handle recover from sql.gz failed, err: %v", err)
|
global.LOG.Errorf("handle recover from sql.gz failed, err: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := handleUnTar(tmpPath+"/app.tar.gz", fmt.Sprintf("%s/%s", constant.AppInstallDir, install.App.Key)); err != nil {
|
if err := handleUnTar(tmpPath+"/app.tar.gz", fmt.Sprintf("%s/%s", constant.AppInstallDir, install.App.Key)); err != nil {
|
||||||
global.LOG.Errorf("handle recover from app.tar.gz failed, err: %v", err)
|
global.LOG.Errorf("handle recover from app.tar.gz failed, err: %v", err)
|
||||||
|
@ -246,6 +250,7 @@ func reCreateDB(dbID uint, oldEnv string) (*model.DatabaseMysql, map[string]inte
|
||||||
oldPassword, _ := envMap["PANEL_DB_USER_PASSWORD"].(string)
|
oldPassword, _ := envMap["PANEL_DB_USER_PASSWORD"].(string)
|
||||||
createDB, err := mysqlService.Create(context.Background(), dto.MysqlDBCreate{
|
createDB, err := mysqlService.Create(context.Background(), dto.MysqlDBCreate{
|
||||||
Name: oldName,
|
Name: oldName,
|
||||||
|
From: "local",
|
||||||
Format: "utf8mb4",
|
Format: "utf8mb4",
|
||||||
Username: oldUser,
|
Username: oldUser,
|
||||||
Password: oldPassword,
|
Password: oldPassword,
|
||||||
|
|
Loading…
Reference in New Issue