Merge pull request #1676 from bowensong/quiet-skip-scan

Skip archiver.Scan before backup when --quiet is set
This commit is contained in:
Alexander Neumann 2018-03-21 20:45:34 +01:00
commit 5d09fca6a2
4 changed files with 49 additions and 4 deletions

View File

@ -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

View File

@ -451,10 +451,13 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
return true return true
} }
stat, err := archiver.Scan(target, selectFilter, newScanProgress(gopts)) var stat restic.Stat
if !gopts.Quiet {
stat, err = archiver.Scan(target, selectFilter, newScanProgress(gopts))
if err != nil { if err != nil {
return err return err
} }
}
arch := archiver.New(repo) arch := archiver.New(repo)
arch.Excludes = opts.Excludes arch.Excludes = opts.Excludes

View File

@ -1312,3 +1312,38 @@ func linkEqual(source, dest []string) bool {
return true 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)
}

View File

@ -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 ``check`` and ``prune`` will do so unless the quiet flag ``-q`` or
``--quiet`` is set. When running from a non-interactive console progress ``--quiet`` is set. When running from a non-interactive console progress
reporting will be limited to once every 10 seconds to not fill your 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 Additionally on Unix systems if ``restic`` receives a SIGUSR1 signal the
current progress will written to the standard output so you can check up current progress will written to the standard output so you can check up