From 0c64c8ff521eff832b4593e5486777c994627a37 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:25:35 +0800 Subject: [PATCH] fix: Fix the problem of incomplete printing of the cronjob (#9197) --- agent/app/service/cronjob_backup.go | 10 +++++----- agent/app/service/cronjob_helper.go | 17 +++++++++++------ agent/i18n/lang/en.yaml | 1 + agent/i18n/lang/ja.yaml | 1 + agent/i18n/lang/ko.yaml | 1 + agent/i18n/lang/ms.yaml | 1 + agent/i18n/lang/pt-BR.yaml | 1 + agent/i18n/lang/ru.yaml | 1 + agent/i18n/lang/zh-Hant.yaml | 1 + agent/i18n/lang/zh.yaml | 1 + 10 files changed, 24 insertions(+), 11 deletions(-) diff --git a/agent/app/service/cronjob_backup.go b/agent/app/service/cronjob_backup.go index a49fbf114..857c18d43 100644 --- a/agent/app/service/cronjob_backup.go +++ b/agent/app/service/cronjob_backup.go @@ -60,7 +60,7 @@ func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time, t if err := doAppBackup(&app, task, backupDir, record.FileName, cronjob.ExclusionRules, cronjob.Secret); err != nil { return err } - downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName)) + downloadPath, err := u.uploadCronjobBackFile(cronjob, task, accountMap, path.Join(backupDir, record.FileName)) if err != nil { return err } @@ -101,7 +101,7 @@ func (u *CronjobService) handleWebsite(cronjob model.Cronjob, startTime time.Tim return err } - downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName)) + downloadPath, err := u.uploadCronjobBackFile(cronjob, task, accountMap, path.Join(backupDir, record.FileName)) if err != nil { return err } @@ -149,7 +149,7 @@ func (u *CronjobService) handleDatabase(cronjob model.Cronjob, startTime time.Ti } } - downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, record.FileName)) + downloadPath, err := u.uploadCronjobBackFile(cronjob, task, accountMap, path.Join(backupDir, record.FileName)) if err != nil { return err } @@ -193,7 +193,7 @@ func (u *CronjobService) handleDirectory(cronjob model.Cronjob, startTime time.T record.CronjobID = cronjob.ID record.Name = cronjob.Name record.DownloadAccountID, record.SourceAccountIDs = cronjob.DownloadAccountID, cronjob.SourceAccountIDs - downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(backupDir, fileName)) + downloadPath, err := u.uploadCronjobBackFile(cronjob, task, accountMap, path.Join(backupDir, fileName)) if err != nil { taskItem.LogFailedWithErr("Upload backup file", err) return err @@ -228,7 +228,7 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T record.CronjobID = cronjob.ID record.Name = cronjob.Name record.DownloadAccountID, record.SourceAccountIDs = cronjob.DownloadAccountID, cronjob.SourceAccountIDs - downloadPath, err := u.uploadCronjobBackFile(cronjob, accountMap, path.Join(path.Dir(backupDir), fileName)) + downloadPath, err := u.uploadCronjobBackFile(cronjob, task, accountMap, path.Join(path.Dir(backupDir), fileName)) if err != nil { taskItem.LogFailedWithErr("Upload backup file", err) return err diff --git a/agent/app/service/cronjob_helper.go b/agent/app/service/cronjob_helper.go index c8540ca3f..b91a7a852 100644 --- a/agent/app/service/cronjob_helper.go +++ b/agent/app/service/cronjob_helper.go @@ -262,23 +262,28 @@ func (u *CronjobService) handleSystemClean(cronjob model.Cronjob, taskItem *task taskItem.AddSubTaskWithOps(i18n.GetMsgByKey("HandleSystemClean"), cleanTask, nil, int(cronjob.RetryTimes), time.Duration(cronjob.Timeout)*time.Second) } -func (u *CronjobService) uploadCronjobBackFile(cronjob model.Cronjob, accountMap map[string]backupClientHelper, file string) (string, error) { +func (u *CronjobService) uploadCronjobBackFile(cronjob model.Cronjob, task *task.Task, accountMap map[string]backupClientHelper, file string) (string, error) { defer func() { _ = os.Remove(file) }() + var errItem error accounts := strings.Split(cronjob.SourceAccountIDs, ",") cloudSrc := strings.TrimPrefix(file, global.Dir.TmpDir+"/") for _, account := range accounts { if len(account) != 0 { - global.LOG.Debugf("start upload file to %s, dir: %s", accountMap[account].name, pathUtils.Join(accountMap[account].backupPath, cloudSrc)) - if _, err := accountMap[account].client.Upload(file, pathUtils.Join(accountMap[account].backupPath, cloudSrc)); err != nil { - global.LOG.Errorf("upload file to %s failed, err: %v", accountMap[account].name, err) + _, err := accountMap[account].client.Upload(file, pathUtils.Join(accountMap[account].backupPath, cloudSrc)) + task.LogWithStatus( + i18n.GetMsgWithMap("UploadFile", map[string]interface{}{ + "file": pathUtils.Join(accountMap[account].backupPath, cloudSrc), + "backup": accountMap[account].name, + }), err) + if err != nil { + errItem = err continue } - global.LOG.Debugf("upload successful!") } } - return cloudSrc, nil + return cloudSrc, errItem } func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap map[string]backupClientHelper, record model.BackupRecord) { diff --git a/agent/i18n/lang/en.yaml b/agent/i18n/lang/en.yaml index 9835df840..06769188a 100644 --- a/agent/i18n/lang/en.yaml +++ b/agent/i18n/lang/en.yaml @@ -204,6 +204,7 @@ HandleSystemClean: 'System cache cleanup' SystemLog: 'System Log' CutWebsiteLog: 'Rotate Website Log' FileOrDir: 'Directory / File' +UploadFile: 'Uploading backup file {{ .file }} to {{ .backup }}' #toolbox ErrNotExistUser: 'The current user does not exist, please modify and try again!' diff --git a/agent/i18n/lang/ja.yaml b/agent/i18n/lang/ja.yaml index b7b9d2586..9c7cb5131 100644 --- a/agent/i18n/lang/ja.yaml +++ b/agent/i18n/lang/ja.yaml @@ -204,6 +204,7 @@ HandleSystemClean: 'システム キャッシュのクリーンアップ' SystemLog: 'システムログ' CutWebsiteLog: 'ウェブサイトログのローテーション' FileOrDir: 'ディレクトリ / ファイル' +UploadFile: 'バックアップファイル {{ .file }} を {{ .backup }} にアップロード中' #toolbox ErrNotExistUser: '現在のユーザーは存在しません。変更してもう一度お試しください。' diff --git a/agent/i18n/lang/ko.yaml b/agent/i18n/lang/ko.yaml index 752e984d7..839c96285 100644 --- a/agent/i18n/lang/ko.yaml +++ b/agent/i18n/lang/ko.yaml @@ -204,6 +204,7 @@ HandleSystemClean: '시스템 캐시 정리' SystemLog: '시스템 로그' CutWebsiteLog: '웹사이트 로그 회전' FileOrDir: '디렉터리 / 파일' +UploadFile: '백업 파일 {{ .file }} 을(를) {{ .backup }}(으)로 업로드 중' #도구상자 ErrNotExistUser: '현재 사용자가 존재하지 않습니다. 수정한 후 다시 시도하세요!' diff --git a/agent/i18n/lang/ms.yaml b/agent/i18n/lang/ms.yaml index eea9fb1cc..675af0423 100644 --- a/agent/i18n/lang/ms.yaml +++ b/agent/i18n/lang/ms.yaml @@ -203,6 +203,7 @@ HandleSystemClean: 'Pembersihan cache sistem' SystemLog: 'Log Sistem' CutWebsiteLog: 'Putar Log Laman Web' FileOrDir: 'Direktori / Fail' +UploadFile: 'Muat naik fail sandaran {{ .file }} ke {{ .backup }}' #kotak alat ErrNotExistUser: 'Pengguna semasa tidak wujud, sila ubah suai dan cuba lagi!' diff --git a/agent/i18n/lang/pt-BR.yaml b/agent/i18n/lang/pt-BR.yaml index 1e56e5976..69bd54177 100644 --- a/agent/i18n/lang/pt-BR.yaml +++ b/agent/i18n/lang/pt-BR.yaml @@ -204,6 +204,7 @@ HandleSystemClean: 'Limpeza de cache do sistema' SystemLog: 'Log do Sistema' CutWebsiteLog: 'Rotacionar Log do Website' FileOrDir: 'Diretório / Arquivo' +UploadFile: 'Enviando arquivo de backup {{ .file }} para {{ .backup }}' #caixa de ferramentas ErrNotExistUser: 'O usuário atual não existe, modifique e tente novamente!' diff --git a/agent/i18n/lang/ru.yaml b/agent/i18n/lang/ru.yaml index f73054ff9..b923b18c7 100644 --- a/agent/i18n/lang/ru.yaml +++ b/agent/i18n/lang/ru.yaml @@ -204,6 +204,7 @@ HandleSystemClean: 'Очистка системного кэша' SystemLog: 'Системный лог' CutWebsiteLog: 'Ротация логов сайта' FileOrDir: 'Каталог / Файл' +UploadFile: 'Загрузка файла резервной копии {{ .file }} в {{ .backup }}' #ящик для инструментов ErrNotExistUser: 'Текущий пользователь не существует, измените его и повторите попытку!' diff --git a/agent/i18n/lang/zh-Hant.yaml b/agent/i18n/lang/zh-Hant.yaml index 5e98c0cdf..3716b1680 100644 --- a/agent/i18n/lang/zh-Hant.yaml +++ b/agent/i18n/lang/zh-Hant.yaml @@ -203,6 +203,7 @@ HandleSystemClean: '系統快取清理' SystemLog: '系統日誌' CutWebsiteLog: '切割網站日誌' FileOrDir: '目錄 / 檔案' +UploadFile: '上傳備份文件 {{ .file }} 到 {{ .backup }}' #toolbox ErrNotExistUser: '目前使用者不存在,請修改後重試!' diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml index 82bc7ea60..fe26b9860 100644 --- a/agent/i18n/lang/zh.yaml +++ b/agent/i18n/lang/zh.yaml @@ -203,6 +203,7 @@ HandleSystemClean: "系统缓存清理" SystemLog: "系统日志" CutWebsiteLog: "切割网站日志" FileOrDir: "目录 / 文件" +UploadFile: "上传备份文件 {{ .file }} 到 {{ .backup }}" #toolbox ErrNotExistUser: "当前用户不存在,请修改后重试!"