新增备份监控与定时配置
This commit is contained in:
@@ -12,6 +12,10 @@ func (s *Service) Update(ctx context.Context, actorID uint64, key string, req Up
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
// 备份定时只能通过独立接口修改,避免拥有普通系统配置权限的管理员改变备份策略。
|
||||
if strings.HasPrefix(key, "backup.") {
|
||||
return nil, ErrInvalidConfig
|
||||
}
|
||||
if key == "" || (req.Value == "" && key != "integration.paddle_ocr_token") {
|
||||
return nil, ErrInvalidConfig
|
||||
}
|
||||
@@ -34,3 +38,25 @@ func (s *Service) Update(ctx context.Context, actorID uint64, key string, req Up
|
||||
}
|
||||
return s.repo.Update(ctx, actorID, key, req, meta)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateBackupSchedule(ctx context.Context, actorID uint64, req BackupScheduleDTO, meta AuditMeta) (*BackupScheduleDTO, error) {
|
||||
if s.repo == nil || req.FullHour < 0 || req.FullHour > 23 || req.FullMinute < 0 || req.FullMinute > 59 || req.BinlogIntervalMinutes < 1 || req.BinlogIntervalMinutes > 5 {
|
||||
return nil, ErrInvalidConfig
|
||||
}
|
||||
updates := []struct {
|
||||
key string
|
||||
value string
|
||||
description string
|
||||
}{
|
||||
{"backup.schedule_enabled", strconv.FormatBool(req.Enabled), "在线备份定时任务是否启用"},
|
||||
{"backup.full_hour", strconv.Itoa(req.FullHour), "每日全量备份小时(Asia/Shanghai)"},
|
||||
{"backup.full_minute", strconv.Itoa(req.FullMinute), "每日全量备份分钟(Asia/Shanghai)"},
|
||||
{"backup.binlog_interval_minutes", strconv.Itoa(req.BinlogIntervalMinutes), "binlog 归档间隔分钟(1-5)"},
|
||||
}
|
||||
for _, item := range updates {
|
||||
if _, err := s.repo.Update(ctx, actorID, item.key, UpdateRequest{Value: item.value, Description: item.description}, meta); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user