Skip to content

Commit

Permalink
feat(ydbcp): do not call export with empty source paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ulya-sidorina committed Oct 14, 2024
1 parent c4cb49b commit 11d3617
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/integration/make_backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"log"
"time"

Expand Down Expand Up @@ -45,6 +47,24 @@ func main() {
if len(backups.Backups) > 0 {
log.Panicf("got backup from empty YDBCP: %s", backups.Backups[0].String())
}

_, err = client.MakeBackup(
context.Background(), &pb.MakeBackupRequest{
ContainerId: containerID,
DatabaseName: databaseName,
DatabaseEndpoint: databaseEndpoint,
SourcePaths: nil,
SourcePathsToExclude: []string{".+"}, // exclude all paths
},
)
if err == nil {
log.Panicf("backup with empty source paths was created")
}

if status.Code(err) != codes.FailedPrecondition {
log.Panicf("unexpected error code: %v", err)
}

backupOperation, err := client.MakeBackup(
context.Background(), &pb.MakeBackupRequest{
ContainerId: containerID,
Expand Down
5 changes: 5 additions & 0 deletions internal/backup_operations/make_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func MakeBackup(
return nil, nil, status.Errorf(codes.Unknown, "error preparing paths for export, dsn %s", dsn)
}

if len(pathsForExport) == 0 {
xlog.Error(ctx, "empty list of paths for export")
return nil, nil, status.Error(codes.FailedPrecondition, "empty list of paths for export")
}

s3Settings := types.ExportSettings{
Endpoint: s3.Endpoint,
Region: s3.Region,
Expand Down
1 change: 1 addition & 0 deletions internal/handlers/schedule_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestBackupScheduleHandler(t *testing.T) {
Status: types.BackupScheduleStateActive,
DatabaseName: "mydb",
DatabaseEndpoint: "mydb.valid.com",
SourcePaths: []string{"/path/to/table"},
ScheduleSettings: &pb.BackupScheduleSettings{
SchedulePattern: &pb.BackupSchedulePattern{Crontab: "* * * * * *"},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestScheduleWatcherSimple(t *testing.T) {
Status: types.BackupScheduleStateActive,
DatabaseName: "mydb",
DatabaseEndpoint: "mydb.valid.com",
SourcePaths: []string{"/path/to/table"},
ScheduleSettings: &pb.BackupScheduleSettings{
SchedulePattern: &pb.BackupSchedulePattern{Crontab: "* * * * *"}, //every minute
},
Expand Down

0 comments on commit 11d3617

Please sign in to comment.