Filters in Duplicati

General Concept of Filters

Duplicati 2.0 can include or exclude files and folders from your backup based on so-called filters. A filter can consist of various rules. And a rule decides if a file is to be included to the backup or excluded from it. This decision is made based on the name of the file or folder. Besides these name-based rules there is also a set of specific settings which exclude files with specific attributes (like system files or hidden files) or files that exceed a specific size.

Duplicati’s filter engine processes folders first then files. The reason for that behavior is performance. If a folder is excluded from a backup, the files inside that folder don’t have to be processed anymore.

When filter rules have been defined the first folder is taken and the filter rules are processed one by one. The first rule that matches is applied and the following rules are not processed anymore. For instance, if the first rule excludes a folder, then this folder and all files within will be excluded from the backup even if following rules include this folder or its files.

It is recommended to write folder rules first and file rules afterwards. That way rules are written in the same order as they will be effective when Duplicati processes them and Duplicati’s filters are easier to understand that way.

Per default, all files and folders will be backed up. That means, if no rule matches, the file or folder will be included. In the special case that all rules are include rules (which does not make sense when all files and folders are included per default) Duplicati assumes that all other files and folders are meant to be excluded (this had to be defined as another rule in Duplicati 1.3 but most people found that confusing so we changed that in Duplicati 2.0).

Syntax

If you want to use file globbing to specify rules, ? and * are allowed placeholders. ? matches any single character. * specifies none or multiple characters. Rules can also be specified as regular expression. In this case put the regular expression (using .NET syntax) into hard brackets []. Folder names always end with a slash / on Linux or Mac and a backslash \ on Windows. For instance, log is a file, log/ is a folder. In the UI a rule to include is started with a +, a rule to exclude is started with a -. Using the command-line there are specific settings to specify include or exclude rules. These are --include and --exclude. Using the command-line various rules can be specified using --include or --exclude repeatedly.

Settings

Besides filter rules there are settings that can exclude specific files by their attributes. Those settings are --skip-files-larger-than and --exclude-files-attributes. The latter is able to exclude files that have any of the following attributes: ReadOnly, Hidden, System, Directory, Archive, Device, Normal, Temporary. Those settings are applied to all files of the backup.

Using filters on Windows

Paths in Windows require the backslash \ separator. The %HOME% keyword in the filter path is not supported.

Duplicati does not support the symbolic links created by Windows in the User’s home directory for non-English versions of the OS. To filter the relative folders, use their path addresses:

  • \Desktop
  • \Pictures
  • \Music
  • \Videos
  • \Documents
  • \Contacts
  • \Downloads

The root directory for users is \Users regardless of the language of the OS. For example, to exclude from the backup the Movies and Music folders of the user ‘MickeyMouse’, add the following filters in teh Duplicati Interface:

  • Exclude folder: *\Users\MickeyMouse\Music
  • Exclude folder: *\Users\MickeyMouse\Videos

Common use cases

Exclude specific sub-folders. On your NAS you want to backup all photos. Your photos are stored in hundreds of folders and each of those folders contains a sub-folder called “@eaDir” that contains thumbnails in different sizes that your NAS uses for a web interface. You want to backup your photos but not the thumbnails. In this example you just exclude all thumbnail folders and thus their content. The rule is: -*/@eaDir/. Don’t forget the trailing slash that defines @eaDir as a folder.

Exclude specific files. You store your photos and movies in the same folders. For some reason, you do not want to include the movies into your backup. Depending on why you want to exclude those movies, there are different solutions. First solution is to define a rule like -*.mov or -*.avi. Second solution is to say --skip-files-larger-than=10M which will exclude all files that are larger than 10MB which will probably affect all movies but no photos. Third way is to explicitly say that you only want to include the photos. Then read on how to do that.

Include specific files only. You have a folder structure that contains a lot of photos and movies from your camera. For some reason you only want to include the photos to your backup. The rule for your backup is +*.jpg +*.jpeg. As there are including rules in this filter, Duplicati automatically excludes all other files. This had to be done manually in Duplicati 1.3 which made including rules a little bit difficult for most users.

Include some files, exclude others. Now let’s define a filter that does both of the above. First it excludes @eaDir specifying -*/@eaDir/. Then it includes only JPG files specifying +*.jpg. The problem here is, that Duplicati includes all files and folders per default. This means that e.g. /photos/movie.avi will also be part of the backup. To make the including rule effective an additional rule is required that excludes all files that do not match any of the current rules. The filter must say “exclude this, exclude that, include this but nothing else”. The best rule for “but nothing else” is a regular expression that excludes all files. It is -[.*[^/]] on Linux or Mac, and on Windows the rule is -[.*[^\\]]. The rule says “exclude everything that is not a folder”. The final filter then is -*/@eaDir/ +*.jpg +*.jpeg -[.*[^/]]. Duplicati will process all folders but @eaDir/ and it will include JPG and JPEG files but exclude all other files.

Help with file extension filters (files will only be saved with the necessary extensions), I got confused, there are several options in the drop-down menu, where to write the regular filter?

Hi @Tuber, if you want to use the “normal” filters in the UI, you should use the “Include expression” option.

1 Like

If you mean one as defined in Syntax above, you can use the three-dot-menu Edit as text.

image

which Edit as list interprets as (or you could have entered as):

image

If you mean a regular expression, that’s a more powerful more difficult syntax. Reference is:

.NET regular expressions (Microsoft)

1 Like

Thanks for the explanation!

Just to make sure I’m getting this right:

  • I set up some include filters for only backupping text files like *.txt, *.doc, *.odt and so on (what from my point of view makes a lot of sense :wink: )
  • Duplicati excludes everything else - wonderful, expected behavior

Now I set up a filter for excluding one file, let’s say “mypasswords.txt” - and then all my include filters are just ignored and everything but that one excluded file is backupped? Without any message or hint (like greyed out include filters)?

And to get around I have to use a regex filter .*[^\] to “un-ignore” my include filters?

I mean, this way, for me the risk of unwillingly backupping sensitive data seems to be very present. In the moment I set up one include filter, isn’t it then very clear, that I don’t want to include everything?

Am I getting something wrong?

P.S.: Got it running, everything works fine, just curious.

Welcome to the forum @bilibu_bilibu

You said that you set up more than one include filter. If you meant one exclude:

So adding one exclude gets you out of above special case, so all are included.
If you meant you set only include filters, then clearly you don’t want everything,
but once you muddy intent with a mix of include and exclude, usual rules apply.

Filters in Duplicati in new docs doesn’t detail. It’s in the old docs – and here too.

Sorry, maybe I was not that precise … I meant at least one include filter. Something like this:

+.txt
+
.odt
+*.docx
-passwords.txt

In this example - which for me makes a lot of sense - the three include filters would just be ignored because of the one exclude filter.

I wanted to say: “Give me all the txt and odt and docx files but that one with the passwords.”

Duplicati hears: “Give me everything but the passwords.txt.”

I got it running by adding the .*[^] expression - everything works fine.

It just seems pretty unusual to define that one special case (only include filters) and ignoring stuff when outside of that special case. If you know about that behavior, fine. If not …

I mean, I’m professionally into software for about 26 years and accidentally backupped tons of video and project files from my work directory to a Google drive - sure, I should have RTFM, but usually filters are a pretty intuitive feature.

So my whole intention was making sure, I understood this correctly and that it’s intended this way. I guess I have and that it is, I’m just not a big fan of it :wink: But thanks for the help!

P.S.: I asked a developer, for a quick test:

What files would you think are backupped?

Files:
something.png
nothing.mp4
foo.txt
bar.doc
mypasswords.txt
myotherpasswords.db

Filters:
Include: *.txt *.doc
Exclude: mypasswords.txt

The answer was what I expected: foo.txt and bar.doc

Then I’ll show the code that’s been in Duplicati for 12.

I think that matches the filters documentation above.
After much time and use, changing seems infeasible.

Duplicati does allow more complex filters than some.
This makes it possible to set very hard to read ones,
such as a regex with lookaheads or lookbehinds, etc.
Ordering matters. I’m not sure who thinks about that.
New UI strangely makes fixing order harder than old.

I can’t explain the developer decisions behind design,
however IMO other areas are a bit complex to set up,
resulting from power and flexibility winning over ease.

1 Like

Hm, wasn’t aware of that yet - how could I not love this? Implemented lookarounds make me feel I should have a different perspective on Duplicati. Maybe I had the ordinary consumer too much on my mind (I usually have to), where ease always wins easily. Personally, I prefer power and flexibility.

So thanks, you changed my mind, I’m a fan of this now :slight_smile:

1 Like