Wildcards during restore

If I were to back up $env:APPDATA\Code\User\settings.json (VSCode settings), then restore on a different computer with a different username, I would have no way of specifying what file to restore, because $env:APPDATA\Code\User\settings.json would refer to a different path (e.g. C:\Users\usr2\AppData\Code\User\settings.json as opposed to C:\Users\usr1\AppData\Code\User\settings.json).
To mitigate this, one could use wildcards on restore, i.e. get the latest snapshot that matches C:\Users\*\AppData\Code\User\settings.json.
Sadly, wildcards are only supported during backup, unless I’m missing something.

How can I restore regardless of the username?
I have considered tags, but then realized tags are not unique, meaning multiple files can have the same tag.

I’ve tested it, and yes, this can be achieved using tags.
I tag every backed up snapshot with the trailing dir/filename, then restore the latest snapshot for every given tag.

However, this creates a new issue: AFAICT, --files-from-verbatim and --include, which is what I’m using to back up a list of files and directories, do not support tags.
I’ve tried iterating through the list one-by-one but restic is asking for password every time.
It would be helpful if like e.g. kopia, one could enter the password a single time to connect to the repo, then freely back up and restore until the end of session.

Update 2
Encountered another roadblock: if I restore C:\Users\usr1\AppData\Code\User\settings.json to $env:APPDATA\Code\User\settings.json on a usr2 machine, it gets restored to C:\Users\usr2\AppData\Code\User\settings.json\C\Users\usr1\AppData\Code\User\settings.json which is… obviously not what I want.
Is it not possible to just restore the file/directory without all of the parents?

The --include option for restore supports wildcards. But it is only used to select which files in a snapshot are restored but not for the snapshot selection.

I’m not sure what you mean here. Adding a tag to a snapshot work independent of how you select which files belong to a snapshot.

Just set the environment variable “RESTIC_PASSWORD”. Or use some of the other options pass the password to restic automatically.

Currently no. Just move the files around. Or use dump if you want to extract a single file. Although you have to find out how to prevent powershell from messing up the file encoding… (it should just write all data output by restic as is into a file, and not convert any encoding)

What I meant is I can do -r D:\restic backup $env:USERPROFILE\Desktop\file1.txt --tag file1.txt followed by -r D:\restic restore latest --tag file1.txt --target .\restore, then -r D:\restic backup $env:USERPROFILE\Desktop\file2.txt --tag file2.txt followed by -r D:\restic restore latest --tag file2.txt --target .\restore, but I cannot do something like (and this is a very rough example)

$Files = (
$Tags = (
$Entries = New-TemporaryFile
$Files | Out-File $Entries.FullName
restic -r D:\restic backup --files-from-verbatim $Entries --tags $Tags
restic -r D:\restic restore latest --tags $Tags

If I understand the powershell syntax correctly, this results in --tag file1.txt file2.txt which is not the correct syntax to set two tags. Either use --tag file1.txt,file2.txt or --tag file1.txt --tag file2.txt.

Wouldn’t that give both files both tags?
I want the first file to have tag file1.txt and second file to have tag file2.txt.

I understand that’s not correct syntax (hence the “cannot do” part), it was just to illustrate what I’m trying to accomplish.

You can only tag snapshots, not files. So either use a tag to identify a snapshot and then select individual files from the snapshot. Or create individual snapshots for each file, although that seems to be a bit overkill.

Oh, btw, you can pass relative paths to the backup command. That might simplify backups with different path names on different hosts.