使用Azure CLI跨Azure存储账户复制Blob快照失败,求解决方案
解决Azure CLI复制Blob快照失败的问题
1. 排查源SAS令牌的权限与格式
- 源SAS必须包含
r(读取)权限,且有效期要覆盖整个复制过程,避免中途过期。 - 源URI必须是Blob快照的完整URL + SAS令牌,不能只传入SAS字符串。示例格式:
https://source-storage-account.blob.core.windows.net/source-container/blob-name.vhd?snapshot=2024-05-20T00:00:00Z&sv=2023-11-03&ss=b&srt=o&sp=r&se=2024-05-21T00:00:00Z&st=2024-05-20T00:00:00Z&spr=https&sig=xxx - 生成SAS时,若用Azure门户需勾选「包含快照」;若用CLI生成,需指定
--snapshot参数关联目标快照。
2. 修正复制命令参数
确保所有变量正确替换,目标容器已存在,账户名/密钥对应目标存储账户:
az storage blob copy start \ --destination-blob "target-snapshot.vhd" \ --destination-container "target-container" \ --account-name "target-storage-account" \ --account-key "target-account-key" \ --source-uri "https://source-storage-account.blob.core.windows.net/source-container/blob-name.vhd?snapshot=2024-05-20T00:00:00Z&sv=2023-11-03&ss=b&srt=o&sp=r&se=2024-05-21T00:00:00Z&st=2024-05-20T00:00:00Z&spr=https&sig=xxx"
3. 获取详细失败原因
通过az storage blob show命令查看具体错误描述,定位问题:
az storage blob show \ --account-key "target-account-key" \ --account-name "target-storage-account" \ --container-name "target-container" \ --name "target-snapshot.vhd" \ --query "{copyStatus:properties.copy.status, errorMsg:properties.copy.statusDescription}" \ --output json
从errorMsg可直接得到失败原因,比如权限不足、源快照不存在等。
4. 备选方案:用存储账户密钥授权源
若你有权限访问源存储账户的密钥,可跳过SAS直接用账户密钥授权,简化操作:
az storage blob copy start \ --destination-blob "target-snapshot.vhd" \ --destination-container "target-container" \ --account-name "target-storage-account" \ --account-key "target-account-key" \ --source-account-name "source-storage-account" \ --source-account-key "source-account-key" \ --source-container "source-container" \ --source-blob "source-blob.vhd" \ --source-snapshot "2024-05-20T00:00:00Z"
5. 验证复制结果
当copyStatus返回success时,复制完成,可验证Blob大小与源快照一致:
az storage blob show \ --account-key "target-account-key" \ --account-name "target-storage-account" \ --container-name "target-container" \ --name "target-snapshot.vhd" \ --query "{name:name, size:properties.contentLength, copyStatus:properties.copy.status}" \ --output json
内容的提问来源于stack exchange,提问作者Sandy
相关产品推荐
相关产品推荐

