From 3563fdd7fdc974a6ee98ca96e858cd18e48f96ba Mon Sep 17 00:00:00 2001 From: yinheli Date: Wed, 15 Oct 2025 10:28:54 +0800 Subject: [PATCH] fix(cli): make --progress flag visible and use it in sync-to command (#3542) (#4877) * fix(cli): improve progress output control in repository sync and documentation - Update progress flag description from "progress bar" to "progress output" for clarity - Document progress control features in Logging, Synchronization, and Command-Line reference - Support --no-progress flag for cleaner automation and scripting usage --- cli/cli_progress.go | 2 +- cli/command_repository_sync.go | 12 +++++++++++- site/content/docs/Advanced/Logging/_index.md | 4 ++++ site/content/docs/Advanced/Synchronization/_index.md | 4 ++++ site/content/docs/Reference/Command-Line/_index.md | 10 ++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cli/cli_progress.go b/cli/cli_progress.go index 0992e1cb9..b5bb64957 100644 --- a/cli/cli_progress.go +++ b/cli/cli_progress.go @@ -29,7 +29,7 @@ type progressFlags struct { } func (p *progressFlags) setup(svc appServices, app *kingpin.Application) { - app.Flag("progress", "Enable progress bar").Hidden().Default("true").BoolVar(&p.enableProgress) + app.Flag("progress", "Enable progress output").Default("true").BoolVar(&p.enableProgress) app.Flag("progress-estimation-type", "Set type of estimation of the data to be snapshotted").Hidden().Default(upload.EstimationTypeClassic). EnumVar(&p.progressEstimationType, upload.EstimationTypeClassic, upload.EstimationTypeRough, upload.EstimationTypeAdaptive) app.Flag("progress-update-interval", "How often to update progress information").Hidden().Default("300ms").DurationVar(&p.progressUpdateInterval) diff --git a/cli/command_repository_sync.go b/cli/command_repository_sync.go index 4aeeb9b27..f0c2690fc 100644 --- a/cli/command_repository_sync.go +++ b/cli/command_repository_sync.go @@ -34,7 +34,8 @@ type commandRepositorySyncTo struct { lastSyncProgress string syncProgressMutex sync.Mutex - out textOutput + out textOutput + progress *cliProgress } func (c *commandRepositorySyncTo) setup(svc advancedAppServices, parent commandParent) { @@ -47,6 +48,7 @@ func (c *commandRepositorySyncTo) setup(svc advancedAppServices, parent commandP cmd.Flag("times", "Synchronize blob times if supported.").BoolVar(&c.repositorySyncTimes) c.out.setup(svc) + c.progress = svc.getProgress() for _, prov := range svc.storageProviders() { // Set up 'sync-to' subcommand @@ -200,6 +202,10 @@ func (c *commandRepositorySyncTo) beginSyncProgress() { } func (c *commandRepositorySyncTo) outputSyncProgress(s string) { + if !c.progress.Enabled() { + return + } + c.syncProgressMutex.Lock() defer c.syncProgressMutex.Unlock() @@ -215,6 +221,10 @@ func (c *commandRepositorySyncTo) outputSyncProgress(s string) { } func (c *commandRepositorySyncTo) finishSyncProcess() { + if !c.progress.Enabled() { + return + } + c.out.printStderr("\r%v\n", c.lastSyncProgress) } diff --git a/site/content/docs/Advanced/Logging/_index.md b/site/content/docs/Advanced/Logging/_index.md index 5cece55c5..9824b54cd 100644 --- a/site/content/docs/Advanced/Logging/_index.md +++ b/site/content/docs/Advanced/Logging/_index.md @@ -54,3 +54,7 @@ You can control how much data is written to console and log files by using flags By default, console output will be colored to indicate different log levels, this can be disabled (useful when redirecting output to a file) with `--disable-color`. To force color colorized output when redirecting to a file use `--force-color`. +### Progress Output + +Kopia displays progress information during operations such as snapshots and synchronization. This output can be controlled separately from log levels using `--progress` (default) or `--no-progress` flags. This is particularly useful when running Kopia in scripts or scheduled tasks where clean output is preferred. + diff --git a/site/content/docs/Advanced/Synchronization/_index.md b/site/content/docs/Advanced/Synchronization/_index.md index 060ee7efc..3f84a3cf7 100644 --- a/site/content/docs/Advanced/Synchronization/_index.md +++ b/site/content/docs/Advanced/Synchronization/_index.md @@ -30,3 +30,7 @@ When synchronizing to a filesystem location, it is important to check that the f ``` $ kopia repository sync-to filesystem --path /dest/repository --must-exist ``` + +### Automation + +For automated synchronization tasks, progress output can be suppressed using the `--no-progress` flag to provide clean output suitable for cron jobs and scripts. diff --git a/site/content/docs/Reference/Command-Line/_index.md b/site/content/docs/Reference/Command-Line/_index.md index 22be47b63..6ff03bec3 100644 --- a/site/content/docs/Reference/Command-Line/_index.md +++ b/site/content/docs/Reference/Command-Line/_index.md @@ -16,6 +16,16 @@ The following environment variables can be used to configure how Kopia runs: | --------------------------- | ------- | -------------------------------------------------------------------------------------------------------- | | `KOPIA_BYTES_STRING_BASE_2` | `false` | If set to `true`, Kopia will output storage values in binary (base-2). The default is decimal (base-10). | +### Global Flags + +The following flags apply to all Kopia commands: + +| Flag | Description | +| ------------------- | -------------------------------------------------------------------------------------------- | +| `--[no-]progress` | Enable or disable progress output (default: enabled). | +| `--log-level` | Set console log level: `debug`, `info`, `warning`, or `error` (default: `info`). | +| `--config-file` | Override the default configuration file location. | + ### Connecting to Repository Most commands require a [Repository](../../advanced/architecture/) to be connected first. The first time you use Kopia, repository must be created, later on it can be connected to from one or more machines.