fix: 解决静态网站备份失败的BUG

pull/85/head
zhengkunwang223 2022-12-22 14:55:36 +08:00 committed by zhengkunwang223
parent 6cf654b5a1
commit 8ddaef68cf
1 changed files with 7 additions and 28 deletions

View File

@ -4,7 +4,6 @@ import (
"bufio"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"path"
@ -423,21 +422,19 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
if err := mysqlOpration(&website, "backup", tmpDir); err != nil {
return err
}
app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
if err != nil {
return err
}
websiteDir := fmt.Sprintf("%s/%s/%s", constant.AppInstallDir, app.App.Key, app.Name)
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.PrimaryDomain), ""); err != nil {
return err
}
} else {
websiteDir := fmt.Sprintf("%s/nginx/%s/www/%s", constant.AppInstallDir, nginxInfo.Name, website.PrimaryDomain)
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.PrimaryDomain), ""); err != nil {
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.app.tar.gz", website.PrimaryDomain), ""); err != nil {
return err
}
}
websiteDir := path.Join(constant.AppInstallDir, "nginx", nginxInfo.Name, "www", "sites", website.PrimaryDomain)
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.PrimaryDomain), ""); err != nil {
return err
}
if err := handleTar(tmpDir, fmt.Sprintf("%s/%s", baseDir, backupDir), backupName+".tar.gz", ""); err != nil {
return err
}
@ -467,8 +464,8 @@ func handleWebsiteRecover(website *model.Website, fileDir string) error {
if err != nil {
return err
}
nginxConfFile := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name, website.PrimaryDomain)
if err := copyConf(fmt.Sprintf("%s/%s.conf", fileDir, website.PrimaryDomain), nginxConfFile); err != nil {
nginxConfPath := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name)
if err := files.NewFileOp().CopyFile(path.Join(fileDir, website.PrimaryDomain+".conf"), nginxConfPath); err != nil {
return err
}
@ -558,24 +555,6 @@ func saveWebsiteJson(website *model.Website, tmpDir string) error {
return nil
}
func copyConf(srcPath, dstPath string) error {
if _, err := os.Stat(srcPath); err != nil {
return err
}
src, err := os.OpenFile(srcPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
if err != nil {
return err
}
defer src.Close()
out, err := os.Create(dstPath)
if err != nil {
return err
}
defer out.Close()
_, _ = io.Copy(out, src)
return nil
}
func deleteWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)