'7zip CLI include and exclude file lists

I need to set up a backup with 7zip on a windows server 2012 R2. I have a list of files I want to include and a list of files I want to exclude.

include_list :

\\remoteServer\App1
\\remoteServer\App2
\\remoteServer\App3

exclude_list :

\\remoteServer\App1\folder\file1
\\remoteServer\App1\folder\file2
\\remoteServer\App1\folder\file3
\\remoteServer\App2\folder\file1
\\remoteServer\App2\folder\file2
\\remoteServer\App2\folder\file3

The command I'm using :

7z.exe a -mx9 -tzip save.zip -ir@%include_list% -x@%Exclude_list%

This creates the archive just fine. But it doesn't take into account the exclusion list. No errors are shown.
I need to exclude files because some of them are locked database files, and they generate an errorlevel 1 exit code that I want to get rid of.

Thank you.



Solution 1:[1]

I think you need to add the an "!" point between "-x" and variable like this '-x!%Eclude_list%'.

Solution 2:[2]

It's an old post but I had the same issue today and wanted to share the solution. 7zips logic for excluding files is weird:

You have to specify relative paths, starting at the last subdirectory of a specified include path.

For example, if you want to archive everything in "c:\sub1\sub2" except "bad.txt", you would have to exclude "sub2\bad.txt".

In your example, the exclude filelist would have to look like this:

App1\folder\file1
App1\folder\file2
App1\folder\file3
App2\folder\file1
App2\folder\file2
App2\folder\file3

P.S. the reason might be, that the exclude paths relate to the directory structure of the created archive and not the source file system

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PhP60
Solution 2 Baine Wedlock