From 34671d7c9ba690eb0ad1276fe2986aa202800cfc Mon Sep 17 00:00:00 2001 From: Bowen Song Date: Tue, 20 Mar 2018 19:54:29 +0000 Subject: [PATCH] Skip archiver.Scan before backup when --quiet is set --- changelog/unreleased/issue-1160 | 5 +++++ cmd/restic/cmd_backup.go | 9 ++++++--- cmd/restic/integration_test.go | 35 +++++++++++++++++++++++++++++++++ doc/manual_rest.rst | 4 +++- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/issue-1160 diff --git a/changelog/unreleased/issue-1160 b/changelog/unreleased/issue-1160 new file mode 100644 index 000000000..9f7d3d73e --- /dev/null +++ b/changelog/unreleased/issue-1160 @@ -0,0 +1,5 @@ +Enhancement: Improve backup speed by skipping the initial scan when the quiet flag is set + +We've improved the backup speed when the quiet flag -q or --quiet is set by skipping the initial scan which gathers information for displaying the progress bar and the ETA estimation. + +https://github.com/restic/restic/issues/1160 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 4e78a1534..abf392e73 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -451,9 +451,12 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error { return true } - stat, err := archiver.Scan(target, selectFilter, newScanProgress(gopts)) - if err != nil { - return err + var stat restic.Stat + if !gopts.Quiet { + stat, err = archiver.Scan(target, selectFilter, newScanProgress(gopts)) + if err != nil { + return err + } } arch := archiver.New(repo) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 91b610d0d..a48402bc8 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -1312,3 +1312,38 @@ func linkEqual(source, dest []string) bool { return true } + +func TestQuietBackup(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + + datafile := filepath.Join("testdata", "backup-data.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(errors.Cause(err)) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + rtest.OK(t, err) + rtest.OK(t, fd.Close()) + + testRunInit(t, env.gopts) + + rtest.SetupTarTestFixture(t, env.testdata, datafile) + opts := BackupOptions{} + + env.gopts.Quiet = false + testRunBackup(t, []string{env.testdata}, opts, env.gopts) + snapshotIDs := testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 1, + "expected one snapshot, got %v", snapshotIDs) + + testRunCheck(t, env.gopts) + + env.gopts.Quiet = true + testRunBackup(t, []string{env.testdata}, opts, env.gopts) + snapshotIDs = testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 2, + "expected two snapshots, got %v", snapshotIDs) + + testRunCheck(t, env.gopts) +} diff --git a/doc/manual_rest.rst b/doc/manual_rest.rst index 821f220fd..e0d151711 100644 --- a/doc/manual_rest.rst +++ b/doc/manual_rest.rst @@ -107,7 +107,9 @@ Subcommand that support showing progress information such as ``backup``, ``check`` and ``prune`` will do so unless the quiet flag ``-q`` or ``--quiet`` is set. When running from a non-interactive console progress reporting will be limited to once every 10 seconds to not fill your -logs. +logs. Use ``backup`` with the quiet flag ``-q`` or ``--quiet`` can skip +the initial scan of the source directory, this may shorten the backup +time needed for large directories. Additionally on Unix systems if ``restic`` receives a SIGUSR1 signal the current progress will written to the standard output so you can check up