@@ -314,7 +314,7 @@ func (u *BackupService) RefreshToken(req dto.OperateByID) error {
314314}
315315
316316func (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
346351func (u * BackupService ) Sync (req dto.SyncFromMaster ) error {
@@ -408,7 +413,7 @@ func (u *BackupService) CheckUsed(id uint) error {
408413
409414func 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
0 commit comments