Probably use a “before-snapshot” action to check if your environment checks out and exit with an error if not. That should prevent the snapshot from happening at all.
SSID_REQUIRED="my_network"
SSID_REQUIRED="INVALID"
ssid=$(/usr/sbin/iwgetid -r 2>/dev/null)
date >> ~/Desktop/debug.txt
if [[ "$ssid" == "$SSID_REQUIRED" ]]; then
exit 0
else
exit 1
fi
And testing it with kopia_wifi.sh; echo $? shows it works from the command line. And checking ~/Desktop/debug.txt shows the script runs when Kopia runs.
I’m using KopiaUI, which may be the problem? The script runs, but the backup also always runs, it never skips a backup. I’m manually clicking the “snapshot now” button. Does manual snapshot override this script?
Have you enabled kopia actions? They are off by default:
When using KopiaUI, actions can be enabled globally by editing your repository.config (it is located in the Config File location in KopiaUI under Repository) and change "enableActions": false to "enableActions": true. Save the file and restart KopiaUI.
and make sure that your action is configured as essential - meaning that it must succeed for kopia backup to continue.
If you’re running a Kopia server like me, than the path for your local script might be something else. E.g. my Kopia server runs on a Linux VM and the path to the script is like this:
/kopia/repos/actions/checkFreeSpace.sh
However, on my Mac the script has to be placed in:
I’m not running a server, just a local KopiaUI. I’m testing this on a local backup (just some files into a different folder). My other backups are non-server too, run from local, over sftp to a remote disk.
The script is executed. I have a “date >> ~/Desktop/debug.txt” which records that the script runs. (not the current version pasted above, where the date command is after the exit command. But without exit 1, the script clearly runs.
The script returns 1 when I test it on the command line.
Yes, I showed the cut and paste output of kopia policy show --global above. And the script is clearly running. Can it run if actions are not enabled? Run but ignore result??
I don’t mean the policy. You need actually to enable actions, when connecting to the repo. Check your repo config - it should have “enableActions”: true in it.
With essential before snapshot action as my kopia_test.sh script.
$ kopia policy show --global
...
Run command before snapshot root: (defined for this target)
Embedded script (stored in repository):
/Users/kptsky/bin/kopia/kopia_test.sh
Mode: essential
Timeout: 5m0s
...
For script returning exit code 0:
$ cat kopia_test.sh
exit 0
$ kopia snapshot create --all
Snapshotting kptsky@kptsky-laptop:/Users/kptsky/Temp ...
* 0 hashing, 0 hashed (0 B), 6188 cached (289.6 MB), uploaded 0 B, estimating...
Created snapshot with root kffdbf7d3a58c25290354c55e58786a88 and ID b119fc9e15cd6c13dc3b016bd6b0fa4c in 0s
The same when using GUI. When script returns exit code 1 I am presented with notification that snapshot failed.
@mankoff - I am not sure why it does not work for you. Maybe your script always returns 0? Try with my super script:) Also are you on the latest kopia? v0.21.1? I have a feeling that you are on some old version as wording of your commands output is different.
@budy: Thank you for suggesting enabling actions. They are enabled and I have said so 3x and shown it with a cut-and-paste. They were not during my first attempt, but after kapitainsky suggested it, I enabled them and restarted kopia.
Your kopia policy show --global shows different results than mine above. Yours contains the output Embedded script (stored in repository): and mine does not contain that. Perhaps that is part of the problem? I am using v0.21.1. I am unable to test this further at the moment because I am in Greenland and on the WiFi network where I do not want kopia to run, so I have shut down the program. I will try it again when I am home.
As I said, I do run a Kopia server which hosts my repo and the global policy for that repo also has this “Embedded script (stored in repo)”, which seems confusing to me, since the script itself is not stored in the repo. This is what my global policy states about my actions:
Run command before snapshot root: (defined for this target)
Embedded script (stored in repository):
/kopia/repos/actions/checkFreeSpace.sh
Mode: essential
Timeout: 5m0s
So the script on the Kopia server indeed is located at that path. However, on my KopiaUI client on the Mac, I have set a different location for the script, since it’s really not the same script anyway:
Run command before snapshot root: (defined for this target)
Embedded script (stored in repository):
/Users/stephan.budach/.config/kopiaActions/checkFreeSpace.sh
Mode: essential
Timeout: 30s
Do you, by any chance, have other policies, besides the global one?