Snapshot on drive mount

What would be the best way to achieve this?
I want to create a snapshot every time an external drive is mounted.
I am using the Kopia GUI on Mac if that helps.

Not really something supported by GUI. Use kopia CLI triggered by launchd.

Use StartOnMount key:

 StartOnMount <boolean>
 This optional key causes the job to be started every time a filesystem is
 mounted.

Such job will be triggered on any new mount so you will also need some script wrapper to check if this is the mount you want to backup.

I could make the plist point to a script on said volume, if it was another volume it will just error out.

Can I use the CLI and GUI together without any problems?

Yes - no problem. Kopia supports parallel operations by design.

There are many ways how to solve details here. Do what’s the easiest for you but I am not sure if you can enable such job when script is missing, e.g. after computer restart.

So with the CLI, can I connect to multiple repositories at once?

How do I specify where the snapshot is saved?
I want to backup, on mount, to three repositories.

Multiple kopia instances can backup to the same repo at the same time.

There is no option to backup to multiple repositories from one kopia instance.

So with the CLI you have to do

kopia disconnect

Before you connect to another repository?

The GUI lets me have three repositories saved and I can pick one from the menu. There is no way to save three repositories with the CLI and specify which one I am saving to with the kopia snapshot create command?

No.

You can be connected to multiple repos at the same time. Then when using them you have to make sure you are telling kopia which one by specifying correct config file, e.g:

$ kopia --config-file="/Users/kptsky/Library/Application Support/kopia/repository.config" ls -l abcd

$ kopia --config-file="/Users/kptsky/Library/Application Support/kopia/repository-1708188240534.config" ls -l xyzv

How do I tell which repository is which config?

These config files do not appear there by magic… You create them when you connect.

GUI tells you which one is which one - click blue CLI button - it shows you what is CLI command.

You can also look inside using any text editor:)

Ok I was confused for a minute until I realized the GUI and CLI share config files in application support…

in case of kopia, GUI at the end is just fancy way to run CLI commands.

For writing my script:
Can I append --config-file=path/to/file
directly to the ‘kopia snapshot create’ command?

Edit: I tried this, it doesn’t work. It says:

failed to open repository: cannot open storage: unable to start rclone: fork/exec
usr/local/bin/rclone: no such file or directory

Of course rclone is in usr/local/bin

Yes you can and even IMO you should to be sure which repository you are backing up to.

You have to make sure that you explicitly specify all files location - e.g. rclone.config etc. Or make sure that your launchd runtime environment contains all PATHs and env variables needed.

I am specifying a config file created in the GUI.
The GUI asked for the location of rclone, which I gave it.
The GUI has no problem connecting, but when I do kopia snapshot create in the CLI it doesn’t work.

I used kopia/rclone combo in the past - do not remember any particular issues. And I had everything scripted too.

Can you run your script from terminal? Forget launchd first and make it work from command line.

Share your script here - maybe we can spot some issue.

No, I mean I’m just trying to run Kopia from the command line with a config file created by the GUI and it doesn’t work.

I did not specifically do ‘kopia connect’ from the command line as if I do this it seems to overwrite my GUI config files?

No launchd or script involved yet.

I did which rclone and it says /usr/local/bin/rclone

then I did rclone listremotes and of course it shows all three remotes.

Kopia GUI shows all three repositories.

Only Kopia CLI doesn’t work. I installed it using brew install kopia
And then tried to use it to create a snapshot.

Is there some way to reconnect to the repositories without overwriting my GUI config files?

Edit: seems like what I need is Kopia repository connect from-config?

I use both GUI and CLI all the time - sharing the same kopia config files from ~/Library/Application Support/kopia. It tells me that you make some small mistake somewhere as in principle it should work without any issues.

You can try to specify rclone location explicitly:

--rclone-exe="/path/to/rclone"

and in addition the same for rclone.conf

--rclone-args="--config=/path/to/rclone.conf"

Do I need to do kopia connect from-config using the CLI if I already connected with the GUI?