SOLVED Need help with RESTful API v2.0 zfs/snapshot/clone

m87

Cadet
Joined
May 9, 2022
Messages
6
Using TrueNAS CORE 13 U3.1
I've been trying to write a script to create an extent and target from a pre-existing (automatic) snapshot. Getting the snapshot "name" is not a problem. Where I've hit a wall is trying to use the API to clone said snapshot, so it can be used to create the extent and target.
I took it out to the command line, and it's failing:
Code:
curl -X POST https://<SERVERNAME>/api/v2.0/zfs/snapshot/clone \
-H "Authorization: Bearer ReallyLongAPIKeyGoesHere" \
-H "Content-Type: application/json" \
-d '{ \
"snapshot": "bigpool/spinners-iscsi-auto-2023-04-14_21-09-2w", \
"dataset_dst": "bigpool/spinners-iscsi-auto-2023-04-14_21-09-2w-clone" \
}'


The error that comes back is:

Code:
"message": "Failed to clone snapshot: Snapshot bigpool/spinners-iscsi-auto-2023-04-14_21-09-2w not found",
"errno": 14


I got the name "bigpool/spinners-iscsi-auto-2023-04-14_21-09-2w" directly from querying the snapshot list, out of the JSON data, so if there's a formatting issue, I'm in the dark about it.
The documentation doesn't seem to help, and even the interactive RESTful API page at https://<SERVERNAME>/api/docs/ fails at this. I've looked through the TrueNAS github python REST API tests - no luck.

Any help at all would be greatly appreciated.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Snapshots usually have an @ in the name, like "bigpool/spinners-iscsi-auto@2023-04-14_21-09-2w", which is probably why you're getting that error. You may have to HTML-escape the @ to %40.
 

m87

Cadet
Joined
May 9, 2022
Messages
6
Snapshots usually have an @ in the name, like "bigpool/spinners-iscsi-auto@2023-04-14_21-09-2w", which is probably why you're getting that error. You may have to HTML-escape the @ to %40.
Thank you for pointing that out! That's what I get for continuing on when I'm too tired.

Unfortunately, the error is the same:

Code:
curl -X POST https://<SERVERNAME>/api/v2.0/zfs/snapshot/clone \
  -H "Authorization: Bearer ReallyLongAPIKeyGoesHere" \
  -H "Content-Type: application/json" \
  -d '{"snapshot": "bigpool/spinners-iscsi%40auto-2023-04-21_21-09-2w", "dataset_dst": "bigpool/spinners-iscsi-auto-2023-04-21_21-09-2w_clone"}'
{
 "message": "Failed to clone snapshot: Snapshot bigpool/spinners-iscsi%40auto-2023-04-21_21-09-2w not found",
 "errno": 14
}


I'll continue to play with this, keeping in mind the HTML-escaping required.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
I'll continue to play with this, keeping in mind the HTML-escaping required.

Try it both ways. I'm not sure if HTML-escaping is needed or not.
 
  • Like
Reactions: m87

m87

Cadet
Joined
May 9, 2022
Messages
6
Try it both ways. I'm not sure if HTML-escaping is needed or not.
Yep. This was the solution. I have been in a rush today with only a minute to look at it, and was also messing up my JSON formatting along the way. I should have just left it until I had some time. Thank you for your patient counsel! :smile:
 
Top