您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

将资源移到新资源组或订阅中Move resources to new resource group or subscription

本文说明了如何将 Azure 资源移动到另一 Azure 订阅,或移动到同一订阅下的另一资源组。This article shows you how to move Azure resources to either another Azure subscription or another resource group under the same subscription. 可以使用 Azure 门户、Azure PowerShell、Azure CLI 或 REST API 移动资源。You can use the Azure portal, Azure PowerShell, Azure CLI, or the REST API to move resources.

在移动操作过程中,源组和目标组都会锁定。Both the source group and the target group are locked during the move operation. 在完成移动之前,将阻止对资源组执行写入和删除操作。Write and delete operations are blocked on the resource groups until the move completes. 此锁意味着将无法添加、更新或删除资源组中的资源,但并不意味着资源已被冻结。This lock means you can't add, update, or delete resources in the resource groups, but it doesn't mean the resources are frozen. 例如,如果将 SQL Server 及其数据库移动到新的资源组中,则使用该数据库的应用程序将不会遇到停机的情况。For example, if you move a SQL Server and its database to a new resource group, an application that uses the database experiences no downtime. 它仍可读取和写入到数据库。It can still read and write to the database.

移动资源仅能够将其移动到新的资源组。Moving a resource only moves it to a new resource group. 移动操作不能更改该资源的位置。The move operation can't change the location of the resource. 新的资源组可能有不同的位置,但这不会更改该资源的位置。The new resource group may have a different location, but that doesn't change the location of the resource.

备注

本文介绍如何在现有 Azure 帐户产品/服务中移动资源。This article describes how to move resources within an existing Azure account offering. 如果确实想要更改 Azure 帐户产品/服务(例如从免费升级到即用即付),则需要转换订阅。If you actually want to change your Azure account offering (such as upgrading from free to pay-as-you-go) you need to convert your subscription.

何时致电 Azure 支持人员When to call Azure support

可以通过本文中所述的自助服务操作移动大部分资源。You can move most resources through the self-service operations shown in this article. 使用自助服务操作可以:Use the self-service operations to:

有以下需要时,请联系支持人员Contact support when you need to:

  • 将资源移到新的 Azure 帐户(和 Azure Active Directory 租户),并且对于上一部分中的说明需要帮助。Move your resources to a new Azure account (and Azure Active Directory tenant) and you need help with the instructions in the preceding section.
  • 移动经典资源时遇到限制方面的问题。Move classic resources but are having trouble with the limitations.

可以移动的服务Services that can be moved

以下列表汇总提供了可移动到新资源组和订阅的 Azure 服务。The following list provides a general summary of Azure services that can be moved to a new resource group and subscription. 有关更为详细的信息,请参阅支持移动操作的资源For greater detail, see Move operation support for resources.

  • Analysis ServicesAnalysis Services
  • API 管理API Management
  • 应用服务应用(Web 应用)- 请参阅应用服务限制App Service apps (web apps) - see App Service limitations
  • 应用服务证书 - 请参阅应用服务证书限制App Service Certificates - see App Service Certificate limitations
  • 自动化Automation
  • Azure Active Directory B2CAzure Active Directory B2C
  • Azure Cosmos DBAzure Cosmos DB
  • Azure Database for MySQLAzure Database for MySQL
  • Azure Database for PostgreSQLAzure Database for PostgreSQL
  • Azure DevOps - 具有非 Microsoft 扩展购买的 Azure DevOps 组织必须先取消其购买,然后才能跨订阅移动帐户。Azure DevOps - Azure DevOps organizations with non-Microsoft extension purchases must cancel their purchases before they can move the account across subscriptions.
  • Azure MapsAzure Maps
  • Azure 中继Azure Relay
  • Azure Stack - 注册Azure Stack - registrations
  • BatchBatch
  • BizTalk 服务BizTalk Services
  • Bot 服务Bot Service
  • CDNCDN
  • 云服务 - 请参阅经典部署限制Cloud Services - see Classic deployment limitations
  • 认知服务Cognitive Services
  • 容器注册表 - 启用异地复制后无法移动容器注册表。Container Registry - A container registry can't be moved when geo-replication is enabled.
  • 内容审查器Content Moderator
  • 成本管理Cost Management
  • Customer InsightsCustomer Insights
  • 数据目录Data Catalog
  • 数据工厂Data Factory
  • Data Lake AnalyticsData Lake Analytics
  • Data Lake StoreData Lake Store
  • DNSDNS
  • 事件网格Event Grid
  • 事件中心Event Hubs
  • Front DoorFront Door
  • HDInsight 群集 - 请参阅 HDInsight 限制HDInsight clusters - see HDInsight limitations
  • IoT 中心Iot Central
  • IoT 中心IoT Hubs
  • Key Vault - 用于磁盘加密的 Key Vault 不能移动到同一订阅中的资源组,也不能跨订阅移动。Key Vault - Key Vaults used for disk encryption can't be moved to resource groups in the same subscription or across subscriptions.
  • 负载均衡器 - 可以移动基本 SKU 负载均衡器。Load Balancers - Basic SKU Load Balancer can be moved. 不能移动标准 SKU 负载均衡器。Standard SKU Load Balancer can't be moved.
  • Log AnalyticsLog Analytics
  • 逻辑应用Logic Apps
  • 机器学习 - 机器学习工作室 Web 服务可以移动到同一订阅中的资源组,但不能移动到不同订阅中。Machine Learning - Machine Learning Studio web services can be moved to a resource group in the same subscription, but not a different subscription. 其他机器学习资源可以跨订阅进行移动。Other Machine Learning resources can be moved across subscriptions.
  • 托管磁盘 - 请参阅虚拟机针对约束的限制Managed Disks - see Virtual Machines limitations for constraints
  • 托管标识 - 用户分配Managed Identity - user-assigned
  • 媒体服务Media Services
  • 监视器 - 确保移动到新订阅时,不会超出订阅配额Monitor - make sure moving to new subscription doesn't exceed subscription quotas
  • 通知中心Notification Hubs
  • 操作见解Operational Insights
  • 操作管理Operations Management
  • 门户仪表板Portal dashboards
  • Power BI - Power BI Embedded 和 Power BI 工作区集合Power BI - both Power BI Embedded and Power BI Workspace Collection
  • 公共 IP - 可以移动基本 SKU 公共 IP。Public IP - Basic SKU Public IP can be moved. 不能移动标准 SKU 公共 IP。Standard SKU Public IP can't be moved.
  • 恢复服务保管库 - 你必须注册受限公共预览版Recovery Services vault - you must be enrolled in a limited public preview.
  • Azure Redis 缓存 - 如果 Azure Redis 缓存实例配置了虚拟网络,则实例无法被移动到其他订阅。Azure Cache for Redis - if the Azure Cache for Redis instance is configured with a virtual network, the instance can't be moved to a different subscription. 请参阅虚拟网络限制See Virtual Networks limitations.
  • 计划程序Scheduler
  • 搜索 - 不能一次性移动不同区域中的多个搜索资源。Search - You can't move several Search resources in different regions in one operation. 只能通过多个单独的操作移动它们。Instead, move them in separate operations.
  • 服务总线Service Bus
  • Service FabricService Fabric
  • Service Fabric 网格Service Fabric Mesh
  • SignalR 服务SignalR Service
  • 存储 - 不同区域中的存储帐户不能在同一操作中移动。Storage - storage accounts in different regions can't be moved in the same operation. 相反,为每个区域使用单独的操作。Instead, use separate operations for each region.
  • 存储(经典)- 请参阅经典部署限制Storage (classic) - see Classic deployment limitations
  • 流分析 - 当流分析作业处于运行状态时,则无法进行移动。Stream Analytics - Stream Analytics jobs can't be moved when in running state.
  • SQL 数据库服务器 - 数据库和服务器必须位于同一个资源组中。SQL Database server - database and server must be in the same resource group. 当移动 SQL 服务器时,其所有数据库也会一起移动。When you move a SQL server, all its databases are also moved. 此行为适用于 Azure SQL 数据库和 Azure SQL 数据仓库数据库。This behavior applies to Azure SQL Database and Azure SQL Data Warehouse databases.
  • 时序见解Time Series Insights
  • 流量管理器Traffic Manager
  • 虚拟机 - 针对使用托管磁盘的虚拟机,请参阅虚拟机限制Virtual Machines - for VMs with managed disks, see Virtual Machines limitations
  • 虚拟机(经典)- 请参阅经典部署限制Virtual Machines (classic) - see Classic deployment limitations
  • 虚拟机规模集 - 请参阅虚拟机限制Virtual Machine Scale Sets - see Virtual Machines limitations
  • 虚拟网络 - 请参阅虚拟网络限制Virtual Networks - see Virtual Networks limitations
  • VPN 网关VPN Gateway

无法移动的服务Services that cannot be moved

以下列表汇总提供了不能移动到新资源组和订阅的 Azure 服务。The following list provides a general summary of Azure services that can't be moved to a new resource group and subscription. 有关更为详细的信息,请参阅支持移动操作的资源For greater detail, see Move operation support for resources.

  • AD 域服务AD Domain Services
  • AD 混合运行状况服务AD Hybrid Health Service
  • 应用程序网关Application Gateway
  • Azure 数据库迁移Azure Database Migration
  • Azure DatabricksAzure Databricks
  • Azure 防火墙Azure Firewall
  • Azure MigrateAzure Migrate
  • 证书 - 应用服务证书可以移动,但上传的证书存在限制Certificates - App Service Certificates can be moved, but uploaded certificates have limitations.
  • 容器实例Container Instances
  • 容器服务Container Service
  • Data BoxData Box
  • Dev SpacesDev Spaces
  • Dynamics LCSDynamics LCS
  • ExpressRouteExpressRoute
  • Kubernetes 服务Kubernetes Service
  • 实验室服务 - 支持移动到同一订阅中的新资源组,但不支持跨订阅移动。Lab Services - move to new resource group in same subscription is enabled, but cross subscription move isn't enabled.
  • 托管应用程序Managed Applications
  • Microsoft 基因组学Microsoft Genomics
  • NetAppNetApp
  • Azure 上的 SAP HANASAP HANA on Azure
  • 安全Security
  • Site RecoverySite Recovery
  • StorSimple 设备管理器StorSimple Device Manager
  • 虚拟网络(经典)- 请参阅经典部署限制Virtual Networks (classic) - see Classic deployment limitations

限制Limitations

此部分说明如何处理移动资源时的复杂方案。The section provides descriptions of how to handle complicated scenarios for moving resources. 限制如下:The limitations are:

虚拟机限制Virtual Machines limitations

从 2018 年 9 月 24 日起,可以移动托管磁盘。From September 24, 2018, you can move managed disks. 此支持意味着,可以移动包含托管磁盘、托管映像和托管快照的虚拟机,以及移动所含虚拟机使用托管磁盘的可用性集。This support means you can move virtual machines with the managed disks, managed images, managed snapshots, and availability sets with virtual machines that use managed disks.

以下方案尚不受支持:The following scenarios aren't yet supported:

  • 证书存储在 Key Vault 中的虚拟机可以移动到同一订阅中的新资源组,但无法跨订阅进行移动。Virtual Machines with certificate stored in Key Vault can be moved to a new resource group in the same subscription, but not across subscriptions.
  • 无法移动具有标准 SKU 负载均衡器或标准 SKU 公共 IP 的虚拟机规模集Virtual Machine Scale Sets with Standard SKU Load Balancer or Standard SKU Public IP can't be moved
  • 无法跨资源组或订阅移动基于附加了计划的市场资源创建的虚拟机。Virtual machines created from Marketplace resources with plans attached can't be moved across resource groups or subscriptions. 在当前订阅中取消预配虚拟机,并在新的订阅中重新部署虚拟机。Deprovision the virtual machine in the current subscription, and deploy again in the new subscription.

若要移动使用 Azure 备份配置的虚拟机,请使用以下解决方法:To move virtual machines configured with Azure Backup, use the following workaround:

  • 找到虚拟机的位置。Find the location of your Virtual Machine.
  • 找到含有以下命名模式的资源组:AzureBackupRG_<location of your VM>_1 例如,AzureBackupRG_westus2_1Find a resource group with the following naming pattern: AzureBackupRG_<location of your VM>_1 for example, AzureBackupRG_westus2_1
  • 如果在 Azure 门户中,则查看“显示隐藏的类型”If in Azure portal, then check "Show hidden types"
  • 如果在 PowerShell 中,则使用 Get-AzureRmResource -ResourceGroupName AzureBackupRG_<location of your VM>_1 cmdletIf in PowerShell, use the Get-AzureRmResource -ResourceGroupName AzureBackupRG_<location of your VM>_1 cmdlet
  • 如果在 CLI 中,则使用 az resource list -g AzureBackupRG_<location of your VM>_1If in CLI, use the az resource list -g AzureBackupRG_<location of your VM>_1
  • 使用类型 Microsoft.Compute/restorePointCollections 找到具有命名模式 AzureBackup_<name of your VM that you're trying to move>_########### 的资源Find the resource with type Microsoft.Compute/restorePointCollections that has the naming pattern AzureBackup_<name of your VM that you're trying to move>_###########
  • 删除此资源。Delete this resource. 此操作仅删除即时恢复点,不删除保管库中的备份数据。This operation deletes only the instant recovery points, not the backed-up data in the vault.
  • 删除完成后,即可移动虚拟机。After delete is complete, you'll be able to move your Virtual Machine. 可以将保管库和虚拟机移到目标订阅。You can move the vault and virtual machine to the target subscription. 移动后即可继续备份,不会丢失数据。After the move, you can continue backups with no loss in data.
  • 若要了解如何移动恢复服务保管库以完成备份,请参阅恢复服务限制For information about moving Recovery Service vaults for backup, see Recovery Services limitations.

虚拟网络限制Virtual Networks limitations

移动虚拟网络时,还必须移动其从属资源。When moving a virtual network, you must also move its dependent resources. 对于 VPN 网关,必须移动 IP 地址、虚拟网络网关和所有关联的连接资源。For VPN Gateways, you must move IP addresses, virtual network gateways, and all associated connection resources. 本地网络网关可以位于不同的资源组中。Local network gateways can be in a different resource group.

若要移动对等的虚拟网络,必须首先禁用虚拟网络对等互连。To move a peered virtual network, you must first disable the virtual network peering. 在禁用后,可以移动虚拟网络。Once disabled, you can move the virtual network. 在移动后,重新启用虚拟网络对等互连。After the move, reenable the virtual network peering.

如果虚拟网络的任何子网包含资源导航链接,则无法将虚拟网络移动到其他订阅。You can't move a virtual network to a different subscription if the virtual network contains a subnet with resource navigation links. 例如,如果 Azure Redis 缓存资源部署到某个子网,则该子网具有资源导航链接。For example, if an Azure Cache for Redis resource is deployed into a subnet, that subnet has a resource navigation link.

应用服务限制App Service limitations

移动应用服务资源的限制各不相同,具体取决于是在订阅内移动资源,还是将应用服务资源移到新的订阅。The limitations for moving App Service resources differ based on whether you're moving the resources within a subscription or to a new subscription. 如果 Web 应用使用应用服务证书,请参阅应用服务证书限制If your web app uses an App Service Certificate, see App Service Certificate limitations

在同一订阅中移动Moving within the same subscription

在同一订阅中移动 Web 应用时,无法移动第三方 SSL 证书。When moving a Web App within the same subscription, you can't move third-party SSL certificates. 不过,可以将 Web 应用移动到新的资源组而不移动其第三方证书,并且,应用的 SSL 功能仍然可以工作。However, you can move a Web App to the new resource group without moving its third-party certificate, and your app's SSL functionality still works.

如果希望随 Web 应用移动 SSL 证书,请执行以下步骤:If you want to move the SSL certificate with the Web App, follow these steps:

  1. 从 Web 应用中删除第三方证书,但保留证书的副本Delete the third-party certificate from the Web App, but keep a copy of your certificate
  2. 移动 Web 应用。Move the Web App.
  3. 将第三方证书上传到移动后的 Web 应用。Upload the third-party certificate to the moved Web App.

跨订阅移动Moving across subscriptions

在订阅之间_移动 Web 应用时存在以下限制:When moving a Web App _across subscriptions, the following limitations apply:

  • 目标资源组中不能有任何现有的应用服务资源。The destination resource group must not have any existing App Service resources. 应用服务资源包括:App Service resources include:
    • Web 应用Web Apps
    • 应用服务计划App Service plans
    • 上传或导入的 SSL 证书Uploaded or imported SSL certificates
    • 应用服务环境App Service Environments
  • 资源组中的所有应用服务资源必须一起移动。All App Service resources in the resource group must be moved together.
  • 只能从最初创建应用服务资源的资源组中移动它们。App Service resources can only be moved from the resource group in which they were originally created. 如果某个应用服务资源不再位于其原始资源组中,则必须首先将其移动回该原始资源组,然后才能将其在订阅之间移动。If an App Service resource is no longer in its original resource group, it must be moved back to that original resource group first, and then it can be moved across subscriptions.

应用服务证书限制App Service Certificate limitations

可将应用服务证书移动到新的资源组或订阅。You can move your App Service Certificate to a new resource group or subscription. 如果应用服务证书已绑定到某个 Web 应用,必须先执行一些步骤,然后才能将资源移到新的订阅中。If your App Service Certificate is bound to a web app, you must take some steps before moving the resources to a new subscription. 移动资源之前,请在 Web 应用中删除 SSL 绑定和专用证书。Delete the SSL binding and private certificate from the web app before moving the resources. 应用服务证书不需删除,只需删除 Web 应用中的专用证书。The App Service Certificate doesn't need to be deleted, just the private certificate in the web app.

经典部署限制Classic deployment limitations

移动通过经典模型部署的资源时,其选项各不相同,具体取决于是在订阅内移动资源,还是将资源移到新的订阅。The options for moving resources deployed through the classic model differ based on whether you're moving the resources within a subscription or to a new subscription.

相同的订阅Same subscription

在同一订阅内将资源从一个资源组移到另一个资源组时存在以下限制:When moving resources from one resource group to another resource group within the same subscription, the following restrictions apply:

  • 不能移动虚拟网络(经典)。Virtual networks (classic) can't be moved.
  • 虚拟机(经典)必须与云服务一起移动。Virtual machines (classic) must be moved with the cloud service.
  • 移动云服务时,必须移动其所有虚拟机。Cloud service can only be moved when the move includes all its virtual machines.
  • 一次只能移动一项云服务。Only one cloud service can be moved at a time.
  • 一次只能移动一个存储帐户(经典)。Only one storage account (classic) can be moved at a time.
  • 存储帐户(经典)与虚拟机或云服务不能在同一操作中移动。Storage account (classic) can't be moved in the same operation with a virtual machine or a cloud service.

要将经典资源移到同一订阅内的新资源组,请通过门户Azure PowerShellAzure CLIREST API 使用标准移动操作。To move classic resources to a new resource group within the same subscription, use the standard move operations through the portal, Azure PowerShell, Azure CLI, or REST API. 使用的操作应与移动 Resource Manager 资源时所用的操作相同。You use the same operations as you use for moving Resource Manager resources.

新订阅New subscription

将资源移到新订阅时存在以下限制:When moving resources to a new subscription, the following restrictions apply:

  • 必须在同一操作中移动订阅中的所有经典资源。All classic resources in the subscription must be moved in the same operation.
  • 目标订阅不得包含任何其他经典资源。The target subscription must not have any other classic resources.
  • 只能通过独立的适用于经典移动的 REST API 来请求移动。The move can only be requested through a separate REST API for classic moves. 将经典资源移到新订阅时,不能使用标准的资源管理器移动命令。The standard Resource Manager move commands don't work when moving classic resources to a new subscription.

要将经典资源移动到新订阅,请使用特定于经典资源的 REST 操作。To move classic resources to a new subscription, use the REST operations that are specific to classic resources. 若要使用 REST,请执行以下步骤:To use REST, perform the following steps:

  1. 检查源订阅是否可以参与跨订阅移动。Check if the source subscription can participate in a cross-subscription move. 使用以下操作:Use the following operation:

    POST https://management.azure.com/subscriptions/{sourceSubscriptionId}/providers/Microsoft.ClassicCompute/validateSubscriptionMoveAvailability?api-version=2016-04-01
    

    在请求正文中包含以下内容:In the request body, include:

    {
     "role": "source"
    }
    

    验证操作的响应采用以下格式:The response for the validation operation is in the following format:

    {
     "status": "{status}",
     "reasons": [
       "reason1",
       "reason2"
     ]
    }
    
  2. 检查目标订阅是否可以参与跨订阅移动。Check if the destination subscription can participate in a cross-subscription move. 使用以下操作:Use the following operation:

    POST https://management.azure.com/subscriptions/{destinationSubscriptionId}/providers/Microsoft.ClassicCompute/validateSubscriptionMoveAvailability?api-version=2016-04-01
    

    在请求正文中包含以下内容:In the request body, include:

    {
     "role": "target"
    }
    

    响应的格式与源订阅验证相同。The response is in the same format as the source subscription validation.

  3. 如果两个订阅都通过了验证,可使用以下操作将所有经典资源从一个订阅移到另一个订阅:If both subscriptions pass validation, move all classic resources from one subscription to another subscription with the following operation:

    POST https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.ClassicCompute/moveSubscriptionResources?api-version=2016-04-01
    

    在请求正文中包含以下内容:In the request body, include:

    {
     "target": "/subscriptions/{target-subscription-id}"
    }
    

运行该操作可能需要几分钟。The operation may run for several minutes.

恢复服务限制Recovery Services limitations

若要移动恢复服务保管库,你必须注册受限公共预览版To move a Recovery Services vault, you must enroll in the limited public preview.

目前,每个区域一次可以移动一个恢复服务保管库。Currently, you can move one Recovery Services vault, per region, at a time. 不能移动在 IaaS 虚拟机中备份 Azure 文件、Azure 文件同步或 SQL 的保管库。You can't move vaults that back up Azure Files, Azure File Sync, or SQL in IaaS virtual machines.

如果虚拟机不随保管库移动,则当前虚拟机恢复点会保留在保管库中,直至过期。If a virtual machine doesn't move with the vault, the current virtual machine recovery points stay in the vault until they expire. 不管虚拟机是否随保管库移动,均可根据保管库的备份历史记录还原虚拟机。Whether the virtual machine moved with the vault or not, you can restore the virtual machine from the backup history in the vault.

恢复服务保管库不支持跨订阅备份。Recovery Services vault doesn't support cross subscription backups. 如果跨订阅移动保管库和虚拟机备份数据,则必须将虚拟机移到同一订阅,并使用同一目标资源组来继续备份。If you move a vault with virtual machine backup data across subscriptions, you must move your virtual machines to the same subscription, and use the same target resource group to continue backups.

在保管库移动后,会保留为保管库定义的备份策略。Backup policies defined for the vault are kept after the vault moves. 在移动后,必须再次为保管库设置报告和监视功能。Reporting and monitoring must be set up again for the vault after the move.

若要将虚拟机移到新的订阅而不移动恢复服务保管库,请执行以下操作:To move a virtual machine to a new subscription without moving the Recovery Services vault:

  1. 暂时停止备份Temporarily stop backup
  2. 删除还原点Delete the restore point. 此操作仅删除即时恢复点,不删除保管库中的备份数据。This operation deletes only the instant recovery points, not the backed-up data in the vault.
  3. 将虚拟机移到新的订阅Move the virtual machines to the new subscription
  4. 在该订阅的新保管库中对其重新进行保护Reprotect it under a new vault in that subscription

移动不支持用于使用 Azure Site Recovery 设置灾难恢复的“存储”、“网络”或“计算”资源。Move isn't enabled for Storage, Network, or Compute resources used to set up disaster recovery with Azure Site Recovery. 例如,假设已设置将本地计算机复制到存储帐户 (Storage1),并且想要受保护的计算机在故障转移到 Azure 之后显示为连接到虚拟网络 (Network1) 的虚拟机 (VM1)。For example, suppose you have set up replication of your on-premises machines to a storage account (Storage1) and want the protected machine to come up after failover to Azure as a virtual machine (VM1) attached to a virtual network (Network1). 不能在同一订阅中的资源组之间或在订阅之间移动这些 Azure 资源 - Storage1、VM1 和 Network1。You can't move any of these Azure resources - Storage1, VM1, and Network1 - across resource groups within the same subscription or across subscriptions.

HDInsight 限制HDInsight limitations

可以将 HDInsight 群集移到新的订阅或资源组。You can move HDInsight clusters to a new subscription or resource group. 但是,无法在订阅之间移动链接到 HDInsight 群集的网络资源(例如虚拟网络、NIC 或负载均衡器)。However, you can't move across subscriptions the networking resources linked to the HDInsight cluster (such as the virtual network, NIC, or load balancer). 此外,无法将连接到群集的虚拟机的 NIC 移到新的资源组。In addition, you can't move to a new resource group a NIC that is attached to a virtual machine for the cluster.

将 HDInsight 群集移到新的订阅时,首先移动其他资源(如存储帐户)。When moving an HDInsight cluster to a new subscription, first move other resources (like the storage account). 然后移动 HDInsight 群集本身。Then, move the HDInsight cluster by itself.

移动资源前需查看的清单Checklist before moving resources

移动资源之前需执行的一些重要步骤。There are some important steps to do before moving a resource. 验证这些条件可以避免错误。By verifying these conditions, you can avoid errors.

  1. 源订阅与目标订阅必须在同一个 Azure Active Directory 租户中。The source and destination subscriptions must exist within the same Azure Active Directory tenant. 若要检查这两个订阅是否具有相同的租户 ID,请使用 Azure PowerShell 或 Azure CLI。To check that both subscriptions have the same tenant ID, use Azure PowerShell or Azure CLI.

    对于 Azure PowerShell,请使用:For Azure PowerShell, use:

    (Get-AzureRmSubscription -SubscriptionName <your-source-subscription>).TenantId
    (Get-AzureRmSubscription -SubscriptionName <your-destination-subscription>).TenantId
    

    对于 Azure CLI,请使用:For Azure CLI, use:

    az account show --subscription <your-source-subscription> --query tenantId
    az account show --subscription <your-destination-subscription> --query tenantId
    

    如果源订阅和目标订阅的租户 ID 不相同,可使用以下方法协调租户 ID:If the tenant IDs for the source and destination subscriptions aren't the same, use the following methods to reconcile the tenant IDs:

  2. 必须针对要移动的资源的资源提供程序注册目标订阅。The destination subscription must be registered for the resource provider of the resource being moved. 否则会出现错误“未针对资源类型注册订阅”。If not, you receive an error stating that the subscription is not registered for a resource type. 将资源移到新的订阅时,可能会看到此错误,但该订阅从未配合该资源类型使用。You might see this error when moving a resource to a new subscription, but that subscription has never been used with that resource type.

    对于 PowerShell,请使用以下命令来获取注册状态:For PowerShell, use the following commands to get the registration status:

    Set-AzureRmContext -Subscription <destination-subscription-name-or-id>
    Get-AzureRmResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState
    

    若要注册资源提供程序,请使用:To register a resource provider, use:

    Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch
    

    对于 Azure CLI,请使用以下命令来获取注册状态:For Azure CLI, use the following commands to get the registration status:

    az account set -s <destination-subscription-name-or-id>
    az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table
    

    若要注册资源提供程序,请使用:To register a resource provider, use:

    az provider register --namespace Microsoft.Batch
    
  3. 移动资源的帐户至少需要具备下列权限:The account moving the resources must have at least the following permissions:

    • 源资源组上的 Microsoft.Resources/subscriptions/resourceGroups/moveResources/action 权限。Microsoft.Resources/subscriptions/resourceGroups/moveResources/action on the source resource group.
    • 目标资源组上的 Microsoft.Resources/subscriptions/resourceGroups/write 权限。Microsoft.Resources/subscriptions/resourceGroups/write on the destination resource group.
  4. 在移动资源之前,请检查要将资源移动到的订阅的订阅配额。Before moving the resources, check the subscription quotas for the subscription you're moving the resources to. 如果移动资源意味着订阅将超出其限制,则需要检查是否可以请求增加配额。If moving the resources means the subscription will exceed its limits, you need to review whether you can request an increase in the quota. 有关限制的列表及如何请求增加配额的信息,请参阅 Azure 订阅和服务限制、配额与约束For a list of limits and how to request an increase, see Azure subscription and service limits, quotas, and constraints.

  5. 在可能的情况下,将大型移动分为单独的移动操作。When possible, break large moves into separate move operations. 在一次操作中有 800 多项资源时,资源管理器会立即返回错误。Resource Manager immediately returns an error when there are more than 800 resources in a single operation. 但是,移动 800 项以下的资源也可能因超时而失败。However, moving less than 800 resources may also fail by timing out.

  6. 该服务必须支持移动资源的功能。The service must enable the ability to move resources. 若要确定移动是否会成功,验证你的移动请求To determine whether the move will succeed, validate your move request. 请参阅本文中的以下部分,了解支持对资源进行移动的服务不支持对资源进行移动的服务See the sections below in this article of which services enable moving resources and which services don't enable moving resources.

验证移动Validate move

验证移动操作可以测试你的移动方案而无需实际移动资源。The validate move operation lets you test your move scenario without actually moving the resources. 使用此操作来确定移动是否会成功。Use this operation to determine if the move will succeed. 若要运行此操作,需要:To run this operation, you need the:

  • 源资源组的名称name of the source resource group
  • 目标资源组的资源 IDresource ID of the target resource group
  • 要移动的每个资源的资源 IDresource ID of each resource to move
  • 你的帐户的访问令牌the access token for your account

发送以下请求:Send the following request:

POST https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<source-group>/validateMoveResources?api-version=2018-02-01
Authorization: Bearer <access-token>
Content-type: application/json

包含请求正文:With a request body:

{
 "resources": ["<resource-id-1>", "<resource-id-2>"],
 "targetResourceGroup": "/subscriptions/<subscription-id>/resourceGroups/<target-group>"
}

如果请求格式正确,则操作将返回:If the request is formatted correctly, the operation returns:

Response Code: 202
cache-control: no-cache
pragma: no-cache
expires: -1
location: https://management.azure.com/subscriptions/<subscription-id>/operationresults/<operation-id>?api-version=2018-02-01
retry-after: 15
...

202 状态代码指示已接受验证请求,但尚未确定移动操作是否会成功。The 202 status code indicates the validation request was accepted, but it hasn't yet determined if the move operation will succeed. location 值包含用于检查长时间运行操作的状态的 URL。The location value contains a URL that you use to check the status of the long-running operation.

若要检查状态,请发送以下请求:To check the status, send the following request:

GET <location-url>
Authorization: Bearer <access-token>

操作仍在运行时,会继续收到 202 状态代码。While the operation is still running, you continue to receive the 202 status code. 请等待 retry-after 值中所示的秒数,然后重试。Wait the number of seconds indicated in the retry-after value before trying again. 如果移动操作验证成功,则会收到 204 状态代码。If the move operation validates successfully, you receive the 204 status code. 如果移动验证失败,则会收到错误消息,例如:If the move validation fails, you receive an error message, such as:

{"error":{"code":"ResourceMoveProviderValidationFailed","message":"<message>"...}}

移动资源Move resources

使用 Azure 门户By using Azure portal

若要移动资源,请选择包含这些资源的资源组,然后选择“移动”按钮。To move resources, select the resource group with those resources, and then select the Move button.

移动资源

选择是要将资源移到新资源组还是新订阅。Select whether you're moving the resources to a new resource group or a new subscription.

选择要移动的资源和目标资源组。Select the resources to move and the destination resource group. 确认需要更新这些资源的脚本,选择“确定”。Acknowledge that you need to update scripts for these resources and select OK. 如果在上一步中已选择“编辑订阅”图标,则还必须选择目标订阅。If you selected the edit subscription icon in the previous step, you must also select the destination subscription.

选择目标

在“通知”中,可以看到移动操作正在运行。In Notifications, you see that the move operation is running.

显示移动状态

操作完成后,你会获得结果通知。When it has completed, you're notified of the result.

显示移动结果

使用 Azure PowerShellBy using Azure PowerShell

要将现有资源移到另一个资源组或订阅,请使用 Move-AzureRmResource 命令。To move existing resources to another resource group or subscription, use the Move-AzureRmResource command. 下面的示例演示了如何将多个资源移动到新的资源组。The following example shows how to move several resources to a new resource group.

$webapp = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExampleSite
$plan = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExamplePlan
Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $webapp.ResourceId, $plan.ResourceId

若要移到新订阅,请包含 DestinationSubscriptionId 参数的值。To move to a new subscription, include a value for the DestinationSubscriptionId parameter.

使用 Azure CLIBy using Azure CLI

若要将现有资源移动到另一个资源组或订阅,请使用 az resource move 命令。To move existing resources to another resource group or subscription, use the az resource move command. 提供要移动的资源的资源 ID。Provide the resource IDs of the resources to move. 下面的示例演示了如何将多个资源移动到新的资源组。The following example shows how to move several resources to a new resource group. --ids 参数中,提供要移动的资源 ID 的空格分隔列表。In the --ids parameter, provide a space-separated list of the resource IDs to move.

webapp=$(az resource show -g OldRG -n ExampleSite --resource-type "Microsoft.Web/sites" --query id --output tsv)
plan=$(az resource show -g OldRG -n ExamplePlan --resource-type "Microsoft.Web/serverfarms" --query id --output tsv)
az resource move --destination-group newgroup --ids $webapp $plan

若要移到新订阅,请提供 --destination-subscription-id 参数。To move to a new subscription, provide the --destination-subscription-id parameter.

使用 REST APIBy using REST API

要将现有资源移到另一个资源组或订阅中,请运行:To move existing resources to another resource group or subscription, run:

POST https://management.azure.com/subscriptions/{source-subscription-id}/resourcegroups/{source-resource-group-name}/moveResources?api-version={api-version}

在请求正文中,指定目标资源组和要移动的资源。In the request body, you specify the target resource group and the resources to move. 有关移动 REST 操作的详细信息,请参阅移动资源For more information about the move REST operation, see Move resources.

后续步骤Next steps