1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

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

This commit is contained in:
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 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 { for _, record := range records {
if job.Type == "snapshot" { if job.Type == "snapshot" && job.Status == constant.StatusSuccess {
var snaps []model.Snapshot var snaps []model.Snapshot
_ = tx.Where("name like ?", "snapshot_"+"%").Find(&snaps).Error _ = tx.Where("name like ?", "snapshot_"+"%").Find(&snaps).Error
for _, snap := range snaps { for _, snap := range snaps {
@ -337,7 +337,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{
} }
continue continue
} }
if job.Type == "log" { if job.Type == "log" && job.Status == constant.StatusSuccess {
item := model.BackupRecord{ item := model.BackupRecord{
From: "cronjob", From: "cronjob",
CronjobID: job.ID, CronjobID: job.ID,
@ -354,7 +354,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{
_ = tx.Create(&item).Error _ = tx.Create(&item).Error
continue continue
} }
if job.Type == "directory" { if job.Type == "directory" && job.Status == constant.StatusSuccess {
item := model.BackupRecord{ item := model.BackupRecord{
From: "cronjob", From: "cronjob",
CronjobID: job.ID, CronjobID: job.ID,

View File

@ -34,6 +34,9 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
return nil 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 return &sftpClient{bucket: bucket, connInfo: fmt.Sprintf("%s:%s", address, port), config: clientConfig}, nil
} }