How you’d achieve that depends on what “exclude directories that are already in source control” means exactly for you. From what you wrote I’m guessing that you mean “all files and sub-directories contained in a directory which has a
.git directory”. That’s only one common case for “directory in source control”, there are many different. For example, for Git, the
.git dir can be anywhere on the local file system.
So, the easiest way you have already discovered:
--exclude-if-present .git takes care of the directory content other that the
.git directory, and
--exclude .git will exclude the
.git dir itself. But this is also not exact, because it means that a file called
.git will also be excluded (together with all other files in the directory).
If you can identify “directories that are already in source control” via another way, it’d be better to write these directories to a file or stdout, and use
--exclude-file, like this:
restic backup --exclude-file <(find /srv -type d -name .git | xargs dirname) /srv
<(...) is a fancy shell way of saying “take the output of the command and make it available as something which resembles a file and return a file name, so the process can be read from it”, this way you don’t have to write an actual file.