从不同区域的快照创建托管磁盘 (Azure)

Creating a managed disk from snapshot in different region (Azure)

我似乎在从快照创建托管磁盘时遇到问题。

看来我只能在美国西部的一个区域创建磁盘。

这是我使用的 PowerShell 脚本:

Get-AzureRmSubscription –SubscriptionName 'MySubscription' | Select-AzureRmSubscription

$resourceGroupName = 'MyResourceGroup';
$diskName = 'MyNewDisk';
$location = 'West US';

$snapshotName = 'MySnapshot';
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName;

$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -SourceResourceId $snapshot.Id -CreateOption Copy;
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName;

如果我将变量 $region 的值更改为 'East US' 或任何其他区域,我会在 PowerShell 中遇到错误(找不到资源)。

快照本身在美国西部,但我想在美国东部创建磁盘。 我做错了什么?

The snapshot itself is in West US but I want to create a disk in East US. What am I doing wrong?

我们无法从快照创建托管磁盘到另一个位置。

如果你想创建一个从快照到另一个位置的托管磁盘,我们应该export/Copy使用PowerShell将托管快照作为VHD存储到不同区域的存储帐户。

这里是示例脚本:

#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"

#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"

#Provide the snapshot name 
$snapshotName = "yourSnapshotName"

#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"

#Provide storage account name where you want to copy the snapshot. 
$storageAccountName = "yourstorageaccountName"

#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"

#Provide the key of the storage account where you want to copy snapshot. 
$storageAccountKey = 'yourStorageAccountKey'

#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"


# Set the context to the subscription Id where Snapshot is created
Select-AzureRmSubscription -SubscriptionId $SubscriptionId

#Generate the SAS for the snapshot 
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read 

#Create the context for the storage account which will be used to copy snapshot to the storage account 
$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  

#Copy the snapshot to the storage account 
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName

#Monitor status
Get-AzureStorageBlobCopyState -Context $destinationContext -Blob $destinationVHDFileName -Container $storageContainerName

更多相关信息,请参考这篇link

您可以简单地使用 azure site recovery 并添加 azure2azure 服务并将您的 vm 复制到其他跨区域,这不会重新启动 v,它会在需要复制的 vm 中安装 azure site recovery 软件,并且这将开始复制,请注意,为了更快地复制虚拟机,请使用高级托管磁盘。

注意:如果您正在将诸如美国东部 2 之类的内容复制到北欧,则将不受支持,有一整份文档统计了支持复制的区域。如果您希望减少停机时间以跨区域复制托管磁盘,这是一个好方法。

按照此方法就不需要拍快照了。

如果您有任何其他疑问,请告诉我。