VMware Cloud Community
njecm
Contributor
Contributor

Cold migration of Vms from one Datacenter to another

I am trying to cold migrate VMs from a host in DatacenterA to a host in DatacenterB both datacenters are managed by the same Vcenter server.

I have followed the RelocateVM method from LucD and attempted to use the move-vm command and both error out.

The relocateVM method errors with "A specified parameter was not correct." and nothing happens.  The script I used is

$vmName = "VMName"
$tgtDS = "DatastoreName"
$tgtHost = "IP of ESXi Host"
$vm = Get-VM $vmName | Get-View
$esx = Get-VMHost $tgtHost | Get-View
$parent = $esx.Parent
while($parent.Type -ne "Datacenter"){
     $parent = (Get-View $parent).Parent
}
$dc = Get-View $parent
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = (Get-Datastore $tgtDS | Get-View).MoRef
$spec.host = $esx.MoRef
$spec.Pool = (Get-Datacenter $dc.Name | Get-ResourcePool -Name "Resources" | Get-View).MoRef
$spec
$vm.RelocateVM($spec,"defaultPriority")

This gives an output similar to:

Datastore       : DiskMoveType    : Pool            : Host            : HostSystem-host-1208 Disk            : Transform       : LinkedView      : DynamicType     : DynamicProperty : Exception calling "RelocateVM" with "2" argument(s): "A specified parameter was not correct. " At C:\scripts\Power off and migrate vms\scriptname.ps1:18 char:15 + $vm.RelocateVM <<<< ($spec,"defaultPriority")     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException     + FullyQualifiedErrorId : DotNetMethodException

The Move-VM method fails with an error about resources in a different datacenter, this simply shuts down all the VMs if they are on and then it is supposed to migrate them to the host in the destination datacenter, then power the vm on.  Both Datacenters have the same networks (on a Vswitch not a dvswitch) and they can see the same Luns.

$cluster = "IP Address of Host" $VMstoShutdown = Get-VM -Location $cluster | where-object {$_.PowerState -eq "PoweredOn" } ForEach ( $VM in $VMstoShutdown ) {     Write-Host "Processing $VM " -ForegroundColor Green     write-host "doing a graceful shutdown of $VM"     $vmshutdown = $VM | shutdown-VMGuest -Confirm:$false     } Write-Host "" Write-Host "Giving VMs 30 seconds to power down before migrating them" Write-Host "" Sleep 30       ForEach ( $VM in $VMstoShutdown ) {      Move-VM -VM $VM -Destination 10.4.1.160      Sleep 10      Start-VM $VM }

what I don't understand is why I can migrate the VMs using the GUI as long as I do a host and storage migration (I select the same LUN the VM is already on as both hosts can see the LUN)

Anyone have any ideas why this is erroring out? or any suggestions on how I should go about accomplishing this with a script?

0 Kudos
2 Replies
LucD
Leadership
Leadership

For the RelocateVM method there is probably some additional info in the vCenter's vpxd log.

You said that the LUNs are visible on the hosts in both datacenters. Is that correct ?

Then you could also unregister the VM, and then register it again but in the new datacenter/cluster.

If you still need the VM on another datastore, you should then be able to do a svMotion within the same datacenter/cluster


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

njecm
Contributor
Contributor

Thanks for the quick reply.. Both hosts/datacenter can access the same Luns

As for the unregister and register process, I'll have to look into it.

I'll also check the vpxd log, I'd prefer for the VMs to remain on the sale Lun throughout the migration as it will make it faster and reduce downtime.

0 Kudos