Support per-job marker-based directory exclusions with --exclude-if-present
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.
.nobackupand.NOBACKUPare 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-tagsmust 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
.nobackupas 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:
- Load the validated marker list from the job metadata.
- Pass it through the existing explicit runner interface.
- Add one argument pair per marker before the archive and source arguments:
--exclude-if-present .nobackup
--exclude-if-present .NOBACKUP
- Log the configured marker names in the job configuration summary.
- 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
.nobackupand.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
.nobackupand.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.