mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 解决升级导致计划任务数据丢失的问题 (#3766)
This commit is contained in:
parent
725ad3f6d9
commit
be53945f0e
@ -290,6 +290,7 @@ var UpdateCronjobSpec = &gormigrate.Migration{
|
|||||||
}).Error; err != nil {
|
}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
job.DefaultDownload = constant.Local
|
||||||
} else {
|
} else {
|
||||||
if err := tx.Model(&model.Cronjob{}).
|
if err := tx.Model(&model.Cronjob{}).
|
||||||
Where("id = ?", job.ID).
|
Where("id = ?", job.ID).
|
||||||
@ -299,11 +300,19 @@ var UpdateCronjobSpec = &gormigrate.Migration{
|
|||||||
}).Error; err != nil {
|
}).Error; err != nil {
|
||||||
return err
|
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" {
|
if job.Type != "directory" && job.Type != "database" && job.Type != "website" && job.Type != "app" && job.Type != "snapshot" && job.Type != "log" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemPath := mapAccount[uint(job.TargetDirID)].BackupPath
|
||||||
|
if job.DefaultDownload == constant.Local || itemPath == "/" {
|
||||||
|
itemPath = ""
|
||||||
|
} else {
|
||||||
|
itemPath = strings.TrimPrefix(itemPath, "/") + "/"
|
||||||
|
}
|
||||||
|
|
||||||
var records []model.JobRecords
|
var records []model.JobRecords
|
||||||
_ = tx.Where("cronjob_id = ?", job.ID).Find(&records).Error
|
_ = tx.Where("cronjob_id = ?", job.ID).Find(&records).Error
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
@ -325,12 +334,6 @@ var UpdateCronjobSpec = &gormigrate.Migration{
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
itemPath := mapAccount[uint(job.TargetDirID)].BackupPath
|
|
||||||
if itemPath != "/" {
|
|
||||||
itemPath = strings.TrimPrefix(itemPath, "/") + "/"
|
|
||||||
} else {
|
|
||||||
itemPath = ""
|
|
||||||
}
|
|
||||||
if job.Type == "log" {
|
if job.Type == "log" {
|
||||||
item := model.BackupRecord{
|
item := model.BackupRecord{
|
||||||
From: "cronjob",
|
From: "cronjob",
|
||||||
@ -367,12 +370,12 @@ var UpdateCronjobSpec = &gormigrate.Migration{
|
|||||||
files := strings.Split(record.File, ",")
|
files := strings.Split(record.File, ",")
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
_ = tx.Model(&model.BackupRecord{}).
|
_ = 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
|
Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_ = tx.Model(&model.BackupRecord{}).
|
_ = 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
|
Updates(map[string]interface{}{"cronjob_id": job.ID, "from": "cronjob"}).Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user