04 66 72 51 22

Excluding files from a backup: writing a rule (“Invalid mask …”)

This page is intended for administrators who wish to exclude files from a backup, or conversely to back up only certain files: temporary files, caches, videos, old or oversized files. It covers the syntax of the rules, the order in which they are applied, and the error messages generated by a badly written rule.

What you will have at the end

A profile that backs up only the files that matter, with clear, verified rules and no mask errors in the report.

Prerequisites

  • A file and folder backup profile.
  • Access to the agent configuration in the web interface.

Where to enter the rules

In the web interface, open the agent configuration for the medium. The Inclusion and exclusion rules block lists the rules. You can either:

  • click Add a rule, choose inclusion or exclusion, then enter the pattern;
  • or click Select from the tree view and untick the folders to be excluded. Each unticked box adds an exclusion rule, which you can then review and edit.

Steps

1. Writing the pattern

A rule compares a pattern against the full path of each file, for example C:\Users\marie\AppData\Local\Temp\fichier.tmp. The comparison is not case-sensitive.

The pattern accepts two wildcards:

  • * stands for any sequence of characters, including folder separators;
  • ? stands for a single character.

Examples:

PatternFiles affected
*.tmpAll files whose name ends in .tmp, in every folder.
C:\Users\*\AppData\Local\Temp\*The contents of every user's temporary folders.
*\node_modules\*The contents of all node_modules folders.
D:\Partage\archive.zipThis single file, with no wildcard.

A pattern without a wildcard must match the file's full path exactly. Writing just archive.zip excludes nothing.

Square brackets have a special meaning in a pattern: […] stands for a single character taken from the list inside the brackets. The pattern C:\Data\[2024]\* therefore does not match C:\Data\[2024]\f.txt, but it does match C:\Data\2\f.txt. To target a folder whose name contains square brackets, replace each bracket with ?: C:\Data\?2024?\*.

2. Choosing between exclusion and inclusion

Exclusion rules are applied first: a file matching one of them is never backed up.

Inclusion rules change how the profile behaves. As soon as a single inclusion rule exists, only items matching at least one inclusion rule are backed up. Everything else is ignored.

These rules also apply to folders, including the source's starting folder: a folder that matches no inclusion is discarded along with all its contents. An inclusion of *.docx on its own therefore backs up nothing, since no folder ends in .docx. Add a second inclusion rule, *\, which keeps all folders:

TypePattern
Inclusion*\
Inclusion*.docx

All folders are then traversed and only .docx files are backed up.

Adding a single inclusion rule to an existing profile can drastically reduce what is backed up, potentially resulting in an empty backup. Review the report of the next backup.

3. Adding a date or size condition

After the pattern, you can add one or more conditions, separated by spaces. The rule then applies only to files meeting all the conditions.

ConditionFiles matched by the rule
-dateinf=Modified before the specified date.
-datesup=Modified after the specified date.
-dateinfore=Modified on or before the specified date.
-datesupore=Modified on or after the specified date.
-sizeinf=Smaller than the specified size, in bytes.
-sizesup=Larger than the specified size, in bytes.
-sizeinfore=Of a size less than or equal, in bytes.
-sizesupore=Of a size greater than or equal, in bytes.

For -dateinf and -datesup, the date is written in dd/mm/yyyy format, or as a number of days relative to the day of the backup. For example, -30 means "30 days ago". For -dateinfore and -datesupore, only the dd/mm/yyyy format is accepted.

Examples:

*.log -dateinf=-30
*.iso -sizesup=1073741824

The first excludes .log files last modified more than 30 days ago. The second excludes .iso files larger than 1,073,741,824 bytes.

Date and size conditions do not protect folders. If the pattern can also match a folder, that folder is discarded in its entirety, whatever the dates of the files it contains. For example, D:\Archives\* -dateinf=-365 discards all the subfolders of D:\Archives. Write a pattern that targets files only, with their extension: D:\Archives\*.pdf -dateinf=-365.

4. Forcing certain files to be re-read

Some files change without their modification date changing, such as certain databases. The @IgnoreLastWriteTime directive, followed by a pattern, forces them to be re-read at every backup. Enter it in the Other commands block:

@IgnoreLastWriteTime D:\Base\*.dat

Limitation: image-based disks

Within a disk backed up as an image, a rule applies only if its pattern starts with that disk's prefix. The web interface indicates this when the profile contains such a disk.

Checking that it worked

Run a backup, then read its report. It must not contain any of the following lines:

  • Invalid "Exclusion" mask "…".
  • Invalid "Inclusion" mask "…".
  • Invalid "Ignore last write time" mask "…".
  • The file "…" generated an error while the exclusion filters were being checked. This error may also be related to its modification date (…). The file will not be backed up.

The mask is quoted in lower case in these lines. The consequences differ according to the type of rule:

  • an invalid exclusion is ignored: it excludes nothing;
  • an invalid inclusion still counts as an inclusion, but matches nothing: if it is the profile's only inclusion, nothing at all is backed up.

The most common cause is an opening bracket [ with no closing bracket. Correct the pattern, then run another backup.

Finally, confirm — via a test restore or by browsing the backup's tree view — that the excluded files are no longer present and that the others are still there.

BeBackup is backup built for IT service providers

Backup and restore of workstations, servers, virtual machines and Microsoft 365, encrypted at source with a key we do not hold, on the hosting of your choice.