Before/after-snapshot-root action logs

I`m trying to setup a before/after-snapshot-root action with no luck: my shell script that’s referenced in the before action fails with an error (Error: upload error: exit status 1) but I cannot find any logs in Kopia that shed the light on the error.
The failed task in the Tasks tab shows only that the before action was called:

19:38:45.166 running action before-snapshot-root on /var/lib/portainer/config_backup policy.ActionCommand{Command:"", Arguments:[]string(nil), Script:"/home/kopia/scripts/portainer_backup_config.sh param1 param2", TimeoutSeconds:60, Mode:"essential"}

and that’s all, i.e. no error output here.
The Kopia logs (in a configured folder) contain only the same ‘1’ error:

ERROR kopia/server snapshot error: snapshot task: upload error: exit status 1

I tried to set the --log-level to ‘info’ to log everything when run the server - same result - no error logs.

The referenced script runs successfully when run manually.

So the question is obvious: how to control the logs verbosity for the task or before action?

Also, a question related to the snapshot+actions basics: the action is called ‘before-snapshot’ so I expected it is run prior to the snapshot but it is not. My scenario is to have a dynamically created folder (/var/lib/portainer/config_backup) which is created by the before action and removed by the after action, but Kopia fails whole snapshot because that folder doesn’t exist when the snapshot initiated. Why???

1 Like

FYI: mkdir -p /var/lib/portainer/config_backup won’t exit 1 if any of the nested dirs already exist.

That’s confirmed via status="$?"; printf "%s\n" "exit code status: $status", immed. post-sh execution, then? Strange. In my case I want Kopia to fail if the sh exit code != “0”.


Set:

kopia policy set "$user@host:$pathToBeSnapshotted" --action-command-timeout=5s --config-file=$HOME/.config/kopia/repository.config --before-snapshot-root-action "$pathToScriptAndPassItsArgs hi hello hola"
Setting policy for $user@host:$pathToBeSnapshotted
 - setting before-snapshot-root (essential) action command to "/pathToScriptAndPassItsArgs" with arguments "hi" "hello" "hola" and timeout 5s

Check:

kopia policy show "$user@host:$pathToBeSnapshotted" --config-file=$HOME/.config/kopia/repository.config | grep -C 3 "essential"
Run command before snapshot root:              (defined for this target)
  Command:
    /pathToScriptAndPassItsArgs hi hello hola
  Mode:                            essential
  Timeout:                                5s

Fire:

time kopia --config-file=$HOME/.config/kopia/repository.config snapshot create $pathToBeSnapshotted; kopia_exit_status="$?"; printf "%s\n" "kopia exit code: $kopia_exit_status"

Scripted passed; 0

Snapshotting $user@host:$pathToBeSnapshotted ...
 * 0 hashing, 0 hashed (0 B), 3 cached (30.3 MB), uploaded 0 B, estimated 30.3 MB (100.0%) 0s left
Created snapshot with root kc9c25d526595cb6114c611ad5d5b6a0f and ID 6f630f9a95dc1392f2e463d6c4fac009 in 1s

real    0m1.285s
user    0m0.217s
sys     0m0.038s
kopia exit code: 0
20250420T200732UTC

Script failed; 1; Kopia doesn’t fire the snapshot:

Snapshotting $user@host:$pathToBeSnapshotted ...
 * 0 hashing, 0 hashed (0 B), 3 cached (30.3 MB), uploaded 0 B, estimated 30.3 MB (100.0%) 0s left
Created snapshot with root kc9c25d526595cb6114c611ad5d5b6a0f and ID 6f630f9a95dc1392f2e463d6c4fac009 in 1s
ERROR upload error: exit status 1

real    0m1.250s
user    0m0.229s
sys     0m0.010s
kopia exit code: 1
20250420T200102UTC

(Posted for future discoverability. As for logs I have nothing ATM. I use status codes in the interim.)

Ref: