mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
fix: 修改恢复导致配置文件清空的BUG
This commit is contained in:
parent
505caa4d49
commit
1034188f40
@ -216,12 +216,13 @@ func (w WebsiteService) Recover(req request.WebsiteRecover) error {
|
|||||||
if !strings.Contains(req.BackupName, "/") {
|
if !strings.Contains(req.BackupName, "/") {
|
||||||
return errors.New("error path of request")
|
return errors.New("error path of request")
|
||||||
}
|
}
|
||||||
fileDir := req.BackupName[:strings.LastIndex(req.BackupName, "/")]
|
fileDir := path.Dir(req.BackupName)
|
||||||
fileName := strings.ReplaceAll(req.BackupName[strings.LastIndex(req.BackupName, "/"):], ".tar.gz", "")
|
pathName := strings.ReplaceAll(path.Base(req.BackupName), ".tar.gz", "")
|
||||||
|
//fileName := strings.ReplaceAll(req.BackupName[strings.LastIndex(req.BackupName, "/"):], ".tar.gz", "")
|
||||||
if err := handleUnTar(req.BackupName, fileDir); err != nil {
|
if err := handleUnTar(req.BackupName, fileDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fileDir = fileDir + "/" + fileName
|
fileDir = fileDir + "/" + pathName
|
||||||
|
|
||||||
if err := handleWebsiteRecover(&website, fileDir); err != nil {
|
if err := handleWebsiteRecover(&website, fileDir); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -415,7 +415,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
if website.Type == constant.Deployment {
|
if website.Type == constant.Deployment {
|
||||||
if err := mysqlOpration(&website, "backup", tmpDir); err != nil {
|
if err := mysqlOperation(&website, "backup", tmpDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
|
app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
|
||||||
@ -460,13 +460,13 @@ func handleWebsiteRecover(website *model.Website, fileDir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nginxConfPath := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name)
|
nginxConfPath := fmt.Sprintf("%s/nginx/%s/conf/conf.d", constant.AppInstallDir, nginxInfo.Name)
|
||||||
if err := files.NewFileOp().CopyFile(path.Join(fileDir, website.PrimaryDomain+".conf"), nginxConfPath); err != nil {
|
if err := files.NewFileOp().CopyFile(path.Join(fileDir, website.Alias+".conf"), nginxConfPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if website.Type == constant.Deployment {
|
if website.Type == constant.Deployment {
|
||||||
if err := mysqlOpration(website, "recover", fileDir); err != nil {
|
if err := mysqlOperation(website, "recover", fileDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,17 +475,16 @@ func handleWebsiteRecover(website *model.Website, fileDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
appDir := fmt.Sprintf("%s/%s", constant.AppInstallDir, app.App.Key)
|
appDir := fmt.Sprintf("%s/%s", constant.AppInstallDir, app.App.Key)
|
||||||
if err := handleUnTar(fmt.Sprintf("%s/%s.web.tar.gz", fileDir, website.PrimaryDomain), appDir); err != nil {
|
if err := handleUnTar(fmt.Sprintf("%s/%s.app.tar.gz", fileDir, website.Alias), appDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := compose.Restart(fmt.Sprintf("%s/%s/docker-compose.yml", appDir, app.Name)); err != nil {
|
if _, err := compose.Restart(fmt.Sprintf("%s/%s/docker-compose.yml", appDir, app.Name)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
appDir := fmt.Sprintf("%s/nginx/%s/www", constant.AppInstallDir, nginxInfo.Name)
|
siteDir := fmt.Sprintf("%s/nginx/%s/www/sites", constant.AppInstallDir, nginxInfo.Name)
|
||||||
if err := handleUnTar(fmt.Sprintf("%s/%s.web.tar.gz", fileDir, website.PrimaryDomain), appDir); err != nil {
|
if err := handleUnTar(fmt.Sprintf("%s/%s.web.tar.gz", fileDir, website.Alias), siteDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cmd := exec.Command("docker", "exec", "-i", nginxInfo.ContainerName, "nginx", "-s", "reload")
|
cmd := exec.Command("docker", "exec", "-i", nginxInfo.ContainerName, "nginx", "-s", "reload")
|
||||||
stdout, err := cmd.CombinedOutput()
|
stdout, err := cmd.CombinedOutput()
|
||||||
@ -497,8 +496,8 @@ func handleWebsiteRecover(website *model.Website, fileDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysqlOpration(website *model.Website, operation, filePath string) error {
|
func mysqlOperation(website *model.Website, operation, filePath string) error {
|
||||||
mysqlInfo, err := appInstallRepo.LoadBaseInfo(constant.AppNginx, "")
|
mysqlInfo, err := appInstallRepo.LoadBaseInfo(constant.AppMysql, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -521,7 +520,7 @@ func mysqlOpration(website *model.Website, operation, filePath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cmd := exec.Command("docker", "exec", "-i", mysqlInfo.ContainerName, "mysql", "-uroot", "-p"+mysqlInfo.Password, db.Name)
|
cmd := exec.Command("docker", "exec", "-i", mysqlInfo.ContainerName, "mysql", "-uroot", "-p"+mysqlInfo.Password, db.Name)
|
||||||
sqlfile, err := os.Open(fmt.Sprintf("%s/%s.sql", filePath, website.PrimaryDomain))
|
sqlfile, err := os.Open(fmt.Sprintf("%s/%s.sql", filePath, website.Alias))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user