From dea81bbe154595150a6fed47e32a4e57bae97eca Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Mon, 29 Apr 2019 12:00:54 -0600 Subject: [PATCH] switch to snapshots cmd for checking repo exists Signed-off-by: Steve Kriss --- changelogs/unreleased/1416-skriss | 1 + pkg/restic/command_factory.go | 4 ++-- pkg/restic/command_factory_test.go | 6 +++--- pkg/restic/repository_manager.go | 12 +++++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 changelogs/unreleased/1416-skriss diff --git a/changelogs/unreleased/1416-skriss b/changelogs/unreleased/1416-skriss new file mode 100644 index 000000000..41dde47ed --- /dev/null +++ b/changelogs/unreleased/1416-skriss @@ -0,0 +1 @@ +switch from `restic stats` to `restic snapshots` for checking restic repository existence diff --git a/pkg/restic/command_factory.go b/pkg/restic/command_factory.go index 3c52a3d45..da75f313d 100644 --- a/pkg/restic/command_factory.go +++ b/pkg/restic/command_factory.go @@ -84,9 +84,9 @@ func InitCommand(repoIdentifier string) *Command { } } -func StatsCommand(repoIdentifier string) *Command { +func SnapshotsCommand(repoIdentifier string) *Command { return &Command{ - Command: "stats", + Command: "snapshots", RepoIdentifier: repoIdentifier, } } diff --git a/pkg/restic/command_factory_test.go b/pkg/restic/command_factory_test.go index f35dd6b7b..1b45a4024 100644 --- a/pkg/restic/command_factory_test.go +++ b/pkg/restic/command_factory_test.go @@ -96,10 +96,10 @@ func TestInitCommand(t *testing.T) { assert.Equal(t, "repo-id", c.RepoIdentifier) } -func TestStatsCommand(t *testing.T) { - c := StatsCommand("repo-id") +func TestSnapshotsCommand(t *testing.T) { + c := SnapshotsCommand("repo-id") - assert.Equal(t, "stats", c.Command) + assert.Equal(t, "snapshots", c.Command) assert.Equal(t, "repo-id", c.RepoIdentifier) } diff --git a/pkg/restic/repository_manager.go b/pkg/restic/repository_manager.go index b1f8dce27..fe7b32a97 100644 --- a/pkg/restic/repository_manager.go +++ b/pkg/restic/repository_manager.go @@ -43,7 +43,7 @@ type RepositoryManager interface { // InitRepo initializes a repo with the specified name and identifier. InitRepo(repo *velerov1api.ResticRepository) error - // ConnectToRepo runs the 'restic stats' command against the + // ConnectToRepo runs the 'restic snapshots' command against the // specified repo, and returns an error if it fails. This is // intended to be used to ensure that the repo exists/can be // authenticated to. @@ -184,11 +184,17 @@ func (rm *repositoryManager) InitRepo(repo *velerov1api.ResticRepository) error } func (rm *repositoryManager) ConnectToRepo(repo *velerov1api.ResticRepository) error { - // restic stats requires a non-exclusive lock + // restic snapshots requires a non-exclusive lock rm.repoLocker.Lock(repo.Name) defer rm.repoLocker.Unlock(repo.Name) - return rm.exec(StatsCommand(repo.Spec.ResticIdentifier), repo.Spec.BackupStorageLocation) + snapshotsCmd := SnapshotsCommand(repo.Spec.ResticIdentifier) + // use the '--last' flag to minimize the amount of data fetched since + // we're just validating that the repo exists and can be authenticated + // to. + snapshotsCmd.ExtraFlags = append(snapshotsCmd.ExtraFlags, "--last") + + return rm.exec(snapshotsCmd, repo.Spec.BackupStorageLocation) } func (rm *repositoryManager) CheckRepo(repo *velerov1api.ResticRepository) error {