Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pkg/backup/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ var (
ErrBackupIsAlreadyExists = errors.New("backup is already exists")
)

func (b *Backuper) resumeExistingBackup(backupName string) bool {
_, checkDownloadErr := os.Stat(path.Join(b.DefaultDataPath, "backup", backupName, "download.state2"))
if errors.Is(checkDownloadErr, os.ErrNotExist) {
log.Warn().Msgf("%s already exists but no download.state2 found, will resume download from scratch", backupName)
} else {
log.Warn().Msgf("%s already exists will try to resume download", backupName)
}
return true
}

func (b *Backuper) Download(backupName string, tablePattern string, partitions []string, schemaOnly, rbacOnly, configsOnly, namedCollectionsOnly, resume bool, hardlinkExistsFiles bool, backupVersion string, commandId int) error {
if pidCheckErr := pidlock.CheckAndCreatePidFile(backupName, "download"); pidCheckErr != nil {
return errors.WithMessage(pidCheckErr, "CheckAndCreatePidFile")
Expand Down Expand Up @@ -87,14 +97,8 @@ func (b *Backuper) Download(backupName string, tablePattern string, partitions [
}
if !b.resume {
return ErrBackupIsAlreadyExists
} else {
_, checkDownloadErr := os.Stat(path.Join(b.DefaultDataPath, "backup", backupName, "download.state2"))
if errors.Is(checkDownloadErr, os.ErrNotExist) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better return here following error

local backup '<name>' exists but download.state2 is missing.
  run `clickhouse-backup delete local <name>` and retry,
  or investigate why the resumable state was lost.

return ErrBackupIsAlreadyExists
}
isResumeExists = true
log.Warn().Msgf("%s already exists will try to resume download", backupName)
}
isResumeExists = b.resumeExistingBackup(backupName)
}
}
startDownload := time.Now()
Expand Down
12 changes: 12 additions & 0 deletions pkg/backup/download_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package backup

import (
"os"
"path"
"regexp"
"testing"
"time"
Expand Down Expand Up @@ -91,6 +93,16 @@ var remoteBackup = storage.Backup{
UploadDate: time.Now(),
}

func TestResumeExistingBackupAllowsMissingStateFile(t *testing.T) {
backupName := "test_resume_crash"
defaultDataPath := t.TempDir()
assert.NoError(t, os.MkdirAll(path.Join(defaultDataPath, "backup", backupName), 0o750))

backuper := &Backuper{DefaultDataPath: defaultDataPath}

assert.True(t, backuper.resumeExistingBackup(backupName))
}

func TestReBalanceTablesMetadataIfDiskNotExists_Files_NoErrors(t *testing.T) {
remoteBackup.DataFormat = "tar"
baseTable := metadata.TableMetadata{
Expand Down
Loading