将资源移到新资源组或订阅中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.

Note

本文介绍如何在现有 Azure 订阅之间移动资源。This article describes how to move resources between existing Azure subscriptions. 如果确实想要升级 Azure 订阅(例如从免费切换到标准的预先支付套餐),则需要转换订阅。If you actually want to upgrade your Azure subscription (such as switching from free to Standard Pay-in-Advance Offer), you need to convert your subscription.

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

何时致电 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 a list of which resource types support move, 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
  • 自动化 - Runbook 必须与自动化帐户存在于同一资源组中。Automation - Runbooks must exist in the same resource group as the Automation Account.
  • 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.
  • Azure Cosmos DB Azure Cosmos DB
  • Azure Database for MySQLAzure Database for MySQL
  • Azure Database for PostgreSQL Azure Database for PostgreSQL
  • Azure Stack - 注册Azure Stack - registrations
  • Batch Batch
  • CDNCDN
  • 云服务 - 请参阅 经典部署限制Cloud Services - see Classic deployment limitations
  • 认知服务Cognitive Services
  • 容器注册表Container Registry
  • 内容审查器 Content Moderator
  • 事件中心 Event Hubs
  • HDInsight 群集 - 请参阅 HDInsight 限制 HDInsight clusters - see HDInsight limitations
  • 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.
  • 逻辑应用 Logic Apps
  • 媒体服务Media Services
  • 监视器 - 确保移动到新订阅时,不会超出订阅配额Monitor - make sure moving to new subscription doesn't exceed subscription quotas
  • 通知中心 Notification Hubs
  • 门户仪表板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.
  • 计划程序 Scheduler
  • 服务总线Service Bus
  • Service Fabric Service Fabric
  • 存储 - 不同区域的存储帐户无法通过同一操作进行移动。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.
  • 流量管理器Traffic Manager
  • 虚拟机 - 请参阅虚拟机限制Virtual Machines - 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 Hybrid Health Service
  • 应用程序网关 Application Gateway
  • Azure Kubernetes 服务 (AKS) Azure Kubernetes Service (AKS)
  • 证书 - 应用服务证书可以移动,但上传的证书存在限制Certificates - App Service Certificates can be moved, but uploaded certificates have limitations.
  • 经典应用程序 Classic Applications
  • Express Route Express Route
  • 安全性Security
  • Site Recovery Site Recovery
  • 虚拟网络(经典)- 请参阅经典部署限制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

可以移动包含托管磁盘、托管映像和托管快照的虚拟机,以及移动所含虚拟机使用托管磁盘的可用性集。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_chinanorth2_1Find a resource group with the following naming pattern: AzureBackupRG_<location of your VM>_1 for example, AzureBackupRG_chinanorth2_1
  • 如果在 Azure 门户中,则查看“显示隐藏的类型”If in Azure portal, then check "Show hidden types"
  • 如果在 PowerShell 中,则使用 Get-AzResource -ResourceGroupName AzureBackupRG_<location of your VM>_1 cmdletIf in PowerShell, use the Get-AzResource -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.

虚拟网络限制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 virtual machine with a network interface card, you must move all dependent resources. 必须移动与该网络接口卡对应的虚拟网络、该虚拟网络的所有其他网络接口卡,以及 VPN 网关。You must move the virtual network for the network interface card, all other network interface cards for the virtual network, and the VPN gateways.

若要移动对等的虚拟网络,必须首先禁用虚拟网络对等互连。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.

如果忘记了原始资源组,可以通过诊断来查找。If you don't remember the original resource group, you can find it through diagnostics. 对于 Web 应用,请选择“诊断和解决问题” 。For your web app, select Diagnose and solve problems. 然后,选择“配置和管理”。 Then, select Configuration and Management.

选择诊断

选择“迁移选项” 。Select Migration Options.

选择迁移选项

选择通过建议的步骤来移动 Web 应用的选项。Select the option for recommended steps to move the web app.

选择建议的步骤

可以看到在移动资源之前需采取的建议操作。You see the recommended actions to take before moving the resources. 该信息包含 Web 应用的原始资源组。The information includes the original resource group for the web app.

建议

应用服务证书限制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 PowerShell、Azure CLI 或 REST 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.chinacloudapi.cn/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.chinacloudapi.cn/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.chinacloudapi.cn/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

恢复服务保管库不支持跨订阅备份。Recovery Services vault doesn't support cross subscription backups.

若要将虚拟机移到新的订阅而不移动恢复服务保管库,请执行以下操作: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. 源订阅和目标订阅必须处于活动状态。The source and destination subscriptions must be active. 如果在启用已禁用的帐户时遇到问题,请创建 Azure 支持请求If you have trouble enabling an account that has been disabled, create an Azure support request. 选择“订阅管理” 作为问题类型。Select Subscription Management for the issue type.

  2. 源订阅与目标订阅必须在同一个 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-AzSubscription -SubscriptionName <your-source-subscription>).TenantId
    (Get-AzSubscription -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
    
  3. 必须针对要移动的资源的资源提供程序注册目标订阅。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-AzContext -Subscription <destination-subscription-name-or-id>
    Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState
    

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

    Register-AzResourceProvider -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
    
  4. 移动资源的帐户至少需要具备下列权限: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.
  5. 在移动资源之前,请检查要将资源移动到的订阅的订阅配额。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.

  6. 在可能的情况下,将大型移动分为单独的移动操作。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.

  7. 服务必须支持移动资源的功能。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.chinacloudapi.cn/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.chinacloudapi.cn/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-AzResource 命令。To move existing resources to another resource group or subscription, use the Move-AzResource command. 下面的示例演示了如何将多个资源移动到新的资源组。The following example shows how to move several resources to a new resource group.

$webapp = Get-AzResource -ResourceGroupName OldRG -ResourceName ExampleSite
$plan = Get-AzResource -ResourceGroupName OldRG -ResourceName ExamplePlan
Move-AzResource -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.chinacloudapi.cn/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