Skip to content

Commit e66eb00

Browse files
authored
feat: delete the test upload file of the backup account (#7758)
1 parent 680e237 commit e66eb00

File tree

30 files changed

+323
-50
lines changed

30 files changed

+323
-50
lines changed

agent/app/dto/cronjob.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,20 @@ type CronjobInfo struct {
113113
ContainerName string `json:"containerName"`
114114
User string `json:"user"`
115115

116-
AppID string `json:"appID"`
117-
Website string `json:"website"`
118-
ExclusionRules string `json:"exclusionRules"`
119-
DBType string `json:"dbType"`
120-
DBName string `json:"dbName"`
121-
URL string `json:"url"`
122-
IsDir bool `json:"isDir"`
123-
SourceDir string `json:"sourceDir"`
124-
SourceAccounts []string `json:"sourceAccounts"`
125-
DownloadAccount string `json:"downloadAccount"`
126-
RetainCopies int `json:"retainCopies"`
116+
AppID string `json:"appID"`
117+
Website string `json:"website"`
118+
ExclusionRules string `json:"exclusionRules"`
119+
DBType string `json:"dbType"`
120+
DBName string `json:"dbName"`
121+
URL string `json:"url"`
122+
IsDir bool `json:"isDir"`
123+
SourceDir string `json:"sourceDir"`
124+
RetainCopies int `json:"retainCopies"`
125+
126+
SourceAccounts []string `json:"sourceAccounts"`
127+
DownloadAccount string `json:"downloadAccount"`
128+
SourceAccountIDs string `json:"sourceAccountIDs"`
129+
DownloadAccountID uint `json:"downloadAccountID"`
127130

128131
LastRecordStatus string `json:"lastRecordStatus"`
129132
LastRecordTime string `json:"lastRecordTime"`

agent/app/service/backup.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (u *BackupService) RefreshToken(req dto.OperateByID) error {
314314
}
315315

316316
func (u *BackupService) checkBackupConn(backup *model.BackupAccount) (bool, error) {
317-
client, err := newClient(backup)
317+
client, err := newClient(backup, false)
318318
if err != nil {
319319
return false, err
320320
}
@@ -340,7 +340,12 @@ func (u *BackupService) checkBackupConn(backup *model.BackupAccount) (bool, erro
340340
if backup.Type != constant.Sftp && backup.Type != constant.Local && targetPath != "/" {
341341
targetPath = strings.TrimPrefix(targetPath, "/")
342342
}
343-
return client.Upload(fileItem, targetPath)
343+
344+
if _, err := client.Upload(fileItem, targetPath); err != nil {
345+
return false, err
346+
}
347+
_, _ = client.Delete(path.Join(backup.BackupPath, "test"))
348+
return true, nil
344349
}
345350

346351
func (u *BackupService) Sync(req dto.SyncFromMaster) error {
@@ -408,7 +413,7 @@ func (u *BackupService) CheckUsed(id uint) error {
408413

409414
func NewBackupClientWithID(id uint) (*model.BackupAccount, cloud_storage.CloudStorageClient, error) {
410415
account, _ := backupRepo.Get(repo.WithByID(id))
411-
backClient, err := newClient(&account)
416+
backClient, err := newClient(&account, true)
412417
if err != nil {
413418
return nil, nil, err
414419
}
@@ -433,7 +438,7 @@ func NewBackupClientMap(ids []string) (map[string]backupClientHelper, error) {
433438
accounts, _ = backupRepo.List(repo.WithByIDs(idItems))
434439
clientMap := make(map[string]backupClientHelper)
435440
for _, item := range accounts {
436-
backClient, err := newClient(&item)
441+
backClient, err := newClient(&item, true)
437442
if err != nil {
438443
return nil, err
439444
}
@@ -448,7 +453,7 @@ func NewBackupClientMap(ids []string) (map[string]backupClientHelper, error) {
448453
return clientMap, nil
449454
}
450455

451-
func newClient(account *model.BackupAccount) (cloud_storage.CloudStorageClient, error) {
456+
func newClient(account *model.BackupAccount, isEncrypt bool) (cloud_storage.CloudStorageClient, error) {
452457
varMap := make(map[string]interface{})
453458
if len(account.Vars) != 0 {
454459
if err := json.Unmarshal([]byte(account.Vars), &varMap); err != nil {
@@ -457,8 +462,10 @@ func newClient(account *model.BackupAccount) (cloud_storage.CloudStorageClient,
457462
}
458463
varMap["bucket"] = account.Bucket
459464
varMap["backupPath"] = account.BackupPath
460-
account.AccessKey, _ = encrypt.StringDecrypt(account.AccessKey)
461-
account.Credential, _ = encrypt.StringDecrypt(account.Credential)
465+
if isEncrypt {
466+
account.AccessKey, _ = encrypt.StringDecrypt(account.AccessKey)
467+
account.Credential, _ = encrypt.StringDecrypt(account.Credential)
468+
}
462469
switch account.Type {
463470
case constant.Sftp, constant.WebDAV:
464471
varMap["username"] = account.AccessKey

core/app/service/backup.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ func (u *BackupService) checkBackupConn(backup *model.BackupAccount) (bool, erro
357357
if backup.Type != constant.Sftp && backup.Type != constant.Local && targetPath != "/" {
358358
targetPath = strings.TrimPrefix(targetPath, "/")
359359
}
360-
return client.Upload(fileItem, targetPath)
360+
if _, err := client.Upload(fileItem, targetPath); err != nil {
361+
return false, err
362+
}
363+
_, _ = client.Delete(path.Join(backup.BackupPath, "test"))
364+
return true, nil
361365
}
362366

363367
func syncAccountToAgent(backup model.BackupAccount, operation string) {

core/app/task/task.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,37 +207,37 @@ func (t *Task) DeleteLogFile() {
207207

208208
func (t *Task) LogWithStatus(msg string, err error) {
209209
if err != nil {
210-
t.Logger.Printf(i18n.GetWithNameAndErr("FailedStatus", msg, err))
210+
t.Logger.Print(i18n.GetWithNameAndErr("FailedStatus", msg, err))
211211
} else {
212-
t.Logger.Printf(i18n.GetWithName("SuccessStatus", msg))
212+
t.Logger.Print(i18n.GetWithName("SuccessStatus", msg))
213213
}
214214
}
215215

216216
func (t *Task) Log(msg string) {
217-
t.Logger.Printf(msg)
217+
t.Logger.Print(msg)
218218
}
219219

220220
func (t *Task) Logf(format string, v ...any) {
221221
t.Logger.Printf(format, v...)
222222
}
223223

224224
func (t *Task) LogFailed(msg string) {
225-
t.Logger.Printf(msg + i18n.GetMsgByKey("Failed"))
225+
t.Logger.Print(msg + i18n.GetMsgByKey("Failed"))
226226
}
227227

228228
func (t *Task) LogFailedWithErr(msg string, err error) {
229-
t.Logger.Printf(fmt.Sprintf("%s %s : %s", msg, i18n.GetMsgByKey("Failed"), err.Error()))
229+
t.Logger.Printf("%s %s : %s", msg, i18n.GetMsgByKey("Failed"), err.Error())
230230
}
231231

232232
func (t *Task) LogSuccess(msg string) {
233-
t.Logger.Printf(msg + i18n.GetMsgByKey("Success"))
233+
t.Logger.Print(msg + i18n.GetMsgByKey("Success"))
234234
}
235235
func (t *Task) LogSuccessF(format string, v ...any) {
236-
t.Logger.Printf(fmt.Sprintf(format, v...) + i18n.GetMsgByKey("Success"))
236+
t.Logger.Print(fmt.Sprintf(format, v...) + i18n.GetMsgByKey("Success"))
237237
}
238238

239239
func (t *Task) LogStart(msg string) {
240-
t.Logger.Printf(fmt.Sprintf("%s%s", i18n.GetMsgByKey("Start"), msg))
240+
t.Logger.Printf("%s%s", i18n.GetMsgByKey("Start"), msg)
241241
}
242242

243243
func (t *Task) LogWithOps(operate, msg string) {

core/i18n/i18n.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package i18n
22

33
import (
44
"embed"
5+
"fmt"
56
"strings"
67

78
"github.com/1Panel-dev/1Panel/core/global"
@@ -64,9 +65,10 @@ func GetErrMsg(key string, maps map[string]interface{}) string {
6465
}
6566

6667
func GetMsgByKey(key string) string {
67-
content, _ := global.I18n.Localize(&i18n.LocalizeConfig{
68+
content, err := global.I18n.Localize(&i18n.LocalizeConfig{
6869
MessageID: key,
6970
})
71+
fmt.Println(err)
7072
return content
7173
}
7274

@@ -132,6 +134,7 @@ func Init() {
132134
_, _ = bundle.LoadMessageFileFS(fs, "lang/ru.yaml")
133135
_, _ = bundle.LoadMessageFileFS(fs, "lang/ms.yaml")
134136
_, _ = bundle.LoadMessageFileFS(fs, "lang/ko.yaml")
137+
global.I18n = i18n.NewLocalizer(bundle, "en")
135138
}
136139

137140
func UseI18nForCmd(lang string) {

core/i18n/lang/en.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ErrBackupCheck: "Backup account connection test failed {{ .err}}"
2828
ErrBackupLocal: "Local backup account does not support this operation!"
2929
ErrBackupPublic: "Non-public backup account detected, please check and retry!"
3030
ErrOSSConn: "Cannot retrieve latest version, please check if the server can connect to external network."
31-
ErrEntrance: "Security entrance error, please check and retry!"
3231

3332
#license
3433
ErrLicense: "License format error, please check and retry!"

core/i18n/lang/ja.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ErrBackupCheck: "バックアップアカウントの接続テストに失敗し
2828
ErrBackupLocal: "ローカルサーバーのバックアップアカウントはこの操作をサポートしていません!"
2929
ErrBackupPublic: "バックアップアカウントが公開ではないことが検出されました、確認して再試行してください!"
3030
ErrOSSConn: "最新バージョンを取得できませんでした、サーバーが外部ネットワークに接続できるか確認してください。"
31-
ErrEntrance: "セキュアエントランス情報エラー、確認して再試行してください!"
3231

3332
#license
3433
ErrLicense: "ライセンスフォーマットエラー、確認して再試行してください!"

core/i18n/lang/ko.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ErrBackupCheck: "백업 계정 연결 테스트 실패 {{ .err}}"
2828
ErrBackupLocal: "로컬 서버 백업 계정은 현재 작업을 지원하지 않습니다!"
2929
ErrBackupPublic: "이 백업 계정이 공용이 아님을 감지했습니다. 다시 확인하고 시도해 주세요!"
3030
ErrOSSConn: "최신 버전을 가져올 수 없습니다. 서버가 외부 네트워크에 연결되어 있는지 확인하세요."
31-
ErrEntrance: "보안 입구 정보가 잘못되었습니다. 다시 확인하고 시도해 주세요!"
3231

3332
#license
3433
ErrLicense: "라이선스 형식이 잘못되었습니다. 다시 확인하고 시도해 주세요!"

core/i18n/lang/ms.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ErrBackupCheck: "Cubaan sambungan akaun sandaran gagal {{ .err}}"
2828
ErrBackupLocal: "Akaun sandaran pelayan tempatan tidak menyokong operasi ini!"
2929
ErrBackupPublic: "Akaun sandaran ini didapati bukan awam, sila semak dan cuba lagi!"
3030
ErrOSSConn: "Tidak dapat mendapatkan versi terkini, sila pastikan pelayan boleh disambung ke rangkaian luar."
31-
ErrEntrance: "Maklumat pintu masuk selamat salah, sila semak dan cuba lagi!"
3231

3332
#license
3433
ErrLicense: "Format lesen salah, sila semak dan cuba lagi!"

core/i18n/lang/pt-BR.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ErrBackupCheck: "Falha na conexão de teste da conta de backup {{ .err}}"
2828
ErrBackupLocal: "A conta de backup do servidor local não suporta essa operação!"
2929
ErrBackupPublic: "Detectamos que a conta de backup não é pública, verifique e tente novamente!"
3030
ErrOSSConn: "Não foi possível obter a versão mais recente, verifique se o servidor pode se conectar à rede externa."
31-
ErrEntrance: "Erro nas informações de entrada de segurança, verifique e tente novamente!"
3231

3332
#license
3433
ErrLicense: "Erro no formato da licença, verifique e tente novamente!"

0 commit comments

Comments
 (0)