gpt4 book ai didi

azure - 将 VHD 从 Azure 磁盘复制到 Azure 存储帐户

转载 作者:行者123 更新时间:2023-12-02 06:05:47 26 4
gpt4 key购买 nike

我有一个Windows 10系统的Azure磁盘。我希望此磁盘必须转换为 VHD,并且应该在 Azure 存储帐户中可用。

简单地说,我希望我的 Azure VM 数据磁盘存在于 Azure 存储 BLOB 中,而无需将 VHD 下载到我的基础计算机上。是否可以。如果是的话,请指导我。

任何人都可以帮助我吗?

谢谢

最佳答案

是的,这是可能的。您可以将托管磁盘复制到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://learn.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://learn.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 .

关于azure - 将 VHD 从 Azure 磁盘复制到 Azure 存储帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61278034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com