Skip to content

Commit

Permalink
fix(redis): dbmon备份文件清理行为 #8334
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored and iSecloud committed Dec 5, 2024
1 parent 8765faa commit 418a07a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions dbm-services/redis/db-tools/dbmon/pkg/redisbinlogbackup/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,16 @@ func (job *Job) DeleteTooOldBinlogbackup(port int) {
Days15Ago := time.Now().Local().AddDate(0, 0, -15)
mylog.Logger.Debug(fmt.Sprintf("port:%d start DeleteTooOldBinlogbackup", port))

// 15 天以前的,本地文件已删除的,记录直接删除
job.Err = job.sqdb.Where("start_time<=? and local_file_removed=?", Days15Ago, 1).
Delete(&RedisBinlogHistorySchema{}).Error
if job.Err != nil {
job.Err = fmt.Errorf(
"DeleteTooOldBinlogbackup gorm delete fail,err:%v,start_time:(%s) local_file_removed:%d",
job.Err, Days15Ago, 1)
mylog.Logger.Error(job.Err.Error())
return
}
// OldFileLeftDay天以以前的,本地文件未删除的,remove本地文件,并记录下该行为
job.Err = job.sqdb.Where("start_time<=? and local_file_removed=?", NDaysAgo, 0).Find(&toDoRows).Error
job.Err = job.sqdb.Where("end_time<=? and local_file_removed=?", NDaysAgo, 0).Find(&toDoRows).Error
if job.Err != nil && job.Err != gorm.ErrRecordNotFound {
job.Err = fmt.Errorf("DeleteTooOldBinlogbackup gorm find fail,err:%v", job.Err)
mylog.Logger.Error(job.Err.Error())
return
}
job.Err = nil
for _, row := range toDoRows {
mylog.Logger.Info(fmt.Sprintf("begin delete old file:%s,4 ModfyTime:%s", row.BackupFile, row.EndTime.GoString()))
removeOK = true
if util.FileExists(row.BackupFile) {
err = os.Remove(row.BackupFile)
Expand All @@ -312,4 +303,15 @@ func (job *Job) DeleteTooOldBinlogbackup(port int) {
mylog.Logger.Error(job.Err.Error())
}
}

// 15 天以前的,本地文件已删除的,记录直接删除
job.Err = job.sqdb.Where("end_time<=? and local_file_removed=?", Days15Ago, 1).
Delete(&RedisBinlogHistorySchema{}).Error
if job.Err != nil {
job.Err = fmt.Errorf(
"DeleteTooOldBinlogbackup gorm delete fail,err:%v,start_time:(%s) local_file_removed:%d",
job.Err, Days15Ago, 1)
mylog.Logger.Error(job.Err.Error())
return
}
}

0 comments on commit 418a07a

Please sign in to comment.