From 5c9315ff1c8d8cb4de2f026bb24c1df0317aa269 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:39:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8D=87=E7=BA=A7=E5=AF=BC=E8=87=B4=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98=20(#3744)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/v_1_9.go | 25 ++++++++++++++-------- backend/utils/cloud_storage/client/sftp.go | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index 5a767039e..65e46ecdd 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -272,16 +272,16 @@ var UpdateCronjobSpec = &gormigrate.Migration{ jobs []model.Cronjob backupAccounts []model.BackupAccount ) - mapAccount := make(map[uint]string) + mapAccount := make(map[uint]model.BackupAccount) if err := tx.Find(&jobs).Error; err != nil { return err } _ = tx.Find(&backupAccounts).Error for _, item := range backupAccounts { - mapAccount[item.ID] = item.Type + mapAccount[item.ID] = item } for _, job := range jobs { - if job.KeepLocal && mapAccount[uint(job.TargetDirID)] != constant.Local { + if job.KeepLocal && mapAccount[uint(job.TargetDirID)].Type != constant.Local { if err := tx.Model(&model.Cronjob{}). Where("id = ?", job.ID). Updates(map[string]interface{}{ @@ -316,6 +316,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{ CronjobID: job.ID, Type: "snapshot", Name: job.Name, + FileDir: "system_snapshot", FileName: snap.Name + ".tar.gz", Source: snap.From, BackupType: snap.From, @@ -324,16 +325,22 @@ var UpdateCronjobSpec = &gormigrate.Migration{ } continue } + itemPath := mapAccount[uint(job.TargetDirID)].BackupPath + if itemPath != "/" { + itemPath = strings.TrimPrefix(itemPath, "/") + "/" + } else { + itemPath = "" + } if job.Type == "log" { item := model.BackupRecord{ From: "cronjob", CronjobID: job.ID, Type: "log", Name: job.Name, - FileDir: path.Dir(record.File), + FileDir: path.Dir(strings.TrimPrefix(record.File, itemPath)), FileName: path.Base(record.File), - Source: mapAccount[uint(job.TargetDirID)], - BackupType: mapAccount[uint(job.TargetDirID)], + Source: mapAccount[uint(job.TargetDirID)].Type, + BackupType: mapAccount[uint(job.TargetDirID)].Type, } _ = tx.Create(&item).Error continue @@ -344,14 +351,14 @@ var UpdateCronjobSpec = &gormigrate.Migration{ CronjobID: job.ID, Type: "directory", Name: job.Name, - FileDir: path.Dir(record.File), + FileDir: path.Dir(strings.TrimPrefix(record.File, itemPath)), FileName: path.Base(record.File), - BackupType: mapAccount[uint(job.TargetDirID)], + BackupType: mapAccount[uint(job.TargetDirID)].Type, } if record.FromLocal { item.Source = constant.Local } else { - item.Source = mapAccount[uint(job.TargetDirID)] + item.Source = mapAccount[uint(job.TargetDirID)].Type } _ = tx.Create(&item).Error continue diff --git a/backend/utils/cloud_storage/client/sftp.go b/backend/utils/cloud_storage/client/sftp.go index 243c4f6d5..a05b29243 100644 --- a/backend/utils/cloud_storage/client/sftp.go +++ b/backend/utils/cloud_storage/client/sftp.go @@ -108,7 +108,7 @@ func (s sftpClient) Download(src, target string) (bool, error) { } defer dstFile.Close() - if _, err = io.Copy(srcFile, dstFile); err != nil { + if _, err = io.Copy(dstFile, srcFile); err != nil { return false, err } return true, err