How to backup an 'ephemeral' folder?

I’m retrieving the backup data in runtime via the before-snapshot action so there is no backup folder in advance (it is created by that ‘before’ script). And according to the before-snapshot action naming I was expecting that the action will be triggered before anything related to the initiated snapshot but it isn’t true and first of all Kopia validates that the snapshot folder exists.

Is there a way to run the before-snapshot action really before?

You are probably doing something wrong… as I use before-snapshot action exactly in this manner and all works. I take filesystem snapshot and mount it to the new folder - which does not exist before.

Share your scripts - maybe somebody can help with it.

And have a look at examples from docs. This is what I used when creating my scripts.

I checked it one more time with:

kopia policy set /path/to/backup --before-snapshot-root-action /path/to/script.sh
kopia policy set /path/to/backup --action-command-mode=essential
kopia policy set /path/to/backup --snapshot-time="13:00"

/path/to/script.sh:
#!/bin/bash
mkdir -p /path/to/backup

This simple setup adjusts the before-action with a script that just creates the /path/to/backup folder which is backed up at 13:00 by kopia server.
Either the snapshot is run at the schedule or manually the result is the same - it fails with:

Error: unable to create local filesystem: unable to determine entry type: lstat /path/to/backup: no such file or directory.

and my before-script didn’t even run (the snapshot run log is empty). If I create the /path/to/backup the snapshot runs just fine.
I’ve already read all documentation multiple times and tried all possible variations of the setup with the same result.

I think you might be right here. This is indeed a bit weird kopia behaviour - and not clearly documented. Should be easy though to work around it by creating your ad hoc folder inside another one you backup.