如何通过Azure Portal或AZ CLI将磁盘快照复制到Azure容器
将VM磁盘快照复制到Azure容器的两种方法
一、通过Azure Portal手动操作
- 登录Azure门户,搜索并进入目标磁盘快照的详情页面。
- 在左侧菜单选择“生成SAS”,设置合理的过期时长(如3600秒),权限勾选“读取”,点击“生成SAS URI”后复制该链接。
- 导航到目标存储账户,进入要存放VHD的容器(无容器则先点击“+容器”创建)。
- 在容器页面点击“上传”,切换到“从URL上传”选项卡。
- 粘贴刚才复制的SAS URI到“源URL”输入框,填写目标VHD文件名,点击“上传”等待任务完成。
二、修复AZ CLI命令执行报错
你遇到的unrecognized arguments错误,是因为SAS URI包含特殊字符(如&),PowerShell解析时会将其拆分为多个参数。解决方法如下:
- 修正变量定义:所有字符串类型的变量需要用双引号包裹,避免解析错误:
$subscriptionId="<subscriptionId>" $resourceGroupName="myResourceGroupName" $snapshotName="mySnapshotName" $sasExpiryDuration=3600 $storageAccountName="mystorageaccountname" $storageContainerName="mystoragecontainername" $storageAccountKey="mystorageaccountkey" $destinationVHDFileName="myvhdfilename"
- 最后一行复制命令中,给
$sas变量加上双引号,确保URI作为单个参数传递:
az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri "$sas"
完整修正后的命令:
$subscriptionId="<subscriptionId>" $resourceGroupName="myResourceGroupName" $snapshotName="mySnapshotName" $sasExpiryDuration=3600 $storageAccountName="mystorageaccountname" $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="myvhdfilename" az account set --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"
内容的提问来源于stack exchange,提问作者Sandy
相关产品推荐
相关产品推荐

