diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index c5f4f0547..00c1bc3c5 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -290,6 +290,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{ }).Error; err != nil { return err } + job.DefaultDownload = constant.Local } else { if err := tx.Model(&model.Cronjob{}). Where("id = ?", job.ID). @@ -299,11 +300,19 @@ var UpdateCronjobSpec = &gormigrate.Migration{ }).Error; err != nil { return err } + job.DefaultDownload = mapAccount[uint(job.TargetDirID)].Type } if job.Type != "directory" && job.Type != "database" && job.Type != "website" && job.Type != "app" && job.Type != "snapshot" && job.Type != "log" { continue } + itemPath := mapAccount[uint(job.TargetDirID)].BackupPath + if job.DefaultDownload == constant.Local || itemPath == "/" { + itemPath = "" + } else { + itemPath = strings.TrimPrefix(itemPath, "/") + "/" + } + var records []model.JobRecords _ = tx.Where("cronjob_id = ?", job.ID).Find(&records).Error for _, record := range records { @@ -325,12 +334,6 @@ 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", @@ -367,12 +370,12 @@ var UpdateCronjobSpec = &gormigrate.Migration{ files := strings.Split(record.File, ",") for _, file := range files { _ = tx.Model(&model.BackupRecord{}). - Where("file_dir = ? AND file_name = ?", path.Dir(file), path.Base(file)). + Where("file_dir = ? AND file_name = ?", path.Dir(strings.TrimPrefix(file, itemPath)), path.Base(file)). Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error } } else { _ = tx.Model(&model.BackupRecord{}). - Where("file_dir = ? AND file_name = ?", path.Dir(record.File), path.Base(record.File)). + Where("file_dir = ? AND file_name = ?", path.Dir(strings.TrimPrefix(record.File, itemPath)), path.Base(record.File)). Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error } }