【问题标题】:How to move an azure VM image to a different location如何将 Azure VM 映像移动到其他位置
【发布时间】:2019-03-15 04:25:09
【问题描述】:

我在美国东部有一个带有托管磁盘的 Azure VM 映像,我想将其移动/复制到西欧。

有什么简单的方法吗?

我看到有一个名为 az-image-copy 的 azure cli 扩展,但它对我不起作用,因为它会输出一个错误,提示它找不到操作系统磁盘(即使资源 ID 正确且我可以在 azure 门户中看到它)

错误:找不到资源服务器Linux_OsDisk_1_c208679747734937b10a1525aa84a7d7

那么还有其他方法吗?

【问题讨论】:

    标签: azure powershell azure-storage azure-virtual-machine azure-cli


    【解决方案1】:

    如果资源属于同一订阅,则您可以将资源从资源组 01(美国东部)移动到资源组 02(西欧)。 为了您的帮助,您可以查看以下文档:

    Move Managed Disks and VMs

    Move resources to new resource group or subscription

    Copy managed disks in the same subscription or different subscription with PowerShell

    Migrating Azure IaaS solutions using MigAz

    最后一个链接是关于 MigAz 工具的,它允许在 Azure 上迁移资源。

    【讨论】:

      【解决方案2】:

      您可以使用 azure powershell 复制托管映像,创建快照并将其复制到另一个区域,然后创建映像。这是similar issue

      创建快照:

      <# -- Create a snapshot of the OS (and optionally data disks) from the generalized VM -- #>
      $vm = Get-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
      $disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName $vm.StorageProfile.OsDisk.Name
      $snapshot = New-AzureRmSnapshotConfig -SourceUri $disk.Id -CreateOption Copy -Location $region
      
      $snapshotName = $imageName + "-" + $region + "-snap"
      
      New-AzureRmSnapshot -ResourceGroupName $resourceGroupName -Snapshot $snapshot -SnapshotName $snapshotName
      

      复制快照:

      # Create the name of the snapshot, using the current region in the name.
      $snapshotName = $imageName + "-" + $region + "-snap"
      
      # Get the source snapshot
      $snap = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
      
      # Create a Shared Access Signature (SAS) for the source snapshot
      $snapSasUrl = Grant-AzureRmSnapshotAccess -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -DurationInSecond 3600 -Access Read
      
      # Set up the target storage account in the other region
      $targetStorageContext = (Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName).Context
      New-AzureStorageContainer -Name $imageContainerName -Context $targetStorageContext -Permission Container
      
      # Use the SAS URL to copy the blob to the target storage account (and thus region)
      Start-AzureStorageBlobCopy -AbsoluteUri $snapSasUrl.AccessSAS -DestContainer $imageContainerName -DestContext $targetStorageContext -DestBlob $imageBlobName
      Get-AzureStorageBlobCopyState -Container $imageContainerName -Blob $imageBlobName -Context $targetStorageContext -WaitForComplete
      
      # Get the full URI to the blob
      $osDiskVhdUri = ($targetStorageContext.BlobEndPoint + $imageContainerName + "/" + $imageBlobName)
      
      # Build up the snapshot configuration, using the target storage account's resource ID
      $snapshotConfig = New-AzureRmSnapshotConfig -AccountType StandardLRS `
                                                  -OsType Windows `
                                                  -Location $targetRegionName `
                                                  -CreateOption Import `
                                                  -SourceUri $osDiskVhdUri `
                                                  -StorageAccountId "/subscriptions/${sourceSubscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Storage/storageAccounts/${storageAccountName}"
      
      # Create the new snapshot in the target region
      $snapshotName = $imageName + "-" + $targetRegionName + "-snap"
      $snap2 = New-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -Snapshot $snapshotConfig
      

      创建图像:

      <# -- In the second subscription, create a new Image from the copied snapshot --#>
      Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId
      
      $snap = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
      
      $imageConfig = New-AzureRmImageConfig -Location $destinationRegion
      
      Set-AzureRmImageOsDisk -Image $imageConfig `
                              -OsType Windows `
                              -OsState Generalized `
                              -SnapshotId $snap.Id
      
      New-AzureRmImage -ResourceGroupName $resourceGroupName `
                       -ImageName $imageName `
                       -Image $imageConfig
      

      更多详情请参考link

      【讨论】:

        猜你喜欢
        • 2019-03-14
        • 2018-08-13
        • 1970-01-01
        • 1970-01-01
        • 2022-07-01
        • 2012-06-25
        • 2018-09-15
        • 2021-08-19
        • 1970-01-01
        相关资源
        最近更新 更多