我们有两个单独的VMWare环境,一个是拥有数百台虚拟机的主要环境。 另一个是安装在一台服务器上的小得多,只是为了存档旧系统。
我想要做的就是对我们的一个活动虚拟机的当前状态进行快照,并使用它来复制到另一个VMWare环境,并在那里创build一个新的机器,将其作为该系统的存档。
这会变得简单吗?
当你使用vSphere 6的时候,你可以完成vCenter之间的克隆,并完成它。
无论如何,如果你使用PowerCLI,这个任务也不会超过5.5。
步骤是这样的:
使用这个方便的PowerCLI的一点点将快照克隆到一个新的虚拟机:
New-VM -Name $CloneName -VM $SourceVM -Location $CloneFolder -Datastore $Datastore -ResourcePool $ResourcePool -VMHost $VMHost -LinkedClone -ReferenceSnapshot $Snapshot
你可以在这里看看所有的选项是什么意思,以及如何填补它们。
他们的关键是“-ReferenceSnapshot”选项。
将您精明的新VM导出到OVF / OVA,或将该文件夹从DS复制到networking上的某个位置
我已经让我的IT安全团队请求运行虚拟机的“取证”副本,包括内存快照,以便在出现病毒或某种违规情况时进行调查。 为了让我的生活更轻松,我写了一个PSfunction,完成所有繁重的工作。 它只需要一个源虚拟机(通过名称或对象)和磁盘上的文件夹。 剩下的就是这样。
Function ExportVM { Param( [parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [PSObject]$SourceVM, [parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$DestinationPath ) #Check if the destination path exists, bail out if it doesn't if ( -not (Test-path $DestinationPath -IsValid) ) { Write-Warning "Please provide a valid path for the exported VM" return } #Get the SourceVM, bail out if it fails if ($SourceVM.GetType().Name -eq "string"){ try { $SourceVM = Get-VM $SourceVM -ErrorAction Stop } catch [Exception]{ Write-Warning "VM $SourceVM does not exist" return } } elseif ($SourceVM -isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]){ Write-Warning "You did not pass a string or a VM object for 'SourceVM'" Return } try { $DestinationPath = $DestinationPath + "\" + $SourceVM.Name #Setup the required compoments to compute an MD5 hash $algo = [System.Security.Cryptography.HashAlgorithm]::Create("MD5") $md5StringBuilder = New-Object System.Text.StringBuilder 50 $ue = New-Object System.Text.UTF8Encoding #Define the snapshot name $SnapshotName = "IT-Security Export - " + (Get-Date -UFormat "%b-%d-%Y, %R") #Create the snapshot $Snapshot = New-Snapshot -VM $SourceVM -Name $SnapshotName -Description "Snapshot for IT-Security Forensic export" -Memory -Quiesce -Confirm:$false $Snapshot #Define variables needed to create the clone $CloneFolder = $SourceVM.Folder $Datastore = Get-Datastore -RelatedObject $SourceVM $ResourcePool = Get-ResourcePool -VM $SourceVM $VMHost = Get-VMHost -VM $SourceVM #Build a unique name for the cloned machine based on the snapshot name $algo.ComputeHash($ue.GetBytes($SnapshotName)) | % { [void] $md5StringBuilder.Append($_.ToString("x2")) } $CloneName = $SourceVM.Name +"_ITSecExport_" + $md5StringBuilder.ToString().SubString(0,15) #Clone the VM $CloneVM = New-VM -Name $CloneName -VM $SourceVM -Location $CloneFolder -Datastore $Datastore -ResourcePool $ResourcePool -VMHost $VMHost -LinkedClone -ReferenceSnapshot $Snapshot #Define the name of the PSDrive, based on the Datastore name $DSName = "ITSecExport_" + ($Datastore.name -replace "[^a-zA-Z0-9]","") #Check to see if it already exists, remove if it does if (Get-PSDrive | Where {$_.Name -like $DSName}) { Remove-PSDrive $DSName } #Add the new drive $PSDrive = New-PSDrive -Location $Datastore -Name $DSName -Scope Script -PSProvider VimDatastore -Root "\" #Define variables needed to copy the SourceVM's VMX and the snapshot's VMSN $SnapshotID = (Get-VM $SourceVM |Get-Snapshot | where {$_.Name -like $SnapshotName}).ExtensionData.ID $SourceVM_VMXPath = (Get-View $SourceVM).Config.Files.VmPathName.Split(" ")[1].replace("/","\") $SourceVM_VMSNPath = $SourceVM_VMXPath.Replace(".vmx", "-Snapshot" + $SnapshotID + ".vmsn") #$CloneVM_VMPath = (Get-View $CloneVM).Config.Files.VmPathName.Split(" ")[1].Split("/")[0] #Copy the VMSN and VMX Copy-DatastoreItem -Item ${DSName}:\$SourceVM_VMXPath -Destination $DestinationPath -Force Copy-DatastoreItem -Item ${DSName}:\$SourceVM_VMSNPath -Destination $DestinationPath -Force #Copy-DatastoreItem -Item ${DSName}:\$CloneVM_Path\* $DestinationPath"$CloneName" -Force -Recurse #Export the VM $CloneVM | Export-VApp -Destination $DestinationPath -Force #Clean up Remove-VM -DeletePermanently $CloneVM -Confirm:$false Remove-Snapshot -Snapshot $Snapshot -Confirm:$false Remove-PSDrive -Name $DSName } catch [Exception]{ $ErrorMessage = $_.Exception.Message $FailedItem = $_.Exception.ItemName Write-Warning "Looks like we ran in to an error" Write-Warning " $ErrorMessage" return } }
据我所知,你可以简单地在主机之间复制虚拟机。 首先安全关机,然后停止虚拟机; 然后将完整的文件夹复制到其他VMWare环境。 复制文件夹后,在Web UI中,转到虚拟机菜单 – > 将虚拟机添加到清单,然后将复制的机器添加到主机。 开机时,您会收到一条消息,询问您是否复制或移动了机器,select“ 复制 ”。 一旦您在第二个VMWare环境中成功运行虚拟机,您可以在第一个VMWare环境中安全地删除和删除虚拟机。 根据您的networkingconfiguration,您可能需要更改一些设置,但应该可以正常工作。