托管磁盤為用戶在后臺處理存儲帳戶的創建/管理,確保用戶不需擔心存儲帳戶的可伸縮性限制。 用戶只需指定磁盤大小和性能層(標準/高級),然后 Azure 就會為用戶創建和管理磁盤。 即使在添加磁盤或者對 VM 進行上下伸縮的時候,用戶也不需擔心所使用的存儲。
如同非托管磁盤(VHD 文件)一般,Azure 提供了以下導出托管磁盤的方法。
Note
只有在虛機處于解除分配狀態,或磁盤未被附加到虛機上時,才可以導出托管磁盤。
導出托管磁盤
當虛機處于解除分配狀態,或磁盤未附加到虛機上時,可以使用 Azure 門戶、PowerShell 或 Azure CLI 導出托管磁盤。如需在虛機開啟時導出托管磁盤,需要先從磁盤創建托管快照,再對快照執行導出操作。托管快照是托管磁盤的只讀副本。
Azure 門戶
在 Azure 門戶中,在磁盤頁面點擊導出按鈕,點擊生成 URL按鈕,即可生成安全的 URL 并直接用瀏覽器下載。
或點擊創建快照按鈕,從磁盤創建快照后,對快照執行導出操作。
PowerShell
以下 PowerShell 腳本先對指定的托管磁盤創建快照,再將快照導出成 VHD 文件,保存在指定的存儲賬戶中。需要使用 2.6.0 以上版本的 AzureRM.Compute 模塊。
PowerShell復制
#提供訂閱 ID$SubscriptionId="yourSubscriptionId"#提供資源組名$ResourceGroupName="yourResourceGroupName"#提供想要復制的托管磁盤名$DiskName="yourDiskName"#提供想要創建的快照名$SnapshotName="yourSnapshotName"#快照 SAS 的過期時間,3600 秒 = 1 小時$sasExpiryDuration="3600"#提供目標存儲賬戶名$StorageAccountName="yourstorageaccountName"#提供目標存儲賬戶容器名$StorageContainerName="yourstoragecontainername"#提供目標存儲賬戶密鑰$StorageAccountKey='yourStorageAccountKey'#提供目標 VHD 文件名$DestinationVHDFileName="yourVHDfilename"#提供地區信息,chinaeast 或 chinanorth$Location="resourcelocation"#獲取想要復制的托管磁盤$Disk=Get-AzureRmDisk-ResourceGroupName$ResourceGroupName-DiskName$DiskName#創建快照配置$Snapshot=New-AzureRmSnapshotConfig-SourceUri$Disk.Id-CreateOptionCopy-Location$Location#拍攝快照New-AzureRmSnapshot-Snapshot$Snapshot-SnapshotName$SnapshotName-ResourceGroupName$ResourceGroupName#創建快照的 SAS Uri$sas=Grant-AzureRmSnapshotAccess-ResourceGroupName$ResourceGroupName-SnapshotName$SnapshotName-DurationInSecond$sasExpiryDuration-AccessRead#創建目標存儲賬戶上下文$destinationContext=New-AzureStorageContext–StorageAccountName$StorageAccountName-StorageAccountKey$StorageAccountKey#將快照的基礎 VHD 復制到存儲賬戶Start-AzureStorageBlobCopy-AbsoluteUri$sas.AccessSAS-DestContainer$StorageContainerName-DestContext$destinationContext-DestBlob$DestinationVHDFileName
Azure CLI
以下 Azure CLI 腳本僅對指定快照生成 SAS Uri,并將快照導出成 VHD 文件至指定存儲賬戶。
此腳本可在 bash 會話中運行,關于更多信息,請參考在 Windows 上使用 Azure CLI。
bash復制
#Provide the subscription Id where snapshot is created$subscriptionId=mySubscriptionId#Provide the name of your resource group where snapshot is created$resourceGroupName=myResourceGroupName#Provide the snapshot name$snapshotName=mySnapshotName#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=mystorageaccountname#Name of the storage container where the downloaded snapshot will be stored$storageContainerName=mystoragecontainername#Provide the key of the storage account where you want to copy snapshot.$storageAccountKey=mystorageaccountkey#Provide the name of the VHD file to which snapshot will be copied.$destinationVHDFileName=myvhdfilenameaz accountset--subscription$subscriptionId$sas=$(az snapshot grant-access --resource-group$resourceGroupName--name$snapshotName--duration-in-seconds$sasExpiryDuration--query [accessSas] -o tsv)az storage blob copy start --destination-blob$destinationVHDFileName--destination-container$storageContainerName--account-name$storageAccountName--account-key$storageAccountKey--source-uri$sas
立即訪問http://market.azure.cn