Skip to content

Commit

Permalink
set RPO to cron duration if it is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
qrort committed Dec 16, 2024
1 parent 9a33f48 commit 8f0a13c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/integration/make_backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ func main() {
log.Panicf("schedule and listed schedule ids does not match: %s, %s", schedules.Schedules[0].Id, schedule.Id)
}

if schedules.Schedules[0].ScheduleSettings.RecoveryPointObjective.AsDuration() != time.Minute {
log.Panicf("wrong recovery point objective: %v", schedules.Schedules[0].ScheduleSettings.RecoveryPointObjective)
}

newScheduleName := "schedule-2.0"
newSourcePath := "/kv_test"
newSchedule, err := scheduleClient.UpdateBackupSchedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package backup_schedule

import (
"context"
"fmt"
"github.com/jonboulle/clockwork"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"google.golang.org/protobuf/types/known/durationpb"
"strconv"
"time"
"ydbcp/internal/auth"
Expand Down Expand Up @@ -133,6 +135,7 @@ func (s *BackupScheduleService) CreateBackupSchedule(
s.IncApiCallsCounter(methodName, codes.FailedPrecondition)
return nil, status.Error(codes.FailedPrecondition, "recovery point objective should be greater than 0")
}

var scheduleName *string
if len(request.ScheduleName) > 0 {
scheduleName = &request.ScheduleName
Expand All @@ -154,6 +157,14 @@ func (s *BackupScheduleService) CreateBackupSchedule(
ScheduleSettings: request.ScheduleSettings,
}

if schedule.ScheduleSettings.RecoveryPointObjective == nil {
duration, err := schedule.GetCronDuration()
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to get cron duration: %v", err))
}
schedule.ScheduleSettings.RecoveryPointObjective = durationpb.New(duration)
}

_, err = backup_operations.OpenConnAndValidateSourcePaths(ctx, backup_operations.FromBackupSchedule(&schedule), s.clientConn)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8f0a13c

Please sign in to comment.