feat: SFTP Client 增加可连接性校验 (#3834)

pull/3836/head
ssongliu 2024-02-05 15:54:13 +08:00 committed by GitHub
parent 140cd564da
commit 9e980e8e0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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,

View File

@ -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
}