I had to figure out how to make sure that VM with vCenter server is protected against software failure. I could use vCenter server hearth beat but is expensive and I don’t need super hiper HA for my vCenter server. I decided to use PowerCLI to make a clone of vCenter server virtual machine and keep two copies. Thanks to my colleague Grzesiek from http://psvmware.wordpress.com who helped me out with a script.
Add-PSSnapin VMware.VimAutomation.Core #variables $VC='vcenter-server-FQDN-or-IP' #import credentials $pwd = Get-Content D:\tools\scripts\ap-vcs-credentials | ConvertTo-SecureString $credentials = New-Object System.Management.Automation.PsCredential “username“, $pwd #Connect to vCenter Connect-VIServer -Server $VC $sourceVM = 'test01' #in $respool you can specify ESX host, cluster or resource pool $respool=Get-VMhost -Name "ESXi host name" $datastore=Get-datastore -Name 'datastore name' $cloneName = $sourceVM+'-01' #Remove second copy of VM Remove-VM $sourceVM'-02' -Confirm:$false -DeletePermanently:$true #Rename latest VM copy Get-VM -Name $sourceVM'-01' | Set-VM -Name $sourceVM'-02' -confirm:$false #Clone VM if(New-VM -Name $cloneName -VM $sourceVM -ResourcePool $respool -Datastore $datastore -DiskStorageFormat Thin ){"DONE"}else{"Something wrong with cloning"} Disconnect-VIServer -Confirm:$false
dirty scripting 😉 heheheh
You may want to check the disk format after the clone operation. In a test I am running this command to duplcate a VM:
PowerCLI C:> new-vm -vmhost esxi3-9 -Datastore nfs_tpl_1 -DiskStorageFormat Thin -VM 2008r2srvrDCtemplate -name 2008r2DC-200
The resulting VM has Thick-eager disks according to the web client. -DiskStorageFormat takes an object that I presume needs to be properly created and passed. I haven’t figured that part out yet.
[…] Cloning vCenter for backup purposes is fully supported, about one year ago Artur posted a PowerCLI script to automate this […]