Skip to content

Commit

Permalink
Merge pull request #71 from ydb-platform/feature/NBYDB-403
Browse files Browse the repository at this point in the history
feat(api): add ttl field to MakeBackupRequest
  • Loading branch information
ulya-sidorina authored Sep 25, 2024
2 parents d913588 + 1f8aed0 commit fe60c5d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 76 deletions.
6 changes: 3 additions & 3 deletions internal/backup_operations/make_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func MakeBackup(
allowedEndpointDomains []string,
allowInsecureEndpoint bool,
req *pb.MakeBackupRequest, scheduleId *string,
subject string, ttl *time.Duration,
subject string,
) (*types.Backup, *types.TakeBackupOperation, error) {
if !IsAllowedEndpoint(req.DatabaseEndpoint, allowedEndpointDomains, allowInsecureEndpoint) {
xlog.Error(
Expand Down Expand Up @@ -145,9 +145,9 @@ func MakeBackup(
xlog.Info(ctx, "Export operation started")

var expireAt *time.Time
if ttl != nil {
if ttl := req.GetTtl(); ttl != nil {
expireAt = new(time.Time)
*expireAt = time.Now().Add(*ttl)
*expireAt = time.Now().Add(ttl.AsDuration())
}

now := timestamppb.Now()
Expand Down
10 changes: 5 additions & 5 deletions internal/handlers/schedule_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"context"
"google.golang.org/protobuf/types/known/durationpb"
"time"
"ydbcp/internal/backup_operations"
"ydbcp/internal/config"
Expand Down Expand Up @@ -43,10 +44,9 @@ func BackupScheduleHandler(
now := time.Now()
// do not handle last_backup_id status = (failed | deleted) for now, just do backups on cron.
if schedule.NextLaunch != nil && schedule.NextLaunch.Before(now) {
var ttl *time.Duration
if schedule.ScheduleSettings != nil && schedule.ScheduleSettings.Ttl != nil {
ttl = new(time.Duration)
*ttl = schedule.ScheduleSettings.Ttl.AsDuration()
var ttl *durationpb.Duration
if schedule.ScheduleSettings != nil {
ttl = schedule.ScheduleSettings.Ttl
}

b, op, err := backup_operations.MakeBackup(
Expand All @@ -56,8 +56,8 @@ func BackupScheduleHandler(
DatabaseEndpoint: schedule.DatabaseEndpoint,
SourcePaths: schedule.SourcePaths,
SourcePathsToExclude: schedule.SourcePathsToExclude,
Ttl: ttl,
}, &schedule.ID, types.OperationCreatorName, //TODO: who to put as subject here?
ttl,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/server/services/backup/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *BackupService) MakeBackup(ctx context.Context, req *pb.MakeBackupReques
ctx = xlog.With(ctx, zap.String("SubjectID", subject))

backup, op, err := backup_operations.MakeBackup(
ctx, s.clientConn, s.s3, s.allowedEndpointDomains, s.allowInsecureEndpoint, req, nil, subject, nil,
ctx, s.clientConn, s.s3, s.allowedEndpointDomains, s.allowInsecureEndpoint, req, nil, subject,
)

if err != nil {
Expand Down
150 changes: 83 additions & 67 deletions pkg/proto/ydbcp/v1alpha1/backup_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/proto/ydbcp/v1alpha1/backup_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ option go_package = "github.com/ydb-platform/ydbcp/pkg/proto/ydbcp/v1alpha1;ydbc

import "ydbcp/v1alpha1/backup.proto";
import "ydbcp/v1alpha1/operation.proto";
import "google/protobuf/duration.proto";

// A set of methods for managing backups;.
service BackupService {
Expand Down Expand Up @@ -52,6 +53,7 @@ message MakeBackupRequest {
repeated string source_paths = 4; // [(size) = "<=256"];
// Regexp for paths excluded from backup.
repeated string source_paths_to_exclude = 5; // [(size) = "<=256"];
google.protobuf.Duration ttl = 6;
}

message DeleteBackupRequest {
Expand Down

0 comments on commit fe60c5d

Please sign in to comment.