From 14aa6f2a00daa27da8f319fa25b6293703baf4c6 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Wed, 14 Sep 2022 17:20:11 +0200 Subject: [PATCH] add --disable-scanner to backup command The scanner process has only cosmetic effect for the progress printer, and can be disabled without impacting functionality when the user does not need an estimate of completion. In many cases the scanner process can provide beneficial priming of the file system cache, so as general advice it should not be disabled. However, tests have shown that backup of NFS and fuse based filesystems, where stat(2) is relatively expensive, can be significantly faster without the scanner. --- changelog/unreleased/pull-3931 | 8 ++++++++ cmd/restic/cmd_backup.go | 20 ++++++++++++-------- doc/040_backup.rst | 11 ++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 changelog/unreleased/pull-3931 diff --git a/changelog/unreleased/pull-3931 b/changelog/unreleased/pull-3931 new file mode 100644 index 000000000..ca1e27314 --- /dev/null +++ b/changelog/unreleased/pull-3931 @@ -0,0 +1,8 @@ +Enhancement: Allow backup file tree scanner to be disabled + +Restic walks the file tree in a separate scanner process to find the total size +and file/directory count, and uses that to provide an ETA. This can slow down +backups, especially of network filesystems. The new flag `--no-scan` +can be used to speed up such backups. + +https://github.com/restic/restic/pull/3931 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 2a1e703eb..c2c973c7d 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -99,6 +99,7 @@ type BackupOptions struct { UseFsSnapshot bool DryRun bool ReadConcurrency uint + NoScan bool } var backupOptions BackupOptions @@ -138,6 +139,7 @@ func init() { f.BoolVar(&backupOptions.IgnoreInode, "ignore-inode", false, "ignore inode number changes when checking for modified files") f.BoolVar(&backupOptions.IgnoreCtime, "ignore-ctime", false, "ignore ctime changes when checking for modified files") f.BoolVarP(&backupOptions.DryRun, "dry-run", "n", false, "do not upload or write any data, just show what would be done") + f.BoolVar(&backupOptions.NoScan, "no-scan", false, "do not run scanner to estimate size of backup") if runtime.GOOS == "windows" { f.BoolVar(&backupOptions.UseFsSnapshot, "use-fs-snapshot", false, "use filesystem snapshot where possible (currently only Windows VSS)") } @@ -586,16 +588,18 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter targets = []string{filename} } - sc := archiver.NewScanner(targetFS) - sc.SelectByName = selectByNameFilter - sc.Select = selectFilter - sc.Error = progressPrinter.ScannerError - sc.Result = progressReporter.ReportTotal + if !opts.NoScan { + sc := archiver.NewScanner(targetFS) + sc.SelectByName = selectByNameFilter + sc.Select = selectFilter + sc.Error = progressPrinter.ScannerError + sc.Result = progressReporter.ReportTotal - if !gopts.JSON { - progressPrinter.V("start scan on %v", targets) + if !gopts.JSON { + progressPrinter.V("start scan on %v", targets) + } + wg.Go(func() error { return sc.Scan(cancelCtx, targets) }) } - wg.Go(func() error { return sc.Scan(cancelCtx, targets) }) arch := archiver.New(repo, targetFS, archiver.Options{ReadConcurrency: backupOptions.ReadConcurrency}) arch.SelectByName = selectByNameFilter diff --git a/doc/040_backup.rst b/doc/040_backup.rst index 1b0888f6a..e038e1485 100644 --- a/doc/040_backup.rst +++ b/doc/040_backup.rst @@ -204,8 +204,17 @@ Combined with ``--verbose``, you can see a list of changes: modified /archive.tar.gz, saved in 0.140s (25.542 MiB added) Would be added to the repository: 25.551 MiB -.. _backup-excluding-files: +Disabling Backup Progress Estimation +************************************ +When you start a backup, restic will concurrently count the number of +files and their total size, which is used to estimate how long it will +take. This will cause some extra I/O, which can slow down backup of +network file systems or fuse mounts. + +- ``--no-scan`` Do not run scanner to estimate size of backup + +.. _backup-excluding-files: Excluding Files ***************