Negative exclusion with Windows paths

Should negative exclusion work with Windows paths? If so, what is the syntax?

I’m trying to backup my G:, ignoring everything and then not ignoring specific directories:

restic backup --exclude-file .\test.exclude G:

.\test.exclude:

G:\*
!G:\file.txt
!G:\1080p

Only the root directory is included in the backup, no content. So the exclusion pattern (G:\*) works fine, but not the negative patterns. I’ve also tested with forward slashes, same result.

It should work, every exclusion pattern starting with an exclamation mark is considered to be a negative pattern. Which restic version are you using?

What output does the backup command produce if you add --verbose=2?

> restic version
restic 0.14.0 compiled with go1.19 on windows/amd64
> restic backup -r rclone:backup:restic-test --verbose=2 --exclude-file .\test.exclude G: --tag "test" --dry-run
open repository
repository aa0ff484 opened (repository version 2) successfully, password is correct
lock repository
using parent snapshot 3e7ecb64
load index files
start scan on [G:]
start backup on [G:]
scan finished in 2.320s: 0 files, 0 B
unchanged /G/

Files:           0 new,     0 changed,     0 unmodified
Dirs:            0 new,     0 changed,     1 unmodified
Data Blobs:      0 new
Tree Blobs:      0 new
Would add to the repository: 0 B   (0 B   stored)

processed 0 files, 0 B in 0:02

Turns out, negative exclusion works in a subdirectory. With the following content in test.exclude:

G:\1080p\*
!G:\1080p\O3310851.MOV
<every file / directory in G:\ root>

and using the same backup command, the O3310851.MOV is added to the repository, but none of the other files in the 1080p directory:

> restic backup -r rclone:backup:restic-test --verbose=2 --exclude-file .\test.exclude G: --tag "test" --dry-run
open repository
repository aa0ff484 opened (repository version 2) successfully, password is correct
lock repository
using parent snapshot 3e7ecb64
load index files
start scan on [G:]
start backup on [G:]
scan: Open: open \\?\G:\System Volume Information: Åtkomst nekad.
scan finished in 2.167s: 1 files, 98.468 MiB
error: Open: open \\?\G:\System Volume Information: Åtkomst nekad.
new       /G/G:./1080p/O3310851.MOV, saved in 0.670s (98.468 MiB added)
new       /G/G:./1080p/, saved in 0.672s (0 B added, 0 B stored, 2.493 KiB metadata)
new       /G/G:./, saved in 0.675s (0 B added, 0 B stored, 255 B metadata)
modified  /G/, saved in 0.676s (0 B added, 0 B stored, 257 B metadata)

Files:           1 new,     0 changed,     0 unmodified
Dirs:            2 new,     1 changed,     0 unmodified
Data Blobs:     64 new
Tree Blobs:      4 new
Would add to the repository: 98.474 MiB (98.282 MiB stored)

processed 1 files, 98.468 MiB in 0:02
Warning: at least one source file could not be read

But I can’t get it to work in the root of the G: drive…

Can you give the following a try?

G:\?*
!G:\file.txt

But this does look like a bug. Can you open a Github issue for that?

No difference, unfortunately.

Bug report created: Negative exclusion not working in windows drive root · Issue #4127 · restic/restic · GitHub