diff --git a/cli/command_snapshot_create.go b/cli/command_snapshot_create.go index 96f7b25d5..395a250a4 100644 --- a/cli/command_snapshot_create.go +++ b/cli/command_snapshot_create.go @@ -55,7 +55,7 @@ func (c *commandSnapshotCreate) setup(svc appServices, parent commandParent) { cmd := parent.Command("create", "Creates a snapshot of local directory or file.") cmd.Arg("source", "Files or directories to create snapshot(s) of.").StringsVar(&c.snapshotCreateSources) - cmd.Flag("all", "Create snapshots for files or directories previously backed up by this user on this computer").BoolVar(&c.snapshotCreateAll) + cmd.Flag("all", "Create snapshots for files or directories previously backed up by this user on this computer. Cannot be used when a source path argument is also specified.").BoolVar(&c.snapshotCreateAll) cmd.Flag("upload-limit-mb", "Stop the backup process after the specified amount of data (in MB) has been uploaded.").PlaceHolder("MB").Default("0").Int64Var(&c.snapshotCreateCheckpointUploadLimitMB) cmd.Flag("checkpoint-interval", "Interval between periodic checkpoints (must be <= 45 minutes).").Hidden().DurationVar(&c.snapshotCreateCheckpointInterval) cmd.Flag("description", "Free-form snapshot description.").StringVar(&c.snapshotCreateDescription) @@ -89,6 +89,10 @@ func (c *commandSnapshotCreate) setup(svc appServices, parent commandParent) { func (c *commandSnapshotCreate) run(ctx context.Context, rep repo.RepositoryWriter) error { sources := c.snapshotCreateSources + if c.snapshotCreateAll && len(sources) > 0 { + return errors.New("cannot use --all when a source path argument is specified") + } + if err := maybeAutoUpgradeRepository(ctx, rep); err != nil { return errors.Wrap(err, "error upgrading repository") } diff --git a/tests/end_to_end_test/snapshot_create_test.go b/tests/end_to_end_test/snapshot_create_test.go index a8c4539dd..2ec4a2376 100644 --- a/tests/end_to_end_test/snapshot_create_test.go +++ b/tests/end_to_end_test/snapshot_create_test.go @@ -783,3 +783,19 @@ func TestSnapshotCreateAllSnapshotPath(t *testing.T) { require.Equal(t, "/foo/bar", si[2].Path) } } + +func TestSnapshotCreateWithAllAndPath(t *testing.T) { + t.Parallel() + + runner := testenv.NewInProcRunner(t) + e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) + + defer e.RunAndExpectSuccess(t, "repo", "disconnect") + + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) + + // creating a snapshot with a directory and --all should fail + e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1) + e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2) + e.RunAndExpectFailure(t, "snapshot", "create", sharedTestDataDir1, "--all") +}