1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-01 03:24:14 +08:00

fix: 解决计划任务备份日志报错的问题 (#2786)

This commit is contained in:
ssongliu 2023-11-03 11:18:45 +08:00 committed by GitHub
parent 46320634f6
commit 7e00b46d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -598,16 +598,17 @@ func (u *CronjobService) handleSystemClean() (string, error) {
} }
func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.Time) (string, error) { func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.Time) (string, error) {
websites, err := websiteRepo.List()
if err != nil {
return "", err
}
backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID))) backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID)))
if err != nil { if err != nil {
return "", err return "", err
} }
pathItem := path.Join(global.CONF.System.BaseDir, "1panel/tmp/log", startTime.Format("20060102150405")) pathItem := path.Join(global.CONF.System.BaseDir, "1panel/tmp/log", startTime.Format("20060102150405"))
websites, err := websiteRepo.List()
if err != nil {
return "", err
}
if len(websites) != 0 {
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil { if err != nil {
return "", err return "", err
@ -639,6 +640,8 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T
} }
} }
} }
global.LOG.Debug("backup website log successful!")
}
systemLogDir := path.Join(global.CONF.System.BaseDir, "1panel/log") systemLogDir := path.Join(global.CONF.System.BaseDir, "1panel/log")
systemDir := path.Join(pathItem, "system") systemDir := path.Join(pathItem, "system")
@ -655,6 +658,8 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T
} }
} }
} }
global.LOG.Debug("backup system log successful!")
loginLogFiles, _ := os.ReadDir("/var/log") loginLogFiles, _ := os.ReadDir("/var/log")
loginDir := path.Join(pathItem, "login") loginDir := path.Join(pathItem, "login")
if _, err := os.Stat(loginDir); err != nil && os.IsNotExist(err) { if _, err := os.Stat(loginDir); err != nil && os.IsNotExist(err) {
@ -669,6 +674,7 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T
} }
} }
} }
global.LOG.Debug("backup ssh log successful!")
fileName := fmt.Sprintf("system_log_%s.tar.gz", startTime.Format("20060102150405")) fileName := fmt.Sprintf("system_log_%s.tar.gz", startTime.Format("20060102150405"))
if err := handleTar(pathItem, pathItem, fileName, ""); err != nil { if err := handleTar(pathItem, pathItem, fileName, ""); err != nil {