Exclude file to block folders from Windows drives

If I want to have an exclude file I can reference from multiple scripts that has “common” exclusions in it like:

\$$RECYCLE.BIN
\PROGRA~1
\PROGRA~2

How can I do so? So far nothing I’ve tried seems to work.

Does the --exclude-file flag not do what you want?
https://restic.readthedocs.io/en/stable/040_backup.html#including-and-excluding-files

Here’s an example of a Windows Restic command line that includes some excludes and wildcards

restic.exe --exclude C:\Photos\Rejects --exclude C:\Photos\200* --exclude "C:\Files\Software\Photography Software" --repo D:\Restic\Backup backup C:\Photos

I don’t back up whole disks so I haven’t tried to exclude program files and such. Program files use the format I have above for “Photography Software”, Recycle Bin not sure. Or even better, specify the folders you do want backed up rather than those you don’t.

My command:

restic backup c:\ e:\ --exclude-caches --exclude-file C:\Users\firee\Desktop\restic-exclude.txt

exclude file:

C:\$$RECYCLE.BIN
"C:\Program Files"
"C:\Program Files (x86)"
"C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection"
C:\ProgramData\Microsoft\Diagnosis
C:\Windows\System32\LogFiles
"C:\System Volume Information"

And…restic merrily shows it’s processing C:\Program Files…

What am I doing wrong?

Only on the command line do you need quotes around paths with spaces. In an exclude file, they’re interpreted as literal quotes.
So
"C:\Program Files" in an exclude file
will not match
C:\Program Files.

Remove the quotes and you should be good.

I really wish that were the case…tried deleting the quotes (again - it’s one of the permutations I’ve tried before). And…watching restic happily process my:
/c/Program Files/lots of stuff

Another problem is that restic treats paths case sensitively, while Windows doesn’t.
Try changing your command to restic backup C:\ E:\ ....

When you say restic backup c:\, restic can find the path, but every path will be remembered as starting with a lower case drive letter /c/.... This causes a mismatch with the exclude file you used, which starts with uppercase drive letter C:\....

It’s best to always use the proper case as shown in explorer, and not rely on Windows’ case-insensitive behaviour when using restic.

I struggled with this getting it to match various directories on a Linux server. In the end I used the
–exclude-if-present exclude_from_backup.txt
flag. So by putting a file called exclude_from_backup.txt in any folder, it gets ignored.

I thought I had it. I really did.

I was even all set to humbly apologize. Which I will anyway - but I still need help. TL;DR version - I’m calling restic via a .CMD batch file - what’s the secret to getting Windows to pass the parameters correctly?

I’ve been using restic via scripts. I have some very simple batch files for Windows - but I’ve made a rather nice (in my opinion) shell script for my Linux server. Things were working fine in the Linux world (I thought) so I was convinced I just had a Windows problem.

Turns out…I had a Linux problem as well. The term is “globbing” - and it totally clobbered my Linux exclusions. After educating myself in how to do things properly (sort of) in the POSIX shell world - I got my Linux script actually doing what it was supposed to do. Which brings me back to Windows.

Executing the restic command, with my exclude file, at the command prompt directly…doesn’t work either. So there’s definitely something wrong with either my exclude file or how I’m calling restic.

I even tried moving the backup locations to the end of the command (like it shows in the usage…):

restic backup --exclude-caches --exclude-file C:\Users\firee\Desktop\restic-exclude.txt c:\ e:\ 

But still not working correctly.

As I already said, since you’re using uppercase drive letters in your exclude file, you need to use uppercase drive letters in the command as well. Don’t rely on Windows’ case insensitive behaviour.

Change restic backup c:\ e:\ ... to restic backup C:\ E:\ ... and you should be good.

Maybe I should take the time to actually read the helpful replies when they’re given…

Totally missed that the first time. So now I went through my exclude file and made it all uppercase.

Didn’t work.

Then as I was about to complain again…I re-read your last post…and changed the backup locations to capital drive letters.

Didn’t work.

Then I tried one more time…proper casing the paths in the exclude file…and I think it’s finally working! Thank you!