Win10: having issues with restic parsing windows filesystem paths when using the --use-fs-snapshot flag

Hi all,

I’m having some weird issues with restic not accepting windows filesystem paths when the --use-fs-snapshot flag is used:

PS C:\Users> restic --repo C:\restic_repo --use-fs-snapshot backup C:\Morrowind
unknown command "C:\\Morrowind" for "restic"

Putting the path in quotes had no effect:

PS C:\Users> restic --repo C:\restic_repo --use-fs-snapshot backup 'C:\Morrowind'
unknown command "C:\\Morrowind" for "restic"
PS C:\Users> restic --repo C:\restic_repo --use-fs-snapshot backup "C:\Morrowind"
unknown command "C:\\Morrowind" for "restic"

Removing the --use-fs-snapshot flag causes the issue to disappear:

PS C:\Users> restic --repo C:\restic_repo backup C:\Morrowind
enter password for repository:                                                                                          signal interrupt received, cleaning up

Weirdly, I’ve found adding the --verbose flag also fixes the problem:

PS C:\Users> restic --use-fs-snapshot --verbose --repo C:\restic_repo backup C:\Morrowind
open repository
enter password for repository:
signal interrupt received, cleaning up

I also noticed that moving the --repo flag after the --use-fs-snapshot flag causes restic to print an error about the repo path instead of the backup path.

This seems to affect 0.11.0 as well as the latest beta release:

PS C:\Users> restic_0.11.0_windows_amd64.exe --use-fs-snapshot --repo C:\restic_repo backup C:\Morrowind
unknown command "C:\\restic_repo" for "restic"
PS C:\Users> restic_v0.12.0-4-g8eb6a580_windows_amd64.exe --use-fs-snapshot --repo C:\restic_repo backup C:\Morrowind
unknown command "C:\\restic_repo" for "restic"

Is anyone else seeing similar behaviour?

Thanks!

The --use-fs-snapshot option is on the backup command, it’s not a global option for restic in general. So try moving the --use-fs-snapshot part to right after the backup command, and it may work just fine.

Just for reference, if you run restic help you will not see the --use-fs-snapshot option, but when you run restic help backup you will.

Ah, that makes perfect sense. I moved the --use-fs-snapshot option to after backup as you said and it’s working fine now, thanks!

PS C:\Users> restic --repo C:\restic_repo backup C:\Morrowind --use-fs-snapshot
enter password for repository:                                                                                          signal interrupt received, cleaning up

It seems that weird --verbose behaviour has kept my backup script functioning for the last ~5 months despite the --use-fs-snapshot option being in the wrong place :grin:

Can you clarify exactly what your command line looked like during this time?

I had the --use-fs-snapshot right at the beginning of the command line (I’m using a slightly tweaked version of kmwoley’s restic powershell scripts):

& $ResticExe --use-fs-snapshot --verbose -q backup $folder_list --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile 3>&1 2>> $ErrorLog | Tee-Object -Append $SuccessLog

The only reason I noticed something was up was because restic v0.12.0 no longer allows the use of both --verbose and -q together, so I removed --verbose and everything stopped working.

What we’re seeing here is a kind of a hen and egg problem: the --use-fs-snapshot option only exists for the backup command, which makes it a problem to specify it before backup in the command line. Another complicating fact is that command-line options can either be a single flag like --use-fs-snapshot or take a parameter like --parent snapshot. restic uses cobra for the command line handling, which when it parses restic --use-fs-snapshot backup ... now faces the unknown option --use-fs-snapshot. Or is it --use-fs-snapshot backup? Cobra seems to assume the later variant, at least as long as it tries to find the command name.

And that provides the explanation for the initial problem: restic --repo C:\restic_repo --use-fs-snapshot backup C:\Morrowind is parsed as options --repo C:\restic_repo and --use-fs-snapshot backup making C:\Morrowind the first non-option parameter.

Adding --verbose into the mix accidentally fixes the problem: restic --repo C:\restic_repo --use-fs-snapshot --verbose backup C:\Morrowind now parses into options --repo C:\restic_repo and --use-fs-snapshot --verbose and backup as command name. Now that cobra knows the correct command it seems to parse the command line arguments again and arrives at the expected --repo C:\restic_repo, --use-fs-snapshot and --verbose.

Thanks so much for breaking it down like that; restic’s behaviour makes total sense when explained in that manner.