|
|
@ -118,6 +118,8 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemFileDir := strings.ReplaceAll(backupDir, localDir+"/", "")
|
|
|
|
if len(record.Name) != 0 {
|
|
|
|
if len(record.Name) != 0 {
|
|
|
|
record.FileName = fileName
|
|
|
|
record.FileName = fileName
|
|
|
|
record.FileDir = backupDir
|
|
|
|
record.FileDir = backupDir
|
|
|
@ -125,7 +127,7 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim
|
|
|
|
record.BackupType = backup.Type
|
|
|
|
record.BackupType = backup.Type
|
|
|
|
if !cronjob.KeepLocal && backup.Type != "LOCAL" {
|
|
|
|
if !cronjob.KeepLocal && backup.Type != "LOCAL" {
|
|
|
|
record.Source = backup.Type
|
|
|
|
record.Source = backup.Type
|
|
|
|
record.FileDir = strings.ReplaceAll(backupDir, localDir+"/", "")
|
|
|
|
record.FileDir = itemFileDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := backupRepo.CreateRecord(&record); err != nil {
|
|
|
|
if err := backupRepo.CreateRecord(&record); err != nil {
|
|
|
|
global.LOG.Errorf("save backup record failed, err: %v", err)
|
|
|
|
global.LOG.Errorf("save backup record failed, err: %v", err)
|
|
|
@ -148,10 +150,13 @@ func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Tim
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return fullPath, err
|
|
|
|
return fullPath, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err = client.Upload(backupDir+"/"+fileName, fullPath); err != nil {
|
|
|
|
if _, err = client.Upload(backupDir+"/"+fileName, itemFileDir+"/"+fileName); err != nil {
|
|
|
|
return fullPath, err
|
|
|
|
return fullPath, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.HandleRmExpired(backup.Type, backupDir, cronjob, client)
|
|
|
|
u.HandleRmExpired(backup.Type, itemFileDir, cronjob, client)
|
|
|
|
|
|
|
|
if cronjob.KeepLocal {
|
|
|
|
|
|
|
|
u.HandleRmExpired("LOCAL", backupDir, cronjob, client)
|
|
|
|
|
|
|
|
}
|
|
|
|
return fullPath, nil
|
|
|
|
return fullPath, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -185,10 +190,8 @@ func (u *CronjobService) HandleRmExpired(backType, backupDir string, cronjob *mo
|
|
|
|
for i := 0; i < len(currentObjs)-int(cronjob.RetainCopies); i++ {
|
|
|
|
for i := 0; i < len(currentObjs)-int(cronjob.RetainCopies); i++ {
|
|
|
|
_, _ = backClient.Delete(currentObjs[i].(string))
|
|
|
|
_, _ = backClient.Delete(currentObjs[i].(string))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !cronjob.KeepLocal {
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(backupDir)
|
|
|
|
files, err := ioutil.ReadDir(backupDir)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("read dir %s failed, err: %v", backupDir, err)
|
|
|
|
global.LOG.Errorf("read dir %s failed, err: %v", backupDir, err)
|
|
|
|