將 VMware VM 遷移至 Azure (無代理程式) - PowerShell

在本文中,您將瞭解如何使用 Azure PowerShell 進行移轉和現代化,以無代理程式方法移轉探索到的 VMware 虛擬機(VM)。

您將學習如何:

  • 擷取 Azure Migrate 專案中探索到的 VMware VM。
  • 開始複寫 VM。
  • 更新復寫 VM 的屬性。
  • 監視複寫。
  • 執行測試移轉,以確保一切如預期般運作。
  • 執行完整的 VM 移轉。

注意

教學課程說明案例最簡單的部署路徑,以便快速設定概念證明。 教學課程會盡可能使用預設選項,而且不會顯示所有可能的設定和路徑。

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

必要條件

開始進行本教學課程之前,您必須:

安裝 Azure Migrate PowerShell 模組

Azure Migrate PowerShell 模組是 Azure PowerShell (Az) 的一部分。 Get-InstalledModule -Name Az.Migrate執行 命令來檢查您的電腦上是否已安裝 Azure Migrate PowerShell 模組。

登入您的 Azure 訂用帳戶

使用 連線-AzAccount Cmdlet 登入您的 Azure 訂用帳戶

Connect-AzAccount

選取您的 Azure 訂用帳戶

使用 Get-AzSubscription Cmdlet 取得您有權存取的 Azure 訂用帳戶清單。 使用 Set-AzContext Cmdlet,選取具有 Azure Migrate 專案要使用的 Azure 訂用帳戶。

Set-AzContext -SubscriptionId 00000000-0000-0000-0000-000000000000

擷取 Azure Migrate 專案

Azure Migrate 專案可用來儲存從您評估或遷移的環境中收集到的探索、評量和移轉中繼資料。 在專案中,您可以追蹤探索到的資產、協調評量,以及執行移轉。

在必要條件中,您已建立 Azure Migrate 專案。 使用 Get-AzMigrateProject Cmdlet 來擷取 Azure Migrate 專案的詳細數據。 您必須指定 Azure Migrate 項目的名稱 (Name) 和 Azure Migrate 專案的資源群組名稱 (ResourceGroupName)。

# Get resource group of the Azure Migrate project
$ResourceGroup = Get-AzResourceGroup -Name MyResourceGroup
# Get details of the Azure Migrate project
$MigrateProject = Get-AzMigrateProject -Name MyMigrateProject -ResourceGroupName $ResourceGroup.ResourceGroupName
# View Azure Migrate project details
Write-Output $MigrateProject

擷取 Azure Migrate 專案中探索到的 VM

Azure Migrate 和現代化會使用輕量型 Azure Migrate 設備。 在必要條件中,您已將 Azure Migrate 設備部署為 VMware VM。

若要在 Azure Migrate 專案中擷取特定的 VMware VM,請指定 Azure Migrate 專案的名稱()、Azure Migrate 專案的資源ProjectName群組和ResourceGroupName VM 名稱 (DisplayName)。

# Get a specific VMware VM in an Azure Migrate project
$DiscoveredServer = Get-AzMigrateDiscoveredServer -ProjectName $MigrateProject.Name -ResourceGroupName $ResourceGroup.ResourceGroupName -DisplayName MyTestVM | Format-Table DisplayName, Name, Type

# View discovered server details
Write-Output $DiscoveredServer

我們會將此 VM 移轉為本教學課程的一部分。

您也可以使用 ProjectNameResourceGroupName 參數,擷取 Azure Migrate 專案中的所有 VMware VM。

# Get all VMware VMs in an Azure Migrate project
$DiscoveredServers = Get-AzMigrateDiscoveredServer -ProjectName $MigrateProject.Name -ResourceGroupName $ResourceGroup.ResourceGroupName

如果您在 Azure Migrate 專案中有多個設備,您可以使用 ProjectNameResourceGroupNameApplianceName 參數來擷取使用特定 Azure Migrate 設備探索到的所有 VM。

# Get all VMware VMs discovered by an Azure Migrate Appliance in an Azure Migrate project
$DiscoveredServers = Get-AzMigrateDiscoveredServer -ProjectName $MigrateProject.Name -ResourceGroupName $ResourceGroup.ResourceGroupName -ApplianceName MyMigrateAppliance

初始化復寫基礎結構

移轉和現代化 會使用多個 Azure 資源來移轉 VM。 移轉和現代化會在與專案相同的資源群組中布建下列資源。

  • 服務總線:移轉和現代化會使用服務總線將復寫協調流程訊息傳送至設備。
  • 閘道記憶體帳戶:移轉和現代化會使用閘道記憶體帳戶來儲存所復寫 VM 的狀態資訊。
  • 記錄記憶體帳戶:Azure Migrate 設備會將 VM 的復寫記錄上傳至記錄記憶體帳戶。 Azure Migrate 會將復寫資訊套用至複本受控磁碟。
  • 密鑰保存庫:Azure Migrate 設備會使用金鑰保存庫來管理服務總線的 連接字串,以及復寫中所用記憶體帳戶的存取密鑰。

在復寫 Azure Migrate 專案中的第一個 VM 之前,請執行下列命令來布建複寫基礎結構。 此命令會布建並設定上述資源,以便開始移轉 VMware VM。

注意

一個 Azure Migrate 專案僅支援移轉至一個 Azure 區域。 執行此文稿之後,您無法將您要移轉 VMware VM 的目標區域變更為 。 如果您在 Azure Migrate 項目中設定新的設備,則必須執行 Initialize-AzMigrateReplicationInfrastructure 命令。

在本文中,我們會初始化復寫基礎結構,以便將 VM 遷移至 Central US 區域。

# Initialize replication infrastructure for the current Migrate project
Initialize-AzMigrateReplicationInfrastructure -ResourceGroupName $ResourceGroup.ResourceGroupName -ProjectName $MigrateProject. Name -Scenario agentlessVMware -TargetRegion "CentralUS" 

復寫 VM

完成探索並初始化復寫基礎結構之後,您就可以開始將 VMware VM 複寫至 Azure。 您最多可以同時執行 500 個復寫。

若要指定複寫屬性,請使用下表。

參數 類型 描述
目標訂用帳戶和資源群組 必要 使用 參數,指定 VM 應該移轉至的訂用帳戶和資源群組 TargetResourceGroupId
目標虛擬網路和子網 必要 指定 Azure 虛擬網絡 實體的識別碼,以及 VM 應該分別使用 TargetNetworkIdTargetSubnetName 參數移轉的子網名稱。
計算機標識碼 必要 指定需要復寫和移轉之探索到機器的標識碼。 使用 InputObject 來指定探索到的 VM 物件進行複寫。
目標 VM 名稱 必要 使用 參數指定要建立 TargetVMName 的 Azure VM 名稱。
目標 VM 大小 必要 使用 TargetVMSize 參數指定要用於復寫 VM 的 Azure VM 大小。 例如,若要將 VM 遷移至 Azure 中的 D2_v2 VM,請將 的值 TargetVMSize 指定為 Standard_D2_v2
授權 必要 若要針對使用中軟體保證或 Windows Server 訂用帳戶涵蓋的 Windows Server 機器使用 Azure Hybrid Benefit,請將 參數的值 LicenseType 指定為 WindowsServer。 否則,請將值指定為 NoLicenseType
作業系統磁碟 必要 指定具有操作系統開機載入器和安裝程式之磁碟的唯一標識碼。 要使用的磁碟標識碼是使用 Get-AzMigrateDiscoveredServer Cmdlet 擷取之磁碟的唯一標識碼 (UUID) 屬性。
磁碟類型 必要 指定要使用的磁碟類型。
基礎結構備援 選擇性 指定基礎結構備援選項,如下所示:

- 可用性區域:將移轉的計算機釘選到區域中的特定可用性區域。 使用此選項可將形成多節點應用層的伺服器分散到可用性區域。 只有在為移轉選取的目標區域支援可用性區域時,才能使用此選項。 若要使用可用性區域,請指定 TargetAvailabilityZone 參數的可用性區域值。
- 可用性設定組:將移轉的計算機放在可用性設定組中。 選取的目標資源群組必須有一或多個可用性設定組才能使用此選項。 若要使用可用性設定組,請指定 TargetAvailabilitySet 參數的可用性設定組標識碼。
開機診斷 儲存體 帳戶 選擇性 若要使用開機診斷記憶體帳戶,請指定 參數的 TargetBootDiagnosticStorageAccount 標識碼。
- 用於開機診斷的記憶體帳戶應位於您要移轉 VM 的相同訂用帳戶中。
- 根據預設,此參數不會設定任何值。
標籤 選擇性 將標籤新增至已移轉的 VM、磁碟和 NIC。
使用 Tag 將標籤新增至 VM、磁碟和 NIC,或:
- 用來 VMTag 將標籤新增至已移轉的 VM。
- 用來 DiskTag 將標籤新增至磁碟。
- 使用 NicTag 將標籤新增至網路介面。
例如,將必要的標籤新增至變數 $tags ,並在必要的參數中傳遞變數: $tags = @{Organization=”Contoso”}

使用所有磁碟復寫 VM

在本教學課程中,我們會復寫探索到 VM 的所有磁碟,併為 Azure 中的 VM 指定新名稱。 我們會將探索到的伺服器的第一個磁碟指定為 OS磁碟 ,並將所有磁碟移轉為 標準HDD。 OS 磁碟是具有作業系統開機載入器和安裝程式的磁碟。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

# Retrieve the resource group that you want to migrate to
$TargetResourceGroup = Get-AzResourceGroup -Name MyTargetResourceGroup
# Retrieve the Azure virtual network and subnet that you want to migrate to
$TargetVirtualNetwork = Get-AzVirtualNetwork -Name MyVirtualNetwork
# Start replication for a discovered VM in an Azure Migrate project
$MigrateJob =  New-AzMigrateServerReplication -InputObject $DiscoveredServer -TargetResourceGroupId $TargetResourceGroup.ResourceId -TargetNetworkId $TargetVirtualNetwork.Id -LicenseType NoLicenseType -OSDiskID $DiscoveredServer.Disk[0].Uuid -TargetSubnetName $TargetVirtualNetwork.Subnets[0].Name -DiskType Standard_LRS -TargetVMName MyMigratedTestVM -TargetVMSize Standard_DS2_v2
# Track job status to check for completion
while (($MigrateJob.State -eq 'InProgress') -or ($MigrateJob.State -eq 'NotStarted')){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $MigrateJob = Get-AzMigrateJob -InputObject $MigrateJob
}
#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $MigrateJob.State

使用選取的磁碟復寫 VM

您也可以使用 New-AzMigrateDiskMapping Cmdlet 選擇性地復寫探索到 VM 的磁碟,並提供該磁碟做為 New-AzMigrateServerReplication Cmdlet 中參數的輸入DiskToInclude。 您也可以使用 New-AzMigrateDiskMapping Cmdlet,為每個要復寫的個別磁碟指定不同的目標磁碟類型。

指定 New-AzMigrateDiskMapping Cmdlet 之下列參數的值:

  • DiskId:指定要移轉之磁碟的唯一標識符。 要使用的磁碟標識碼是使用 Get-AzMigrateDiscoveredServer Cmdlet 擷取之磁碟的 UUID 屬性。
  • IsOSDisk:指定要 true 移轉的磁碟是否為 VM 的 OS 磁碟。 否則,請指定 false
  • DiskType:指定要在 Azure 中使用的磁碟類型。

在下列範例中,我們只會復寫探索到 VM 的兩個磁碟。 我們會指定 OS 磁碟,並針對要復寫的每個磁碟使用不同的磁碟類型。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

# View disk details of the discovered server
Write-Output $DiscoveredServer.Disk
# Create a new disk mapping for the disks to be replicated
$DisksToReplicate = @()
$OSDisk = New-AzMigrateDiskMapping -DiskID $DiscoveredServer.Disk[0].Uuid -DiskType StandardSSD_LRS -IsOSDisk true
$DataDisk = New-AzMigrateDiskMapping -DiskID $DiscoveredServer.Disk[1].Uuid -DiskType Premium_LRS -IsOSDisk false

$DisksToReplicate += $OSDisk
$DisksToReplicate += $DataDisk
# Retrieve the resource group that you want to migrate to
$TargetResourceGroup = Get-AzResourceGroup -Name MyTargetResourceGroup
# Retrieve the Azure virtual network and subnet that you want to migrate to
$TargetVirtualNetwork = Get-AzVirtualNetwork -Name MyVirtualNetwork
# Start replication for the VM
$MigrateJob =  New-AzMigrateServerReplication -InputObject $DiscoveredServer -TargetResourceGroupId $TargetResourceGroup.ResourceId -TargetNetworkId $TargetVirtualNetwork.Id -LicenseType NoLicenseType -DiskToInclude $DisksToReplicate -TargetSubnetName $TargetVirtualNetwork.Subnets[0].Name -TargetVMName MyMigratedTestVM -TargetVMSize Standard_DS2_v2
# Track job status to check for completion
while (($MigrateJob.State -eq 'InProgress') -or ($MigrateJob.State -eq 'NotStarted')){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $MigrateJob = Get-AzMigrateJob -InputObject $MigrateJob
}
# Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $MigrateJob.State

監視複寫

複寫會在下列情況下發生:

  • 啟動複寫作業順利完成後,機器便會開始初始複寫至 Azure。
  • 在初始復寫期間,會建立 VM 快照集。 快照集中的磁碟數據會復寫至 Azure 中的復本受控磁碟。
  • 初始複寫完成後,就會開始進行差異複寫。 對內部部署磁碟的累加變更會定期複寫至 Azure 中的複本磁碟。

使用 Get-AzMigrateServerReplication Cmdlet 來追蹤復寫的狀態。

# List replicating VMs and filter the result for selecting a replicating VM. This cmdlet will not return all properties of the replicating VM.
$ReplicatingServer = Get-AzMigrateServerReplication -ProjectName $MigrateProject.Name -ResourceGroupName $ResourceGroup.ResourceGroupName -MachineName MyTestVM
# Retrieve all properties of a replicating VM 
$ReplicatingServer = Get-AzMigrateServerReplication -TargetObjectID $ReplicatingServer.Id

您可以在輸出中追蹤 移轉狀態移轉狀態描述 屬性。

  • 針對初始複寫,移轉狀態和移轉狀態描述屬性InitialSeedingInProgress的值分別為 和 Initial replication
  • 在差異複寫期間,移轉狀態和移轉狀態描述屬性Replicating的值分別為 和 Ready to migrate
  • 完成移轉之後,移轉狀態和移轉狀態描述屬性Migration succeeded的值分別為 和 Migrated
AllowedOperation            : {DisableMigration, TestMigrate, Migrate}
CurrentJobId                : /Subscriptions/xxx/resourceGroups/xxx/providers/Micr
                              osoft.RecoveryServices/vaults/xxx/replicationJobs/None
CurrentJobName              : None
CurrentJobStartTime         : 1/1/1753 1:01:01 AM
EventCorrelationId          : 9d435c55-4660-41a5-a8ed-dd74213d85fa
Health                      : Normal
HealthError                 : {}
Id                          : /Subscriptions/xxx/resourceGroups/xxx/providers/Micr
                              osoft.RecoveryServices/vaults/xxx/replicationFabrics/xxx/replicationProtectionContainers/xxx/
                              replicationMigrationItems/10-150-8-52-b090bef3-b733-5e34-bc8f-eb6f2701432a_5009e941-3e40-
                              39b2-1e14-f90584522703
LastTestMigrationStatus     :
LastTestMigrationTime       :
Location                    :
MachineName                 : MyTestVM
MigrationState              : InitialSeedingInProgress
MigrationStateDescription   : Initial replication
Name                        : 10-150-8-52-b090bef3-b733-5e34-bc8f-eb6f2701432a_5009e941-3e40-39b2-1e14-f90584522703
PolicyFriendlyName          : xxx
PolicyId                    : /Subscriptions/xxx/resourceGroups/xxx/providers/Micr
                              osoft.RecoveryServices/vaults/xxx/replicationPolicies/xxx
ProviderSpecificDetail      : Microsoft.Azure.PowerShell.Cmdlets.Migrate.Models.Api20180110.VMwareCbtMigrationDetails
TestMigrateState            : None
TestMigrateStateDescription : None
Type                        : Microsoft.RecoveryServices/vaults/replicationFabrics/replicationProtectionContainers/replicationMigrationItems

如需復寫進度的詳細資訊,請執行下列 Cmdlet:

Write-Output $replicatingserver.ProviderSpecificDetail

您可以使用輸出中的初始植入進度百分比屬性來追蹤初始復寫進度

    "DataMoverRunAsAccountId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.OffAzure/VMwareSites/xxx/runasaccounts/xxx",
    "FirmwareType":  "BIOS",
    "InitialSeedingProgressPercentage": 20,
    "InstanceType":  "VMwareCbt",
    "LastRecoveryPointReceived":  "\/Date(1601733591427)\/",
    "LicenseType":  "NoLicenseType",
    "MigrationProgressPercentage":  null,
    "MigrationRecoveryPointId":  null,
    "OSType":  "Windows",
    "PerformAutoResync":  "true",

複寫會在下列情況下發生:

  • 啟動複寫作業順利完成後,機器便會開始初始複寫至 Azure。
  • 在初始復寫期間,會建立 VM 快照集。 快照集中的磁碟數據會復寫至 Azure 中的復本受控磁碟。
  • 初始複寫完成後,就會開始進行差異複寫。 對內部部署磁碟的累加變更會定期複寫至 Azure 中的複本磁碟。

擷取作業的狀態

您可以使用 Get-AzMigrateJob Cmdlet 來監視作業的狀態。

# Retrieve the updated status for a job
$job = Get-AzMigrateJob -InputObject $job

更新復寫 VM 的屬性

移轉和現代化 可讓您變更復寫 VM 的目標屬性,例如名稱、大小、資源群組、NIC 組態等等。

VM 可以更新下列屬性。

參數 類型 描述
VM 名稱 選擇性 使用 參數指定要建立 TargetVMName 的 Azure VM 名稱。
VM 大小 選擇性 使用 TargetVMSize 參數指定要用於復寫 VM 的 Azure VM 大小。 例如,若要將 VM 遷移至 Azure 中的 D2_v2 VM,請將 的值 TargetVMSize 指定為 Standard_D2_v2
虛擬網路 選擇性 使用 TargetNetworkId 參數,指定 VM 應該移轉至的 Azure 虛擬網路識別碼。
資源群組 選擇性 IC 組態可以使用 New-AzMigrateNicMapping Cmdlet 來指定。 然後,對象會傳遞至 NicToUpdate Set-AzMigrateServerReplication Cmdlet 中的參數。

- 變更IP配置:若要指定 NIC 的靜態IP,請使用 參數提供要作為 VM TargetNicIP 靜態IP的 IPv4 位址。 若要動態指派 NIC 的 IP,請提供 auto 做為 參數的值 TargetNicIP
- 使用 值 PrimarySecondaryDoNotCreate 針對 TargetNicSelectionType 參數指定 NIC 應該是主要、次要或不應該在移轉的 VM 上建立。 只有一個 NIC 可以指定為 VM 的主要 NIC。
- 若要建立 NIC 主要複本,您也必須指定其他應設為次要或未在移轉的 VM 上建立的 NIC。
- 若要變更 NIC 的子網,請使用 TargetNicSubnet 參數指定子網的名稱。
網路介面 選擇性 使用 參數指定要建立 TargetVMName 的 Azure VM 名稱。
可用性區域 選擇性 若要使用可用性區域,請指定 TargetAvailabilityZone 參數的可用性區域值。
可用性設定組 選擇性 若要使用可用性設定組,請指定 TargetAvailabilitySet 參數的可用性設定組標識碼。
標籤 選擇性 若要更新標籤,請使用下列參數:或 、、 和更新標籤作業UpdateTagOperation的類型或UpdateVMTagOperationUpdateNicTagOperationUpdateDiskTagOperation 、 、 UpdateNicTagUpdateDiskTagUpdateVMTagUpdateTag 更新標籤作業會採用下列值:Merge、Delete 和 Replace。
用來 UpdateTag 更新 VM、磁碟和 NIC 之間的所有標籤。
用來 UpdateVMTag 更新 VM 標籤。
用來 UpdateDiskTag 更新磁碟標籤。
用來 UpdateNicTag 更新 NIC 標籤。
用來 UpdateTagOperation 更新 VM、磁碟和 NIC 之間所有標籤的作業。
用來 UpdateVMTagOperation 更新 VM 標籤。
用來 UpdateDiskTagOperation 更新磁碟標籤。
用來 UpdateNicTagOperation 更新 NIC 標籤。

replace 選項會將整個現有標記集取代為新的集合。
合併選項允許新增具有新名稱的標籤,以及以現有名稱更新標籤的值。
刪除選項允許根據特定名稱或名稱/值組選擇性地刪除標記。
Disks 選擇性 針對 OS 磁碟:
- 使用 TargetDiskName 參數更新 OS 磁碟的名稱。

若要更新多個磁碟:
- 使用 Set-AzMigrateDiskMapping 將磁碟名稱設定為變數 $DiskMappingDiskToUpdate然後使用 參數並傳遞 變數。

Set-AzMigrateDiskMapping 中使用的磁碟標識符是使用 Get-AzMigrateDiscoveredServer Cmdlet 擷取之磁碟的 UUID 屬性。
NIC 的名稱 選擇性 使用 New-AzMigrateNicMapping 將 NIC 名稱設定為變數 $NICMappingNICToUpdate然後使用 參數並傳遞 變數。

Get-AzMigrateServerReplication Cmdlet 會傳回可追蹤以監視作業狀態的工作。

# List replicating VMs and filter the result for selecting a replicating VM. This cmdlet will not return all properties of the replicating VM.
$ReplicatingServer = Get-AzMigrateServerReplication -ProjectName $MigrateProject.Name -ResourceGroupName $ResourceGroup.ResourceGroupName -MachineName MyTestVM
# Retrieve all properties of a replicating VM 
$ReplicatingServer = Get-AzMigrateServerReplication -TargetObjectID $ReplicatingServer.Id

# View NIC details of the replicating server
Write-Output $ReplicatingServer.ProviderSpecificDetail.VMNic

在下列範例中,我們會將第一個 NIC 設為主要,並將靜態 IP 指派給它,以更新 NIC 組態。 我們會捨棄第二個 NIC 以進行移轉、更新目標 VM 名稱和大小,以及自定義 NIC 名稱。

# Specify the NIC properties to be updated for a replicating VM.
$NicMapping = @()
$NicMapping1 = New-AzMigrateNicMapping -NicId $ReplicatingServer.ProviderSpecificDetail.VMNic[0].NicId -TargetNicIP ###.###.###.### -TargetNicSelectionType Primary TargetNicName "ContosoNic_1"
$NicMapping2 = New-AzMigrateNicMapping -NicId $ReplicatingServer.ProviderSpecificDetail.VMNic[1].NicId -TargetNicSelectionType DoNotCreate - TargetNicName "ContosoNic_2"

$NicMapping += $NicMapping1
$NicMapping += $NicMapping2
# Update the name, size and NIC configuration of a replicating server
$UpdateJob = Set-AzMigrateServerReplication -InputObject $ReplicatingServer -TargetVMSize Standard_DS13_v2 -TargetVMName MyMigratedVM -NicToUpdate $NicMapping

在下列範例中,我們會自定義磁碟名稱。

# Customize the Disk names for a replicating VM
$OSDisk = Set-AzMigrateDiskMapping -DiskID "6000C294-1217-dec3-bc18-81f117220424" -DiskName "ContosoDisk_1" 
$DataDisk1= Set-AzMigrateDiskMapping -DiskID "6000C292-79b9-bbdc-fb8a-f1fa8dbeff84" -DiskName "ContosoDisk_2" 
$DiskMapping = $OSDisk, $DataDisk1 
# Update the disk names for a replicating server
$UpdateJob = Set-AzMigrateServerReplication InputObject $ReplicatingServer DiskToUpdate $DiskMapping 

在下列範例中,我們會將標籤新增至複寫的 VM。

# Update all tags across virtual machines, disks, and NICs.
Set-azmigrateserverreplication UpdateTag $UpdateTag UpdateTagOperation Merge/Replace/Delete

# Update virtual machines tags
Set-azmigrateserverreplication UpdateVMTag $UpdateVMTag UpdateVMTagOperation Merge/Replace/Delete 

使用下列範例來追蹤作業狀態。

# Track job status to check for completion
while (($UpdateJob.State -eq 'InProgress') -or ($UpdateJob.State -eq 'NotStarted')){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $UpdateJob = Get-AzMigrateJob -InputObject $UpdateJob
}
# Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $UpdateJob.State

執行測試移轉

當差異複寫開始時,您可以先針對 VM 執行測試移轉,再執行完整移轉至 Azure。 強烈建議您至少針對每部機器測試移轉一次,再進行移轉。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

  • 執行測試移轉會檢查移轉是否如預期般運作。 測試移轉不會影響內部部署計算機,其仍可運作並繼續複寫。
  • 測試移轉會使用複寫的數據建立 Azure VM 來模擬移轉。 測試通常會移轉至 Azure 訂用帳戶中的非生產虛擬網路。
  • 您可以使用複寫的測試 Azure VM 來驗證移轉、執行應用程式測試,以及在完整移轉之前解決任何問題。

使用 參數指定虛擬網路的識別碼,以選取要用於測試的 Azure 虛擬網路 TestNetworkID

# Retrieve the Azure virtual network created for testing
$TestVirtualNetwork = Get-AzVirtualNetwork -Name MyTestVirtualNetwork
# Start test migration for a replicating server
$TestMigrationJob = Start-AzMigrateTestMigration -InputObject $ReplicatingServer -TestNetworkID $TestVirtualNetwork.Id
# Track job status to check for completion
while (($TestMigrationJob.State -eq 'InProgress') -or ($TestMigrationJob.State -eq 'NotStarted')){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $TestMigrationJob = Get-AzMigrateJob -InputObject $TestMigrationJob
}
# Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $TestMigrationJob.State

測試完成之後,請使用 Start-AzMigrateTestMigrationCleanup Cmdlet 清除測試移轉。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

# Clean-up test migration for a replicating server
$CleanupTestMigrationJob = Start-AzMigrateTestMigrationCleanup -InputObject $ReplicatingServer
# Track job status to check for completion
while (($CleanupTestMigrationJob.State -eq "InProgress") -or ($CleanupTestMigrationJob.State -eq "NotStarted")){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $CleanupTestMigrationJob = Get-AzMigrateJob -InputObject $CleanupTestMigrationJob
}
# Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $CleanupTestMigrationJob.State

移轉 VM

確認測試移轉如預期般運作之後,您可以使用下列 Cmdlet 來移轉復寫伺服器。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

如果您不想關閉來源伺服器,請勿使用 TurnOffSourceServer 參數。

# Start migration for a replicating server and turn off source server as part of migration
$MigrateJob = Start-AzMigrateServerMigration -InputObject $ReplicatingServer -TurnOffSourceServer
# Track job status to check for completion
while (($MigrateJob.State -eq 'InProgress') -or ($MigrateJob.State -eq 'NotStarted')){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $MigrateJob = Get-AzMigrateJob -InputObject $MigrateJob
}
#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
Write-Output $MigrateJob.State

完成移轉

  1. 移轉完成後,請停止內部部署計算機的複寫,並使用下列 Cmdlet 清除 VM 的復寫狀態資訊。 Cmdlet 會傳回可追蹤以監視作業狀態的工作。

    # Stop replication for a migrated server
    $StopReplicationJob = Remove-AzMigrateServerReplication -InputObject $ReplicatingServer
    
    # Track job status to check for completion
    while (($StopReplicationJob.State -eq 'InProgress') -or ($StopReplicationJob.State -eq 'NotStarted')){
            #If the job hasn't completed, sleep for 10 seconds before checking the job status again
            sleep 10;
            $StopReplicationJob = Get-AzMigrateJob -InputObject $StopReplicationJob
    }
    # Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded".
    Write-Output $StopReplicationJob.State
    
  2. 執行任何移轉後應用程式調整,例如更新資料庫連接字串和 Web 伺服器設定。

  3. 在現在於 Azure 中執行的已移轉應用程式上,執行最終的應用程式和移轉接受度測試。

  4. 將流量完全移轉至已遷移的 Azure VM 執行個體。

  5. 從您的本機 VM 清查中移除內部部署 VM。

  6. 從本機備份中移除內部部署 VM。

  7. 更新任何內部文件,以顯示 Azure VM 的新位置和 IP 位址。

移轉後的最佳做法