azure - Save-AzureRmVMImage 强制创建无效的 blob 容器名称

标签 azure azure-storage azure-powershell azure-resource-manager

我正在捕获 ARM VM 镜像,以便在从镜像创建操作中使用它。 然而,Save-AzureRmVMImage 命令强制(或只是默认?)创建这样的容器和 blob 名称,这对于其他命令似乎无效。

容器名称中的“/Microsoft.Compute/”部分和 blob 名称中的“osDisk.xxxx”部分由 Save-AzureRmVMImage 命令隐式放置。

澄清一下: 我用了Save-AzureRmVMImage -DestinationContainerName 'vhds' -VHDNamePrefix 'template'...但该命令创建容器system/Microsoft.Compute/Images/vhds +“发明”包含osdisk的blobname。 (点) 部分。两者都不是来 self ……并且无法阻止-

首先,这个名称似乎在 New-AzureRmVM 操作中不可用。 (请参阅我的详细描述 Creating new ARM VM from captured image: Blob name in URL must end with '.vhd' extension error

作为上述错误的解决方法,我发现我会将图像复制到不包含 . (点)。然而事实证明,我经过充分测试且工作正常的副本脚本也会引发该 blob 名称的错误...

复制源代码(同样,它对于其他 blob 具有完整的功能)

(注意:这个问题是关于 Save-AzureRmVMImage 问题,或者如何在后续操作中解决它奇怪且无效的名称。所以问题不是关于这个复制脚本。这里的脚本只是演示诊断体验。

Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"


$sourceRgName = "rg-wp"
$sourceName = "mystorage"
$sourceContainerName = "system/Microsoft.Compute/Images/vhds" #the dots seems to be invalid
$sourceBlobName = "template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd" #the dots seems to be invalid

$destinationRgName = "rg-wp"
$destinationName = "mystorage"
$destinationContainerName = "vhds"
$destinationBlobName = "template.vhd"

$sourceKeys = Get-AzureRmStorageAccountKey -Name $sourceName -ResourceGroupName $sourceRgName
$destinationKeys = Get-AzureRmStorageAccountKey -Name $destinationName -ResourceGroupName $destinationRgName

$contextSource = New-AzureStorageContext -StorageAccountName $sourceName -StorageAccountKey $sourceKeys.Key1
$contextDestination = New-AzureStorageContext -StorageAccountName $destinationName -StorageAccountKey $destinationKeys.Key1


Start-AzureStorageBlobCopy -Context $contextSource -SrcContainer $sourceContainerName -SrcBlob $sourceBlobName -DestContext $contextDestination -DestContainer $destinationContainerName -DestBlob $destinationBlobName

# Wait for copy to complete
Get-AzureStorageBlobCopyState -Context $contextDestination -Container $destinationContainerName -Blob $destinationBlobName -WaitForComplete

完整错误消息:

[ERROR] Start-AzureStorageBlobCopy : Container name 'system/Microsoft.Compute/Images/vh
[ERROR] ds' is invalid. Valid names start and end with a lower case letter or a number 
[ERROR] and has in between a lower case letter, number or dash with no consecutive dash
[ERROR] es and is 3 through 63 characters long.
[ERROR] At D:\work\.vsonline\Azure\PowerShell\PowerShell\copy blob.ps1:40 char:1
[ERROR] + Start-AzureStorageBlobCopy -Context $contextSource -SrcContainer $sourceConta
[ERROR] ine ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] ~~~
[ERROR]     + CategoryInfo          : NotSpecified: (:) [Start-AzureStorageBlobCopy],  
[ERROR]    ArgumentException
[ERROR]     + FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure. 
[ERROR]    Commands.Storage.Blob.Cmdlet.StartAzureStorageBlobCopy
[ERROR]  

最佳答案

您的代码失败的原因是您在脚本中指定的容器名称无效。请参阅此链接以获取有效的容器名称:https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx .

根据您在上面评论中提供的信息,请尝试以下操作:

$sourceContainerName = "system"
$sourceBlobName = "Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd

关于azure - Save-AzureRmVMImage 强制创建无效的 blob 容器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35864662/

相关文章:

azure - 如何避免 Windows Azure 队列中的竞争条件

azure - Get-AzureRmVM 需要名称参数吗?

python - Azure Web 应用服务上的 Anaconda 安装

azure - 如何在Azure Scheduler中安排Azure机器学习的批量执行服务

c# - 在 Azure 辅助角色中使用 kernel32 CreateThread/TerminateThread

Azure 表存储重试策略问题

azure - 如何查找Azure存储帐户内不同访问层中的blob大小?

git - azure 网站,不断收到错误 : Could not connect to the Local Git repository

azure - 术语 'Register-AzResourceProvider' 未被识别为 cmdlet 的名称

powershell - Azure 发布管道 Powershell 任务失败