TrueNAS Scale create snapshot programatically

Hello,
I would like to create a ZFS snapshot of a dataset programmatically, from a script.

To be more precise, I’m writing a script that safely stops services (on a different machine; they store data on the TrueNAS using a NFS share), creates a (ZFS) snapshots of the data, updates the services and starts them back up. In case anything goes wrong, I need to be able to restore to the last version of the service and its data.

The script is running on a different machine than TrueNAS. Preferably, it would connect to TrueNAS using SSH to create the snapshot.

Does TrueNAS have any CLI or API?

It has both.

Except, that the CLI is deprecated and is not receiving further updates in 24.04 :frowning:

And the REST API is deprecated as well.

To the correct way to do it now is to use the python client (github: truenas/api_client)?

(I cannot include links)

Yes, and it’s being replaced by the websocket API. Which is documented at the link I gave. Or, for that matter, in TrueNAS itself.

Python client, or Go client, or some other client of your own design if you like.

1 Like

Thank you, I managed to find it.

You accidentally linked to the deprecated REST API. The new API has docs at api.truenas.com and the client for that is pre-installed on TrueNAS Scale and can be used from SSH :+1:

Now I need to figure out how to create a snapshot…