Skip to main content

Friends,

I want to use a script to retire/delete VMs from Commvault when the last backup is at a certain age. As we are a tenant customer, we don’t have options like Workflows.

So I build a Powershell script to collect data, do different checks and fire Rest calls to Commvault.


I can delete via the following command and this works fine:
Invoke-RestMethod -Method 'Delete' -Headers $headers -Uri $($url + "/v4/virtualmachines/$UUID")

 

But I can’t find the option to Retire the VM !
And important in this case that I only retire the VM backup, not the client, as FS and SQL backups might be still in use.

 

Anyone who knows how to Retire a VM using Rest-API ?

 

Thanks in advance, Maurice

It depends on how your vm content is defined.

That’s the question you have to answer before anyone can help you.

For example; if your vm content is defined by tag or attribute then every time the vCenter pseudo client runs discovery the vm will be recreated.

 

Virtual machine backups are NOT defined at the vm level but rather at the vCenter Hypervisor level. 

 

You can find this for a particular vm under

protect → virtualization → virtual machines → vm group → content

 

Those content rules will show you how the virtual machine is being discovered.

 

Thanks.

Chris.


Hello Chris,

Thanks for your anwer.
Recreation of the VM is no risk. I only want to retire/delete VM’s that didn’t do any backup in the last 30 days. My script is checking on the age of the last backup.

 

The Delete command that I showed above, can only delete a VM backup what is retired first and we have in the meantime almost 1000 VM’s to delete, what can’t be done without Retire.
I prefer to not do this manually via Command Center… and in the meantime we keep paying for backups that are obsolete.

 

I only need to find the option to give the Retire command to the VM-backup….

Thanks in advance, Maurice


Try this.

 

https://documentation.commvault.com/11.16/rest_api_delete_client.html


Hello Chris,

Thanks again :)

If I retire a client, I also retire any other type of backup. There is a warning at the top of this page and I noticed this myself in the wrong way…

 

So in case we switch from VM-based backup to File-based backup, we want to retire/delete the VM-backups after 30 days.

If we delete the client, we uninstall any CV agent from the VM and delete all backup data, from the other agents as well.

 

So I am looking for a way to specifically retire the VM only… just as you can do in Command Center.

 

Thanks in advance, Maurice 


Try this.

Get the client hierarchy and filter for the VM instance.

https://documentation.commvault.com/11.16/rest_api_get_client_hierarchy.html

 

Delete the VM instance.

https://documentation.commvault.com/2023e/essential/rest_api_delete_instance.html


Hello Chris,

I though that Instance was only for databases…. I will give it a try and share the results, thanks !


LMK, I’m curious.

 

Thanks.


$a1 = Invoke-RestMethod -Method 'Get' -Headers $headers -Uri $($URL + "/Client/5014/Hierarchy")

$a1 | ConvertTo-FlatObject

processinginstructioninfo_attributes_0_name : WebServer
processinginstructioninfo_attributes_0_value : CVCSblabla
entity_0_subclientId : 7468
entity_0_displayName : someOldVm
entity_0_clientId : 5014
entity_0_instanceName : VMInstance
entity_0_appName : Virtual Server
entity_0_applicationId : 106
entity_0_clientName : someOldVm
entity_0_backupsetId : 7148
entity_0_instanceId : 2
entity_0_subclientName : default
entity_0_backupsetName : defaultBackupSet

 

InstanceId, what is needed for the delete is “2”… I checked this with a few random other clients, but it’s always 2 in case of VMInstance.

So I don’t think it’s a good idea to just delete instance 2 via the “Delete Instance” call… as I don’t know what I will be delete in reality.

 

 


By the way…. I use this: https://api.commvault.com/docs/SP34/api/cv/OpenAPI3/delete-virtual-machine

 

This works fine to delete a VM from Commvault… but the issue that I have is that the VM first needs to be retired… And I miss the option to retire the VM.

 

And I am not even able to see if a VM is retired or not retired… If the VM is not retired, the Delete command will fail with an error that the VM needs a retire before delete.

 

Thanks, Maurice


$a1 = Invoke-RestMethod -Method 'Get' -Headers $headers -Uri $($URL + "/Client/5014/Hierarchy")

$a1 | ConvertTo-FlatObject

processinginstructioninfo_attributes_0_name : WebServer
processinginstructioninfo_attributes_0_value : CVCSblabla
entity_0_subclientId : 7468
entity_0_displayName : someOldVm
entity_0_clientId : 5014
entity_0_instanceName : VMInstance
entity_0_appName : Virtual Server
entity_0_applicationId : 106
entity_0_clientName : someOldVm
entity_0_backupsetId : 7148
entity_0_instanceId : 2
entity_0_subclientName : default
entity_0_backupsetName : defaultBackupSet

 

InstanceId, what is needed for the delete is “2”… I checked this with a few random other clients, but it’s always 2 in case of VMInstance.

So I don’t think it’s a good idea to just delete instance 2 via the “Delete Instance” call… as I don’t know what I will be delete in reality.

 

 

That’s just a failure in logic, 

it’s hierarchical so you can walk the hierarchy,

 

Meaning rather than converting to a flat object use obj-select to choose the vm instance.


I make a flat object to make it easier readable in this community… I don’t use it in the logic… It’s just $a1.entitya0].instanceID in above example.

Anyhow, instanceId for the VMInstance is “2” in the 5 different VM’s that I checked, so I can’t just blindly delete instance 2, as I don’t believe its related.


That’s my point you don’t have to blindly delete you use select-object in powershell to select the virtual server instance


Here are some examples on how to do it.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.4

 

 


I think you miss the point… It’s not about Powershell….

 

I just need to be able to Retire a VM, not Delete.

 

And instanceId can not be used as the value is not unique, it has the same value “2” for the 5 VM’s that I checked.


oh. Carry on.


Anyone who knows how to Retire a VM using Rest-API ?


@DUO-CSR please consult the API documentation: https://api.commvault.com/docs/SP34/api/cv/ClientOperations/retire-client#retire-client

As an alternative you could look into using the PowerShell or Python SDKs. 


Hello Onno,

 

Thanks for your feedback, but this will not retire the VM, but retire the client and all agents plus uninstall any Commvault software. See the “Caution” on the page that you shared.

 

I am looking for a way to only retire the VM and not all the rest.

 

Strange enough you can delete the VM without touching the rest, but I can’t find a way to retire the VM without touching the rest….. While you need to retire before delete.
Or in our case wait 2 months after the last backup, then it seems it’s retired automatically, but this means that we need to pay 2 months for obsolete backup data.


Delete VM: Delete a Virtual Machine | Commvault®️
Retire VM: ???


Seems that there is no way to retire a VM only…

 

Even within CommandCenter Protect-Virtualization, if you select a VM and do a Retire, you don’t retire the VM only, but everything for this client and CV software will be uninstalled.

 

This is pretty horrible implemented… 


Reply