borg-backup-ui icon indicating copy to clipboard operation
borg-backup-ui copied to clipboard

Support per-job marker-based directory exclusions with --exclude-if-present

Open borg-codex-bot opened this issue 3 months ago • 0 comments

Summary

Add a per-job option for Borg's --exclude-if-present NAME mechanism. This allows users to exclude dynamically discovered directories by placing a marker object such as .nobackup inside them instead of maintaining a separate absolute exclusion path for every directory.

This is especially useful for structures that grow dynamically, for example per-user Nextcloud directories such as files_versions and files_trashbin.

Current behavior

Borg Backup UI currently supports explicit source exclusions. Each configured absolute path is validated as a child of a selected source and translated into a Borg --exclude argument.

The UI does not currently expose --exclude-if-present. Users therefore need to add every matching directory as a separate exclusion even when their existing backup layout already uses marker files.

Borg semantics

For each configured marker name, Borg recursively checks directories below the selected sources. If a directory contains a filesystem object with that name, Borg omits the containing directory and all of its contents from the archive.

Important details:

  • Marker names are case-sensitive. .nobackup and .NOBACKUP are separate entries.
  • More than one marker name can be supplied by repeating --exclude-if-present.
  • Borg omits both the tagged directory contents and the marker object by default.
  • --keep-exclude-tags must not be enabled implicitly. It is not part of this request.
  • Existing explicit path exclusions remain active and are combined with marker-based exclusions.

Reference: https://borgbackup.readthedocs.io/en/1.4-maint/usage/create.html

Proposed user experience

Add a subsection to Job Wizard -> Sources and target -> Exclusions:

  • Label: Exclude directories containing marker files
  • Accept a repeatable list of marker names.
  • Explain that the complete containing directory is skipped recursively.
  • Explain that matching is case-sensitive.
  • Provide .nobackup as an example, but do not enable any marker by default.
  • Show the configured marker names in the flow preview and job summary.

The empty default must preserve the behavior of all existing jobs.

Proposed data model

Store marker names as a job-owned list, for example:

{
  "exclude_if_present": [
    ".nobackup",
    ".NOBACKUP"
  ]
}

The final field name should follow the existing job metadata conventions.

Validation should:

  • reject empty values;
  • reject NUL, CR and LF characters;
  • accept names only, not absolute paths or path traversal components;
  • reject / as part of a marker name;
  • remove exact duplicates while preserving case differences;
  • apply reasonable count and length limits;
  • return a clear localized validation error instead of accepting raw Borg arguments.

Runtime implementation

Extend the existing job metadata, environment handoff and Borg runner without accepting arbitrary command-line input:

  1. Load the validated marker list from the job metadata.
  2. Pass it through the existing explicit runner interface.
  3. Add one argument pair per marker before the archive and source arguments:
--exclude-if-present .nobackup
--exclude-if-present .NOBACKUP
  1. Log the configured marker names in the job configuration summary.
  2. Keep the option independent from file activity output, retention and explicit path exclusions.

Backward compatibility

  • Existing job files without the new field behave exactly as before.
  • Saving an existing job must not add an active default marker.
  • Job import/export and settings backup/restore must preserve the list when present.
  • No migration is required beyond treating a missing field as an empty list.

Tests

Add coverage for:

  • parsing and persistence of zero, one and multiple marker names;
  • case-sensitive entries such as .nobackup and .NOBACKUP;
  • validation of separators, traversal attempts and control characters;
  • exact Borg argument construction without shell interpolation;
  • coexistence with explicit path exclusions;
  • unchanged command construction for existing jobs;
  • wizard creation, editing, summary and localization;
  • job transfer/export round trips where applicable;
  • a focused runtime test proving that a tagged directory is absent while an untagged sibling remains in the archive.

Documentation

Update both user manuals and in-app help with:

  • the difference between explicit path exclusions and marker-based exclusions;
  • the recursive directory behavior;
  • case sensitivity;
  • an example using .nobackup and .NOBACKUP.

Acceptance criteria

  • A user can configure multiple marker names per backup job.
  • Directories containing any configured marker are excluded recursively.
  • Existing explicit exclusions continue to work.
  • Existing jobs remain unchanged unless the option is configured.
  • Invalid marker values cannot become raw Borg command-line arguments.
  • German and English UI text, documentation and tests are included.

borg-codex-bot avatar Sep 05 '26 15:09 borg-codex-bot