From 9e980e8e0c2a3b2464b508a29b7961a7e22a2b65 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:54:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SFTP=20Client=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E8=BF=9E=E6=8E=A5=E6=80=A7=E6=A0=A1=E9=AA=8C=20(#3834?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/v_1_9.go | 8 ++++---- backend/utils/cloud_storage/client/sftp.go | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index 5c21f4872..551684811 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -314,9 +314,9 @@ var UpdateCronjobSpec = &gormigrate.Migration{ } var records []model.JobRecords - _ = tx.Where("cronjob_id = ? AND status = ?", job.ID, constant.StatusSuccess).Find(&records).Error + _ = tx.Where("cronjob_id = ?", job.ID).Find(&records).Error for _, record := range records { - if job.Type == "snapshot" { + if job.Type == "snapshot" && job.Status == constant.StatusSuccess { var snaps []model.Snapshot _ = tx.Where("name like ?", "snapshot_"+"%").Find(&snaps).Error for _, snap := range snaps { @@ -337,7 +337,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{ } continue } - if job.Type == "log" { + if job.Type == "log" && job.Status == constant.StatusSuccess { item := model.BackupRecord{ From: "cronjob", CronjobID: job.ID, @@ -354,7 +354,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{ _ = tx.Create(&item).Error continue } - if job.Type == "directory" { + if job.Type == "directory" && job.Status == constant.StatusSuccess { item := model.BackupRecord{ From: "cronjob", CronjobID: job.ID, diff --git a/backend/utils/cloud_storage/client/sftp.go b/backend/utils/cloud_storage/client/sftp.go index 17e828e1a..749e796c8 100644 --- a/backend/utils/cloud_storage/client/sftp.go +++ b/backend/utils/cloud_storage/client/sftp.go @@ -34,6 +34,9 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) { return nil }, } + if _, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", address, port), clientConfig); err != nil { + return nil, err + } return &sftpClient{bucket: bucket, connInfo: fmt.Sprintf("%s:%s", address, port), config: clientConfig}, nil }