Skip to main content

Setting Up Regex-Based Global Exclusions While Allowing Specific Sub-folders

Setting Up Regex-Based Global Exclusions While Allowing Specific Sub-folders

Updated over a week ago

Overview

The following information contains steps to configure Regular Expression based Global Exclusions so that we exclude a folder but still back up certain subfolders inside it.

Problem Description

Regular Expression–based Global Exclusions can be configured to exclude specific folder paths from backups across all operating systems, including Windows, macOS, and Linux. In certain scenarios, it may be necessary to include a subfolder within an excluded parent folder in the backup set. You can refer to the examples mentioned below.

Cause

If a folder is excluded through a Regular Expression–based Global Exclusion, this exclusion takes precedence over inclusion rules. As a result, the folder and all of its subfolders will not be included in the backup set.

Resolution

Sample Global Exclusion for macOS-based devices -

^/Users/[^/]+/Library/(?!Group Containers$|Application Support$)[^/]+$

What it does -

^/Users/ → Path must start with /Users/

[^/]+ → Matches the username (one folder deep)

/Library/ → Goes into the Library folder

(?!Group Containers$|Application Support$) → Negative lookahead, excludes exactly Group Containers or Application Support

[^/]+$ → Matches any single folder name at the end of the path

So effectively, it matches all first-level folders inside the Library folder except the Group Containers and Application Support folders.

Sample Global Exclusion for Windows OS based devices -

^C:/Users/[^/]+/AppData/Local/(?:(?!Google$|Mozilla$)[^/]+)?(?:/.*)?$

What it does -

C:/Users/ → Matches the literal path prefix C:/Users/.

[^/]+ → Matches one or more characters that are not /.

This represents the Windows username (e.g., John).

/AppData/Local/ → Matches the literal folder path.

(?:(?!Google)[^/]+)? → A non-capturing group that does two things -

(?!Google) → Negative lookahead to ensure the folder name is not "Google".

[^/]+ → Matches one folder name (anything except /).

The ? means this group is optional (can exist once or not at all).

Effectively: “Optionally match all subfolders in the Local folder, but not if it’s named Google or Mozilla.”

Few examples for Windows -

C:/Windows/(?!Prefetch$|System32$|INF$)[^/]*$

The above will exclude all folders present in the C:\Windows folder, but include the Prefetch and System32 folders.

C:/Windows/System32/(?!config$|winevt$|sru$)[^/]*$

The above will exclude all folders present in the C:\Windows\System32 folder, but include the config, winevt and sru folders.

C:/Windows/INF/(?!setupapi$)[^/]*$

The above will exclude all folders present in the C:\Windows\INF folder, but include the setupapi folders.

C:/ProgramData/(?!Microsoft$|ssh$)[^/]*$

The above will exclude all folders present in the C:/ProgramData folder, but include the Microsoft and ssh folders.

Did this answer your question?