使用 Azure Site Recovery REST API 自动执行 VMware 到 Azure 代理的迁移

本文介绍如何使用 Azure Site Recovery REST API 自动执行简化的基于代理的虚拟机迁移到 Azure。 可以使用这些 API 通过 InMageRcm 复制提供程序生成用于大规模迁移的自定义自动化解决方案。 如果希望使用本文来:

  • 大规模自动化简化的 VMware/物理到 Azure 代理的迁移。
  • 将迁移过程集成到现有工具或管道中。
  • 以编程方式控制复制、测试迁移和故障转移操作。

Prerequisites

在开始之前,请确保具有以下各项:

  • 具有 Azure Migrate 所有者角色的 Azure 订阅,用于创建和管理 Azure Migrate 资源。 Azure Migrate 内置角色

Important

权限不足可能会导致 API 调用失败,并出现授权或资源访问错误。

  • 为基于代理的迁移配置的迁移项目。
  • 已部署并在保管库中注册的复制设备。
  • VMware 或设备发现的物理虚拟机。
  • 在 Azure 门户中启用首次复制,以创建复制所需的初始资源。

收集所需的资源 ID

在调用 API 之前,请收集所需的资源标识符。 本部分介绍如何获取每个标识符。

获取 Azure Site Recovery 保管库 ID

在 Azure 门户中,转到 Azure Migrate 项目 > 执行 > 迁移 > 复制摘要 > 属性。 在“链接恢复服务保管库”下,标识复制类型设置为“其他”的保管库,并复制保管库 ID。 或者,可以在创建 Azure Migrate 项目的资源组中找到保管库 ID。 资源 ID 格式为:

/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{migrateProjectName-MigrateVault-numbers}

获取进程服务器 ID 和站点 ID

processServerId是负责处理 VM 复制的复制设备的机器 ID。 要获取它:

步骤 1:列出布料

GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics?api-version=2025-08-01

选择 properties.customDetails.instanceType 等于 InMageRcm 的结构。

示例响应 (织物列表)

{
  "value": [
    {
      "name": "fabric-name-1",
      "type": "Microsoft.RecoveryServices/vaults/replicationFabrics",
      "id": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name-1",
      "properties": {
        "friendlyName": "fabric-name-1",
        "encryptionDetails": {
          "kekState": "None",
          "kekCertThumbprint": null
        },
        "rolloverEncryptionDetails": {
          "kekState": "None",
          "kekCertThumbprint": null
        },
        "internalIdentifier": "internal-guid-1",
        "bcdrState": "Valid",
        "customDetails": {
          "instanceType": "HyperVSite",
          "hyperVHosts": []
        },
        "healthErrorDetails": [],
        "health": "Normal"
      }
    },
    {
      "name": "fabric-name-2",
      "type": "Microsoft.RecoveryServices/vaults/replicationFabrics",
      "id": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name-2",
      "properties": {
        "friendlyName": "fabric-name-2",
        "encryptionDetails": {
          "kekState": "None",
          "kekCertThumbprint": null
        },
        "rolloverEncryptionDetails": {
          "kekState": "None",
          "kekCertThumbprint": null
        },
        "internalIdentifier": "internal-guid-2",
        "bcdrState": "Valid",
        "customDetails": {
          "instanceType": "InMageRcm",
          "vmwareSiteId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name",
          "physicalSiteId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/ServerSites/physical-site-name",
          "serviceEndpoint": "https://stamp-endpoint.hypervrecoverymanager.windowsazure.cn",
          "serviceResourceId": "redacted",
          "serviceContainerId": "redacted",
          "dataPlaneUri": "https://stamp-endpoint.backup.windowsazure.cn",
          "controlPlaneUri": "https://stamp-endpoint.hypervrecoverymanager.windowsazure.cn",
          "sourceAgentIdentityDetails": null,
          "processServers": [],
          "rcmProxies": [],
          "pushInstallers": [],
          "replicationAgents": [],
          "reprotectAgents": [],
          "marsAgents": [],
          "dras": [],
          "agentDetails": []
        },
        "healthErrorDetails": [],
        "health": "Normal"
      }
    }
  ],
  "nextLink": null
}

步骤 2:查询构造详细信息

GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}?api-version=2025-08-01

在响应中,进程服务器 ID 位于 properties.customDetails.processServers[].id. 网站信息存在于properties.customDetails.vmwareSiteIdproperties.customDetails.physicalSiteId中。

示例响应(构造详细信息)

{
  "name": "fabric-name",
  "type": "Microsoft.RecoveryServices/vaults/replicationFabrics",
  "id": "/Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name",
  "properties": {
    "friendlyName": "fabric-name",
    "encryptionDetails": {
      "kekState": "None",
      "kekCertThumbprint": null
    },
    "rolloverEncryptionDetails": {
      "kekState": "None",
      "kekCertThumbprint": null
    },
    "internalIdentifier": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "bcdrState": "Valid",
    "customDetails": {
      "instanceType": "InMageRcm",
      "vmwareSiteId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name",
      "physicalSiteId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name/providers/Microsoft.OffAzure/ServerSites/physical-site-name",
      "serviceEndpoint": "https://region-endpoint.hypervrecoverymanager.windowsazure.cn",
      "serviceResourceId": "redacted",
      "serviceContainerId": "redacted",
      "dataPlaneUri": "https://region-endpoint.backup.windowsazure.cn",
      "controlPlaneUri": "https://region-endpoint.hypervrecoverymanager.windowsazure.cn",
      "sourceAgentIdentityDetails": {
        "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "applicationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "objectId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "audience": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "aadAuthority": "https://login.chinacloudapi.cn/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "processServers": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "ipAddresses": [
            "x.x.x.x"
          ],
          "version": "9.66.7614.1",
          "lastHeartbeatUtc": "2026-04-21T04:24:56.3135603Z",
          "totalMemoryInBytes": 39727841280,
          "availableMemoryInBytes": 14194757689,
          "usedMemoryInBytes": 25533083591,
          "memoryUsagePercentage": 64.27,
          "totalSpaceInBytes": 665717829632,
          "availableSpaceInBytes": 660404075520,
          "usedSpaceInBytes": 5313754112,
          "freeSpacePercentage": 99.20,
          "throughputUploadPendingDataInBytes": 0,
          "throughputInBytes": 0,
          "processorUsagePercentage": 0.0,
          "throughputStatus": "Healthy",
          "systemLoad": 0,
          "systemLoadStatus": "Healthy",
          "diskUsageStatus": "Healthy",
          "memoryUsageStatus": "Healthy",
          "processorUsageStatus": "Healthy",
          "health": "Normal",
          "healthErrors": [],
          "historicHealth": "Normal"
        }
      ],
      "rcmProxies": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "clientAuthenticationType": "Certificate",
          "version": "1.44.9645.8268",
          "lastHeartbeatUtc": "2026-04-21T04:25:34.6896754Z",
          "health": "Normal",
          "healthErrors": []
        }
      ],
      "pushInstallers": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "version": "1.47.9649.18387",
          "lastHeartbeatUtc": "2026-04-21T04:25:11.2351003Z",
          "health": "Normal",
          "healthErrors": []
        }
      ],
      "replicationAgents": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "version": "1.45.9649.18472",
          "lastHeartbeatUtc": "2026-04-21T04:24:53.5000477Z",
          "health": "Normal",
          "healthErrors": []
        }
      ],
      "reprotectAgents": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "version": "1.48.9649.18457",
          "lastHeartbeatUtc": "2026-04-21T04:25:21.4453717Z",
          "health": "Normal",
          "healthErrors": [],
          "accessibleDatastores": [],
          "vcenterId": null
        }
      ],
      "marsAgents": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "fabricObjectId": null,
          "fqdn": "appliance-fqdn",
          "version": "2.0.9955.0",
          "lastHeartbeatUtc": "2026-04-21T04:24:29.8514455Z",
          "health": "Normal",
          "healthErrors": []
        }
      ],
      "dras": [
        {
          "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "name": "appliance-name",
          "biosId": "XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
          "version": "5.25.904.11",
          "lastHeartbeatUtc": "2026-04-21T04:30:31.8387555Z",
          "health": "Normal",
          "healthErrors": []
        }
      ],
      "agentDetails": []
    },
    "healthErrorDetails": [],
    "health": "Normal"
  }
}

将进程服务器条目中的 id 值用作与发现计算机的复制设备对应的 processServerId

获取 Fabric 发现计算机 ID

fabricDiscoveryMachineId这是 Azure Migrate 中发现的 VM 的 Azure 资源管理器 ID。 若要查找它:

(for VMware VMs) GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/VMwareSites/{siteName}/machines?api-version=2023-06-06
(for physical machines) GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure//ServerSites/{siteName}/machines?api-version=2023-06-06

响应返回已发现的计算机的列表,包括其完整的 Azure 资源管理器 (ARM) ID。 每个计算机条目还包括一个友好名称,以帮助标识相应的虚拟机。

示例响应(发现的计算机详细信息)

[
  {
    "id": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/serversites/server-site-name/machines/machine-id",
    "name": "machine-id",
    "type": "Microsoft.OffAzure/serversites/machines",
    "properties": {
      "totalDiskSizeInGB": 60.0,
      "appliancePropertiesCollection": [
        {
          "runAsAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/serversites/server-site-name/runasaccounts/run-as-account-id",
          "applianceName": "appliance-name",
          "status": "Registered"
        }
      ],
      "displayName": "machine-hostname",
      "provisioningState": "Succeeded",
      "errors": [],
      "arcDiscovery": {
        "status": "Unknown",
        "machineResourceId": null
      },
      "numberOfSecurityRisks": -1,
      "numberOfSoftware": -1,
      "hypervisor": null,
      "discoverySource": "Appliance",
      "processorInfo": null,
      "autoEnableDependencyMapping": "ValidationInProgress",
      "disks": [
        {
          "diskId": "disk-guid-1",
          "usedSpaceInBytesV2": null,
          "id": "\\\\.\\PHYSICALDRIVE0",
          "generatedId": "disk-guid-1",
          "maxSizeInBytes": 53687091200,
          "usedSpaceInBytes": 0,
          "name": "disk-guid-1",
          "diskType": "Basic",
          "lun": 0,
          "path": "\\\\.\\PHYSICALDRIVE0",
          "logicalSectorSizeInBytes": 0
        },
        {
          "diskId": "disk-guid-2",
          "usedSpaceInBytesV2": null,
          "id": "\\\\.\\PHYSICALDRIVE1",
          "generatedId": "disk-guid-2",
          "maxSizeInBytes": 10737418240,
          "usedSpaceInBytes": 0,
          "name": "disk-guid-2",
          "diskType": "Basic",
          "lun": 0,
          "path": "\\\\.\\PHYSICALDRIVE1",
          "logicalSectorSizeInBytes": 0
        }
      ],
      "totalFreeSpaceOfAllDisksInGB": 0.0,
      "fqdn": "machine-hostname",
      "networkAdapters": [
        {
          "nicId": "Intel(R) 82574L Gigabit Network Connection",
          "macAddress": "XX:XX:XX:XX:XX:XX",
          "ipAddressList": [],
          "networkName": "Intel(R) 82574L Gigabit Network Connection",
          "ipAddressType": "Dynamic"
        }
      ],
      "hydratedFqdn": "machine-hostname",
      "validationRequired": null,
      "firmware": "UEFI",
      "guestOSDetails": {
        "osType": null,
        "osName": null,
        "osVersion": null,
        "osArchitecture": null
      },
      "numberOfApplications": -1,
      "guestDetailsDiscoveryTimestamp": null,
      "isFileServerSupported": null,
      "isGuestDetailsDiscoveryInProgress": true,
      "dependencyMapping": "Disabled",
      "dependencyMappingStartTime": null,
      "dependencyMappingEndTime": null,
      "runAsAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/serversites/server-site-name/runasaccounts/run-as-account-id",
      "applianceNames": [
        "appliance-name"
      ],
      "distinctErrorCount": 0,
      "applicationDiscovery": {
        "discoveryScopeStatus": "DiscoveryInProgress",
        "errors": [],
        "hydratedRunAsAccountId": null
      },
      "dependencyMapDiscovery": {
        "discoveryScopeStatus": "DiscoveryInProgress",
        "errors": [],
        "hydratedRunAsAccountId": null
      },
      "staticDiscovery": {
        "discoveryScopeStatus": "DiscoverySucceeded",
        "errors": [],
        "hydratedRunAsAccountId": null
      },
      "sqlDiscovery": {
        "successfullyDiscoveredServerCount": -1,
        "totalServerCount": -1,
        "sqlMetadataHydratedRunAsAccountId": null,
        "sqlMetadataDiscoveryPipe": "Unknown",
        "discoveryScopeStatus": "DiscoveryInProgress"
      },
      "webAppDiscovery": {
        "totalWebServerCount": 0,
        "totalWebApplicationCount": 0,
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "oracleDiscovery": {
        "totalInstanceCount": 0,
        "totalDatabaseCount": 0,
        "shallowDiscoveryStatus": "Disabled",
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "springBootDiscovery": {
        "totalInstanceCount": 0,
        "totalApplicationCount": 0,
        "shallowDiscoveryStatus": "Disabled",
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "mySQLDiscovery": {
        "totalInstanceCount": 0,
        "totalDatabaseCount": 0,
        "shallowDiscoveryStatus": "Disabled",
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "pgSQLDiscovery": {
        "totalInstanceCount": 0,
        "totalDatabaseCount": 0,
        "shallowDiscoveryStatus": "Disabled",
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "fileShareDiscovery": {
        "totalFileShareCount": 0,
        "shallowDiscoveryStatus": "Disabled",
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "iisDiscovery": {
        "totalWebServerCount": 0,
        "totalWebApplicationCount": 0,
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "tomcatDiscovery": {
        "totalWebServerCount": 0,
        "totalWebApplicationCount": 0,
        "discoveryScopeStatus": "DiscoverySucceeded"
      },
      "appsAndRoles": null,
      "totalApplicationCount": 0,
      "totalInstanceCount": -1,
      "ipAddresses": "",
      "productSupportStatus": {
        "currentVersion": "6.2.9200",
        "esuStatus": "Unknown",
        "supportStatus": "Unknown",
        "supportEndDate": "0001-01-01T00:00:00",
        "esuYear": "Unknown"
      },
      "discoveredWorkloads": [],
      "eTag": "redacted",
      "numberOfProcessorCore": 2,
      "allocatedMemoryInMB": 4095.0,
      "operatingSystemDetails": {
        "osType": "WindowsGuest",
        "osName": "Windows NT 6.2Build 9200 ",
        "osVersion": "6.2.9200",
        "osArchitecture": "x64"
      },
      "biosSerialNumber": null,
      "biosGuid": "bios-guid",
      "isDeleted": false,
      "createdTimestamp": "2026-03-30T12:50:24.3488832Z",
      "tags": {},
      "updatedTimestamp": "2026-03-30T14:34:17.2385399Z"
    },
    "tags": {}
  }
]

获取 Run-As 帐户 ID(可选)

若要推送安装移动代理,必须指定凭据:

(for VMware VMs) GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/VMwareSites/{siteName}/runasaccounts?api-version=2023-06-06

对于物理计算机,请使用计算机详细信息中的 properties.runAsAccountId runasaccount。

示例响应(以帐户详细信息运行)

[
  {
    "id": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/serversites/server-site-name/runasaccounts/run-as-account-id-1",
    "name": "run-as-account-id-1",
    "type": "Microsoft.OffAzure/serversites/runasaccounts",
    "properties": {
      "displayName": "Admin",
      "credentialType": "WindowsServer",
      "createdTimestamp": "2026-03-27T09:55:26.2199115Z",
      "updatedTimestamp": "2026-03-27T10:03:36.9959594Z",
      "applianceName": "appliance-name"
    }
  },
  {
    "id": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/serversites/server-site-name/runasaccounts/run-as-account-id-2",
    "name": "run-as-account-id-2",
    "type": "Microsoft.OffAzure/serversites/runasaccounts",
    "properties": {
      "displayName": "credentialLessRunAsAccount",
      "credentialType": "CredentialLessAccount",
      "createdTimestamp": "2026-03-27T09:55:26.3762304Z",
      "updatedTimestamp": "2026-03-27T10:03:37.2459485Z",
      "applianceName": "appliance-name"
    }
  }
]

迁移工作流概述

基于 REST API 的Azure Site Recovery迁移工作流包括以下步骤:

  1. 启用复制 - 开始将 VMware VM 复制到 Azure。
  2. 更新复制设置 - 根据需要修改目标 VM 属性。
  3. 测试迁移 - 验证迁移而不影响生产。
  4. 执行迁移 - 执行到 Azure 的实际迁移(故障转移)。

身份验证

所有 REST API 调用都需要使用 Microsoft Entra ID 进行身份验证。 若要进行身份验证,请使用支持的方法之一获取持有者访问令牌。

  • Azure CLI:az account get-access-token
  • Azure PowerShell: Get-AzAccessToken
  • Azure SDK 身份验证库

在标头中包含 Authorization 令牌:

Authorization: Bearer <access-token>

或者,可以在 PowerShell 中使用 armclient 或 Invoke-AzRestMethod。

Note

本文中的所有示例都使用 Azure Site Recovery 资源提供程序的 2025-08-01 API 版本。 确保所有 REST 请求都指定了相同的 API 版本。

步骤 1:启用复制

若要开始将 VM 复制到 Azure,请使用 创建复制保护项 API。

请求

PUT https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}?api-version={api_version}

请求正文

{
  "properties": {
    "policyId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationPolicies/24-hour-replication-policy",
    "providerSpecificDetails": {
        "instanceType": "InMageRcm",
        "fabricDiscoveryMachineId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/machines/machine-id",
        "licenseType": "NoLicenseType",
        "disksToInclude": [
            {
                "diskId": "disk-id-1",
                "logStorageAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Storage/storageAccounts/storage-account-name",
                "diskType": "Standard_LRS",
                "isFabricDiscoveryDiskId": "true",
                "sectorSizeInBytes": 0,
                "diskSizeInGB": 50
            },
            {
                "diskId": "disk-id-2",
                "logStorageAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Storage/storageAccounts/storage-account-name",
                "diskType": "Standard_LRS",
                "isFabricDiscoveryDiskId": "true",
                "sectorSizeInBytes": 0,
                "diskSizeInGB": 10
            }
        ],
        "processServerId": "process-server-id",
        "runAsAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/runasaccounts/run-as-account-id",
        "targetNetworkId": "/subscriptions/subscription-id/resourceGroups/target-resource-group/providers/Microsoft.Network/virtualNetworks/vnet-name",
        "targetSubnetName": "default",
        "targetResourceGroupId": "/subscriptions/subscription-id/resourceGroups/target-resource-group",
        "targetVmSecurityProfile": {
            "targetVmConfidentialEncryption": "Disabled",
            "targetVmTpm": "Enabled",
            "targetVmSecureBoot": "Enabled",
            "targetVmSecurityType": "TrustedLaunch"
        },
        "targetBootDiagnosticsStorageAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Storage/storageAccounts/storage-account-name",
        "linuxLicenseType": "NoLicenseType",
        "targetVmName": "target-vm-name"
    },
    "protectableItemId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/machines/machine-id"
  }
}

InMageRcm 启用保护输入参数

参数 必选 Description
instanceType 是的 必须是 InMageRcm
fabricDiscoveryMachineId 是的 Azure Migrate 中发现的 VMware 计算机的 Azure 资源管理器 ID
processServerId 是的 要用于复制的进程服务器的 ID
targetResourceGroupId 是的 Azure 中目标资源组的 Azure 资源管理器 ID
disksToInclude 是的* 包含其配置的待复制磁盘列表
disksDefault 是的* 默认磁盘配置(使用disksToIncludedisksDefault,不能同时使用)
targetNetworkId 目标虚拟网络的 Azure 资源管理器 ID
testNetworkId 测试虚拟网络的 Azure 资源管理器 ID
targetSubnetName 目标子网的名称
testSubnetName 测试子网的名称
targetVmName 目标 Azure VM 的名称
targetVmSize Azure VM 大小(例如 Standard_D2s_v3
licenseType 许可证类型: NoLicenseTypeWindowsServer
sqlServerLicenseType SQL Server 许可证:NotSpecified、、NoLicenseTypePAYGAHUB
linuxLicenseType Linux 许可证:NotSpecified、、NoLicenseTypeRHEL_BYOSSLES_BYOS
targetAvailabilitySetId 目标可用性集的 Azure 资源管理器 ID
targetAvailabilityZone 目标可用性区域(1、2 或 3)
targetProximityPlacementGroupId 目标邻近放置组的 Azure 资源管理器 ID
targetBootDiagnosticsStorageAccountId 启动诊断存储帐户的 Azure 资源管理器 ID
runAsAccountId 用于安装移动代理的运行方式帐户的 Azure 资源管理器 ID
multiVmGroupName 多虚拟机(VM)一致性组名称
targetVmTags 要应用于目标 VM 的标记
seedManagedDiskTags 种子管理磁盘的标签
targetManagedDiskTags 目标托管磁盘的标记
targetNicTags 目标 NIC 的标记

磁盘输入参数

使用 disksToInclude时,每个磁盘对象都需要:

参数 必选 Description
diskId 是的 要复制的磁盘的 UUID
diskType 是的 目标磁盘类型:Standard_LRS、、Premium_LRSStandardSSD_LRSPremium_ZRSStandardSSD_ZRS
logStorageAccountId 是的 用于复制的缓存存储帐户的 Azure 资源管理器 ID
diskEncryptionSetId 用于服务器端加密的磁盘加密集的 Azure 资源管理器 ID

使用 disksDefault 时:

参数 必选 Description
diskType 是的 所有磁盘的默认磁盘类型
logStorageAccountId 是的 缓存存储帐户的 Azure 资源管理器 ID
diskEncryptionSetId 默认磁盘加密集的 Azure 资源管理器 ID

响应

成功的请求返回 HTTP 200(OK)或 202(已接受),其中包含复制受保护的项详细信息并跟踪启用复制作业。

    {
                        "id": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name/replicationProtectionContainers/replication-container/replicationProtectedItems/machine-id",
                        "name": "machine-id",
                        "type": "Microsoft.RecoveryServices/vaults/replicationFabrics/replicationProtectionContainers/replicationProtectedItems",
                        "properties": {
                            "friendlyName": "target-vm-name",
                            "protectedItemType": "",
                            "protectableItemId": null,
                            "recoveryServicesProviderId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name/replicationRecoveryServicesProviders/process-server-id",
                            "primaryFabricFriendlyName": "fabric-name",
                            "primaryFabricProvider": "InMageRcmFabric",
                            "recoveryFabricFriendlyName": "Microsoft Azure",
                            "recoveryFabricId": "Microsoft Azure",
                            "primaryProtectionContainerFriendlyName": "replication-container",
                            "recoveryProtectionContainerFriendlyName": "Microsoft Azure",
                            "protectionState": "UnplannedFailoverFailed",
                            "protectionStateDescription": "Failover failed",
                            "activeLocation": "Primary",
                            "testFailoverState": "MarkedForDeletion",
                            "testFailoverStateDescription": "Cleaning up test environment",
                            "switchProviderState": "None",
                            "switchProviderStateDescription": null,
                            "allowedOperations": [
                                "UnplannedFailover",
                                "DisableProtection",
                                "TestFailover"
                            ],
                            "replicationHealth": "Critical",
                            "failoverHealth": "Warning",
                            "healthErrors": [
                                {
                                    "innerHealthErrors": [],
                                    "errorSource": "ReplicationUnitFailoverValidatorError",
                                    "errorType": "15",
                                    "errorLevel": "Warning",
                                    "errorCategory": "TestFailover",
                                    "errorCode": "161011",
                                    "summaryMessage": "",
                                    "errorMessage": "No successful test failover has been done on the virtual machine 'target-vm-name'.",
                                    "possibleCauses": "No successful test failover has been done on the virtual machine after it was replicated.",
                                    "recommendedAction": "Do a test failover on the virtual machine.",
                                    "creationTimeUtc": "2026-04-20T20:53:29.879895Z",
                                    "recoveryProviderErrorMessage": null,
                                    "entityId": "internal-id",
                                    "errorId": "6:15",
                                    "customerResolvability": "NotAllowed"
                                }
                            ],
                            "policyId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationPolicies/24-hour-replication-policy",
                            "policyFriendlyName": "24-hour-replication-policy",
                            "currentScenario": {
                                "scenarioName": "None",
                                "jobId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationJobs/None",
                                "startTime": "1753-01-01T01:01:01Z"
                            },
                            "failoverRecoveryPointId": null,
                            "providerSpecificDetails": {
                                "instanceType": "InMageRcm",
                                "internalIdentifier": "internal-id",
                                "fabricDiscoveryMachineId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/machines/machine-id",
                                "multiVmGroupName": null,
                                "discoveryType": "VCenter",
                                "processServerId": "process-server-id",
                                "processorCoreCount": 2,
                                "allocatedMemoryInMB": 4095.0,
                                "processServerName": "appliance-name",
                                "runAsAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/runasaccounts/run-as-account-id",
                                "osType": "Windows",
                                "firmwareType": "UEFI",
                                "primaryNicIpAddress": "ip-address",
                                "targetGeneration": "V2",
                                "licenseType": "NoLicenseType",
                                "storageAccountId": null,
                                "targetVmName": "target-vm-name",
                                "targetVmSize": "Standard_F2s_v2",
                                "targetResourceGroupId": "/subscriptions/subscription-id/resourceGroups/target-resource-group",
                                "targetLocation": "chinaeast2chinanorth3",
                                "targetAvailabilitySetId": "",
                                "targetAvailabilityZone": "",
                                "targetProximityPlacementGroupId": "",
                                "targetBootDiagnosticsStorageAccountId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Storage/storageAccounts/storage-account",
                                "targetNetworkId": "/subscriptions/subscription-id/resourceGroups/target-network-rg/providers/Microsoft.Network/virtualNetworks/vnet-name",
                                "testNetworkId": "/subscriptions/subscription-id/resourceGroups/target-network-rg/providers/Microsoft.Network/virtualNetworks/vnet-name",
                                "failoverRecoveryPointId": null,
                                "lastRecoveryPointReceived": "2026-04-19T13:41:58.1335596Z",
                                "lastRpoInSeconds": 3399,
                                "lastRpoCalculatedTime": "2026-04-19T14:38:36.6808164Z",
                                "lastRecoveryPointId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/fabric-name/replicationProtectionContainers/cloud_cloud-id/replicationProtectedItems/machine-id/recoveryPoints/recovery-point-id",
                                "initialReplicationProgressPercentage": null,
                                "initialReplicationProcessedBytes": null,
                                "initialReplicationTransferredBytes": null,
                                "initialReplicationProgressHealth": "None",
                                "resyncProgressPercentage": null,
                                "resyncProcessedBytes": null,
                                "resyncTransferredBytes": null,
                                "resyncProgressHealth": "None",
                                "resyncRequired": "false",
                                "resyncState": "None",
                                "agentUpgradeState": "None",
                                "lastAgentUpgradeType": null,
                                "agentUpgradeJobId": null,
                                "agentUpgradeAttemptToVersion": null,
                                "protectedDisks": [],
                                "unprotectedDisks": [],
                                "isLastUpgradeSuccessful": "false",
                                "isAgentRegistrationSuccessfulAfterFailover": null,
                                "mobilityAgentDetails": {
                                    "version": "9.66.7643.1",
                                    "latestVersion": null,
                                    "latestAgentReleaseDate": null,
                                    "driverVersion": "9.66.7611.1",
                                    "latestUpgradableVersionWithoutReboot": null,
                                    "lastHeartbeatUtc": "2026-04-19T13:47:24.8791557Z",
                                    "reasonsBlockingUpgrade": [
                                        "AlreadyOnLatestVersion"
                                    ],
                                    "isUpgradeable": "false"
                                },
                                "lastAgentUpgradeErrorDetails": [],
                                "agentUpgradeBlockingErrorDetails": [],
                                "vmNics": [],
                                "discoveredVmDetails": {
                                    "vCenterId": "/subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.OffAzure/VMwareSites/vmware-site-name/vcenters/vcenter-name",
                                    "vCenterFqdn": "",
                                    "datastores": [
                                        "datastore-name"
                                    ],
                                    "ipAddresses": [],
                                    "vmwareToolsStatus": "NotRunning",
                                    "powerStatus": "OFF",
                                    "vmFqdn": "",
                                    "osName": "Windows Server 2019",
                                    "createdTimestamp": "2026-04-12T17:30:44.93064+00:00",
                                    "updatedTimestamp": "2026-04-19T13:58:29.1016242+00:00",
                                    "isDeleted": false,
                                    "lastDiscoveryTimeInUtc": "2026-04-19T14:48:39.4886738Z"
                                },
                                "targetVmTags": [],
                                "seedManagedDiskTags": null,
                                "targetManagedDiskTags": null,
                                "targetNicTags": null,
                                "sqlServerLicenseType": "NotSpecified",
                                "supportedOSVersions": null,
                                "osName": "Microsoft Windows Server 2022 Datacenter",
                                "targetVmSecurityProfile": {
                                    "targetVmSecurityType": "None",
                                    "targetVmSecureBoot": "Disabled",
                                    "targetVmTpm": "Disabled",
                                    "targetVmMonitoring": "Disabled",
                                    "targetVmConfidentialEncryption": "Disabled"
                                }
                            },
                            "recoveryContainerId": "/Subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.RecoveryServices/vaults/vault-name/replicationFabrics/recovery-fabric-id/replicationProtectionContainers/recovery-container-id",
                            "eventCorrelationId": "event-correlation-id"
                        }
                    }
                ],
                "nextLink": null
            },
            "contentLength": 12791
        }

步骤 2:更新复制设置

启用复制后,可以使用 更新复制保护项 API 修改目标 VM 属性。

请求

PATCH https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}?api-version={api_version}

请求正文

{
  "properties": {
    "providerSpecificDetails": {
      "instanceType": "InMageRcm",
      "targetVmName": "{newTargetVmName}",
      "targetVmSize": "Standard_D4s_v3",
      "targetResourceGroupId": "/subscriptions/{subscriptionId}/resourceGroups/{newTargetResourceGroupName}",
      "targetNetworkId": "/subscriptions/{subscriptionId}/resourceGroups/{networkResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{newVnetName}",
      "testNetworkId": "/subscriptions/{subscriptionId}/resourceGroups/{networkResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{newTestVnetName}",
      "targetAvailabilitySetId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}",
      "targetAvailabilityZone": "",
      "targetProximityPlacementGroupId": "",
      "targetBootDiagnosticsStorageAccountId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}",
      "licenseType": "WindowsServer",
      "sqlServerLicenseType": "AHUB",
      "linuxLicenseType": "NoLicenseType",
      "vmNics": [
        {
          "nicId": "{sourceNicId}",
          "isPrimaryNic": true,
          "targetSubnetName": "{subnetName}",
          "targetStaticIPAddress": "10.0.0.10",
          "testSubnetName": "{testSubnetName}",
          "testStaticIPAddress": "10.1.0.10",
          "isSelectedForMigration": true
        }
      ],
      "targetVmTags": [
        {
          "tagName": "Environment",
          "tagValue": "Production"
        }
      ],
      "targetManagedDiskTags": [
        {
          "tagName": "Project",
          "tagValue": "Migration"
        }
      ],
      "vmDisks": [
        {
          "diskId": "{diskUuid}",
          "targetDiskName": "{customDiskName}"
        }
      ]
    }
  }
}

InMageRcm 更新保护输入参数

参数 Description
instanceType 必须是 InMageRcm
targetVmName 已更新目标 Azure VM 的名称
targetVmSize 更新了 Azure VM 大小
targetResourceGroupId 更新了目标资源组的 Azure 资源管理器 ID
targetNetworkId 更新了目标虚拟网络 Azure 资源管理器 ID
testNetworkId 更新了测试虚拟网络的 Azure 资源管理器 ID
targetAvailabilitySetId 更新了可用性集 Azure 资源管理器 ID(设置为空字符串以删除)
targetAvailabilityZone 更新了可用性区域(设置为空字符串以进行移除)
targetProximityPlacementGroupId 更新了邻近放置组 Azure 资源管理器 识别码
targetBootDiagnosticsStorageAccountId 更新了启动诊断存储帐户 Azure 资源管理器 ID
licenseType 更新的许可证类型
sqlServerLicenseType 更新了 SQL Server 许可证类型
linuxLicenseType 更新了 Linux 许可证类型
vmNics NIC 配置列表
targetVmTags 应用于目标 VM 的标记
targetManagedDiskTags 要应用于目标磁盘的标记
targetNicTags 要应用于目标 NIC 的标记
vmDisks 具有自定义名称的磁盘配置列表

NIC 输入参数

参数 Description
nicId 源 NIC 标识符
isPrimaryNic 这是否是主 NIC
targetSubnetName 迁移的目标子网名称
targetStaticIPAddress 用于迁移的静态 IP 地址
testSubnetName 测试迁移的子网名称
testStaticIPAddress 用于测试迁移的静态 IP
isSelectedForMigration 是否在迁移中包含此 NIC

步骤 3:测试迁移

Important

在进行实际迁移之前,请始终执行测试迁移(测试故障切换)以验证配置。

使用 测试故障转移 API。

请求

POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}/testFailover?api-version={api_version}

请求正文

{
  "properties": {
    "failoverDirection": "PrimaryToRecovery",
    "networkType": "VmNetworkAsInput",
    "networkId": "/subscriptions/{subscriptionId}/resourceGroups/{networkResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{testVnetName}",
    "providerSpecificDetails": {
      "instanceType": "InMageRcm",
      "networkId": "/subscriptions/{subscriptionId}/resourceGroups/{networkResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{testVnetName}",
      "recoveryPointId": ""
    }
  }
}

从最新处理的恢复点中选择一个,以最大程度地减少数据丢失。 使用properties.providerSpecificDetails.lastRecoveryPointId返回的值。

InMageRcm 测试故障转移输入参数

参数 必选 Description
instanceType 是的 必须是 InMageRcm
networkId 测试网络的 Azure 资源管理器 ID。 如果未指定,请使用配置的测试网络。
recoveryPointId 特定恢复点的 Azure 资源管理器 ID。 为最新恢复点留空。
osUpgradeVersion 测试迁移期间 OS 就地升级的目标 OS 版本

响应

API 返回跟踪测试迁移进度的作业:

{
  "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationJobs/{jobId}",
  "name": "{jobId}",
  "type": "Microsoft.RecoveryServices/vaults/replicationJobs",
  "properties": {
    "activityId": "{activityId}",
    "scenarioName": "TestFailover",
    "friendlyName": "Test failover",
    "state": "InProgress"
  }
}

测试故障转移清理

验证测试迁移后,使用 测试故障转移清理 API 清理测试资源。

POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}/testFailoverCleanup?api-version={api_version}
{
  "properties": {
    "comments": "Test migration validation completed successfully"
  }
}

步骤 4:执行迁移(故障转移)

准备好将 VM 迁移到 Azure 时,请使用 计划外故障转移 API。

请求

POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}/unplannedFailover?api-version={api_version}

请求正文

{
  "properties": {
    "failoverDirection": "PrimaryToRecovery",
    "sourceSiteOperations": "NotRequired",
    "providerSpecificDetails": {
      "instanceType": "InMageRcm",
      "recoveryPointId": "",
      "performShutdown": false
    }
  }
}

InMageRcm 故障转移输入参数

参数 必选 Description
instanceType 是的 必须是 InMageRcm
recoveryPointId 用于故障转移的恢复点的 Azure 资源管理器 ID。 留空以使用最新版本。
performShutdown 是否在故障转移前关闭源 VM(建议尽量减少数据丢失)
osUpgradeVersion 迁移期间就地 OS 升级的目标 OS 版本
targetCapacityReservationGroupId 目标容量预留组的 Azure 资源管理器 ID

响应

{
  "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationJobs/{jobId}",
  "name": "{jobId}",
  "type": "Microsoft.RecoveryServices/vaults/replicationJobs",
  "properties": {
    "activityId": "{activityId}",
    "scenarioName": "UnplannedFailover",
    "friendlyName": "Unplanned failover",
    "state": "InProgress"
  }
}

步骤 5:完成或禁用迁移

成功故障转移后,禁用复制以使用 删除 API 清理资源:

DELETE https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectedItems/{replicatedItemName}?api-version={api_version}

监控任务

使用获取作业 API 跟踪迁移操作的状态:

GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/replicationJobs/{jobId}?api-version={api_version}

作业状态包括:

  • NotStarted
  • InProgress
  • Succeeded
  • Failed
  • Cancelled

错误处理

常见的错误方案和解决方法:

错误 解决方案
InvalidParameter 确保所有必需的参数都提供了有效值
ResourceNotFound 确保所有 Azure 资源管理器资源 ID 正确且资源存在
ReplicationNotHealthy 在测试/实际迁移之前检查复制运行状况
RecoveryPointNotFound 使用最新的恢复点或验证指定的恢复点是否存在

有关更多详细信息,请参阅 故障排除

PowerShell 自动化示例

Azure PowerShell 示例包括用于启用迁移、运行测试迁移、清理测试迁移、执行迁移和禁用迁移的脚本。 这些脚本从 CSV 文件获取输入。 将这些示例用作集成参考。

最佳做法

  • 首先运行测试迁移:始终执行测试迁移,以在开始实际迁移之前验证配置。
  • 使用适当的恢复点:若要最大程度地减少数据丢失,请选择最新处理的恢复点。
  • 监视复制运行状况:在启动迁移之前验证复制是否正常。
  • 计划维护时段:在计划的维护时段内安排迁移。
  • 批量迁移:将虚拟机分组到多 VM 一致性组,以启用应用程序一致性迁移。
  • 在验证之前保留恢复点:在生产环境中验证迁移之前保留恢复点。

后续步骤

编写脚本以自动执行上述步骤。 如果遇到任何问题,请联系Azure 支持。