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
This commit is contained in:
yinheli
2025-10-15 10:28:54 +08:00
committed by GitHub
parent 8465e45693
commit 3563fdd7fd
5 changed files with 30 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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