Automate backup of selected VMs from a VMGroup using RESTAPI
Hello All
We take adhoc backups every day for patching activities and we search for each and every client in Command Center and trigger incremental backups for those clients(more than 100 every day). Is there a way that we can trigger the backup for these clients using RESTAPI. Foreach through these clients and trigger the incremental backup. I was able to authenticate and generate the authentication token but cannot trigger the backups for those clients. Its my first time with RESTAPIs. Would be grateful if someone can point in the right direction. I am using PoweShell.
Thanks
Page 1 / 1
Hi,
I am calling the same script through Workflow but its failing with error message:
server1 server2 INFO: Get-CVVirtualMachine: virtual machine not found having name iserver1] INFO: Get-CVClient: client not found having id <0] You cannot call a method on a null-valued expression.
Similary for server2
I have not looked in the lines of code in the SDK but I assume adding 16 seconds per VM is still to much depending on how many VMs you want to process ;-)
Anyway best is to run it outside of the function so you only have to pull the information into memory ones.
Hi Abdul,
You should take out the Get-CVVirtualMachine out of the existing function and enrich the metadata that is required to execute the Backup-CVVirtualMachine upfront so that you only have to parse the required information into the function.
That way you only execute the Get-CVVirtualMachine one time.
Onno
Thank you. That will improve the performance. And to your point about the performance of PowerShell and API calls, I did a quick comparison:
Both the command return the same number of results but PowerShell commands take more time.
Hi Abdul,
You should take out the Get-CVVirtualMachine out of the existing function and enrich the metadata that is required to execute the Backup-CVVirtualMachine upfront so that you only have to parse the required information into the function.
That way you only execute the Get-CVVirtualMachine one time.
Onno
Hi Abdul,
Not sure if the "performance" is related to you specific environment due to high load on the CommServe or a high amount of client computers but I bet you that direct API communication gives back the same result when it comes to timings. The SDKs are there to simplify the consumption of the APIs and int hat sense also use the APIs.
I'm not sure why you have to run the Get-CVVirtualMachine command but if you already now the name of the VM that needs to be protected then you can submit the VM directly. It is clear that retrieving a list of all the VMs in the environment with their properties takes time so if that is the "issue" than you will have to program some kind of cache yourself in where your store the results so in that case you save 36 seconds. Additionally but I assume I do not have to point you to the idea to store the results in a variable.
Last suggestion I can give is to post your script here so it can be reviewed.
Thanks for the response. The reason I have to run Get-CVVirtualMachine is that Backup-CVVirtualMachine requires to add the ClientName in the command parameters. Here is the script:
Not sure if the "performance" is related to you specific environment due to high load on the CommServe or a high amount of client computers but I bet you that direct API communication gives back the same result when it comes to timings. The SDKs are there to simplify the consumption of the APIs and int hat sense also use the APIs.
I'm not sure why you have to run the Get-CVVirtualMachine command but if you already now the name of the VM that needs to be protected then you can submit the VM directly. It is clear that retrieving a list of all the VMs in the environment with their properties takes time so if that is the "issue" than you will have to program some kind of cache yourself in where your store the results so in that case you save 36 seconds. Additionally but I assume I do not have to point you to the idea to store the results in a variable.
Last suggestion I can give is to post your script here so it can be reviewed.
There is a special SDK available for Powershell that can do the trick. This will save you a lot of time because there is no need to look into the API documentation. It is available on Github see: GitHub - Commvault/CVPowershellSDK: Developer SDK - Powershell
Regards,
Onno
I tried PowerShell module but that is very slow and is not flexible. It gets the job done but the objects it returns lack the values that I need so I have to run multiple GET commands to prepare the command that I need to trigger the backup. For instance:
If I need to run the backup for VirtualMachine1 hosted on Hyperviser1.
I have to first use Get-CVVirtualMachine which takes 36 seconds to return the object.
I then have to get the psudoclient name from the returned object and run Get-CVClient to get its Name(Not the displayName). Takes 3 seconds to return the object.
At this point I have all the info that I need to trigger the backup with Backup-CVVirtualMachine.
It takes nearly 45 seconds to trigger a VM backup. I tried running this from inside the Commserv server.
Hi Abdul,
There is a special SDK available for Powershell that can do the trick. This will save you a lot of time because there is no need to look into the API documentation. It is available on Github see: GitHub - Commvault/CVPowershellSDK: Developer SDK - Powershell