Skip to content

Commit

Permalink
support canceling long-running backup/restore operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vroldanbet committed Nov 6, 2023
1 parent 7225cfb commit 13089c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func backupCmdFunc(cmd *cobra.Command, args []string) error {

var stored uint
for {
if err := ctx.Err(); err != nil {
return fmt.Errorf("aborted backup: %w", err)
}

relsResp, err := relationshipStream.Recv()
if err != nil {
if !errors.Is(err, io.EOF) {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func restoreCmdFunc(cmd *cobra.Command, args []string) error {
var written uint64
var batchesWritten int
for rel, err := decoder.Next(); rel != nil && err == nil; rel, err = decoder.Next() {
if err := ctx.Err(); err != nil {
return fmt.Errorf("aborted restore: %w", err)
}

batch = append(batch, rel)

if len(batch)%batchSize == 0 {
Expand Down

0 comments on commit 13089c8

Please sign in to comment.