How can i get total restore time (or job duration) of a VM using the API?

guerro

Member
Oct 1, 2021
11
0
6
22
Hello Everyone,
As title say, we're trying to automate some basic task we do periodically and one of those involves restore a machine, get how much time it takes (so we can get a raw estime) and then manually recreate the entire enviroment of our client.

Using PVE API I managed to restore a machine and get the UPID of the task:
1681226322313.png
what I would like to do next is save how much time the job took to finish, but as you can see if i fetch the job status using the API there's no total time or end time reported even if the job is finished:
1681281396246.png

The backup I'm restoring is from a Proxmox Backup Server.

Am I missing something?
In the web GUI job duration is reported...
I appreciate any effort, thank you very much.
 
Hi,
unfortunately endtime is not exposed in a straight forward manner. You will get a tasks endtime by querying all the tasks on cluster level requesting a json response and parse it from the JSON Object with matching UPID. For example via
Code:
pvesh get /cluster/tasks --output-format json-pretty
you will get the desired information, which is also used to calculated the duration based on the difference to the tasks start time in the webuis task viewer.

Hope this helps!