将 VHD 从 azure 磁盘复制到 azure 存储帐户
Posted
技术标签:
【中文标题】将 VHD 从 azure 磁盘复制到 azure 存储帐户【英文标题】:Copy VHD from azure disk to azure storage account 【发布时间】:2020-07-31 07:59:41 【问题描述】:我有一个 Windows 10 系统的 Azure 磁盘。我希望此磁盘必须转换为 VHD,并且应该在 azure 存储帐户中可用。
简单地说,我希望我的 Azure VM 数据磁盘存在于 azure 存储 BLOB 中,而无需将 VHD 下载到我的基础计算机上。可能吗。如果是,请指导我。
谁能帮帮我。
谢谢
【问题讨论】:
【参考方案1】:是的,这是可能的。您可以将托管磁盘复制到 VHD 文件中并将其存储在存储中。下面是通过 PowerShell 的示例代码:
#Provide the subscription Id of the subscription where managed disk is created
$subscriptionId = "yourSubscriptionId"
#Provide the name of your resource group where managed is created
$resourceGroupName ="yourResourceGroupName"
#Provide the managed disk name
$diskName = "yourDiskName"
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"
#Provide storage account name where you want to copy the underlying VHD of the managed disk.
$storageAccountName = "yourstorageaccountName"
#Name of the storage container where the downloaded VHD will be stored
$storageContainerName = "yourstoragecontainername"
#Provide the key of the storage account where you want to copy the VHD of the managed disk.
$storageAccountKey = 'yourStorageAccountKey'
#Provide the name of the destination VHD file to which the VHD of the managed disk will be copied.
$destinationVHDFileName = "yourvhdfilename"
#Set the value to 1 to use AzCopy tool to download the data. This is the recommended option for faster copy.
#Download AzCopy v10 from the link here: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
#Ensure that AzCopy is downloaded in the same folder as this file
#If you set the value to 0 then Start-AzStorageBlobCopy will be used. Azure storage will asynchronously copy the data.
$useAzCopy = 1
# Set the context to the subscription Id where managed disk is created
Select-AzSubscription -SubscriptionId $SubscriptionId
#Generate the SAS for the managed disk
$sas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read
#Create the context of the storage account where the underlying VHD of the managed disk will be copied
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
#Copy the VHD of the managed disk to the storage account
if($useAzCopy -eq 1)
$containerSASURI = New-AzStorageContainerSASToken -Context $destinationContext -ExpiryTime(get-date).AddSeconds($sasExpiryDuration) -FullUri -Name $storageContainerName -Permission rw
$containername,$sastokenkey = $containerSASURI -split "\?"
$containerSASURI = "$containername/$destinationVHDFileName`?$sastokenkey"
azcopy copy $sas.AccessSAS $containerSASURI
else
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
但在我的测试中,当你使用azcopy
命令时,VHD 文件有问题。命令Start-AzStorageBlobCopy
运行良好。所以我为你推荐命令Start-AzStorageBlobCopy
。更多详情请见Export/Copy the VHD of a managed disk to a storage account in different region with PowerShell。
【讨论】:
非常感谢。我会乖乖地试试这个。希望它有效。再次提前感谢。如果我被卡住了,我会回来的。 @AnilSharma 支票呢?它解决了你的问题吗?如果是,请接受它作为答案。以上是关于将 VHD 从 azure 磁盘复制到 azure 存储帐户的主要内容,如果未能解决你的问题,请参考以下文章
Windows Azure - 孤立磁盘。 VHD 和 VM 已被删除