问题描述
已经遵循了这一文章()我想创建虚拟机的使用PowerShell的(PS)从Azure的门户网站的快照。这是我创建了拍摄快照的PS脚本
Having followed this article(http://www.coreazure.com/snapshot-vms-in-azure-2/) I am trying to create a snapshot of VM using powershell(PS) from Azure portal. This is the PS script which I have created to take a snapshot
workflow snapshot1
{
$subName = 'XYZ'
$cred = Get-AutomationPSCredential -Name "[email protected]"
Add-AzureAccount -Credential $cred
Set-AzureSubscription -SubscriptionName $subName -CurrentStorageAccount 'storagename'
$serviceName = "a1smallvm"
$vm = Get-AzureVM –ServiceName $serviceName –Name "a1smallvm"
$storageContainer = "backups"
InlineScript {
# Create a storage for putting the backups of OSDisk & DataDisks
New-AzureStorageContainer -Name $Using:storageContainer -Permission off
# Stop VM if running
$Using:vm | Stop-AzureVM -StayProvisioned
$vm = Get-AzureVM –ServiceName $Using:serviceName –Name "a1smallvm"
$vmOSDisk = $vm | Get-AzureOSDisk
$vmDataDisks = $vm | Get-AzureDataDisk
Write-output "OSDisk: $vmOSDisk"
$storageAccountName = $vmOSDisk.MediaLink.Host.Split(‘.’)[0]
Write-output "Data Disk: $vmDataDisks"
Write-output "StorageAccountName: $storageAccountName"
$vmOSBlobName = $vmOSDisk.MediaLink.Segments[-1]
$vmOSContainerName = $vmOSDisk.MediaLink.Segments[-1].Split(‘/’)[0]
Write-output "vmOSBlobName: $vmOSBlobName"
Write-output "vmOSContainerName: $vmOSContainerName"
# Backup the osblob and oscontainer
Start-AzureStorageBlobCopy -SrcContainer $vmOSContainerName -SrcBlob $vmOSBlobName -DestContainer $Using:storageContainer
Get-AzureStorageBlobCopyState -Container $Using:storageContainer -Blob $vmOSBlobName -WaitForComplete
# Backup the dataBlob and dataContainer
ForEach ($vmDataDisk in $vmDataDisks) {
$vmDataBlobName = $vmDataDisk.MediaLink.Segments[-1]
$vmDataContainerName = $vmDataDisk.MediaLink.Segments[-2].Split(‘/’)[0]
Start-AzureStorageBlobCopy -SrcContainer $vmDataContainerName -SrcBlob $vmDataBlobName -DestContainer backups -Force
Get-AzureStorageBlobCopyState -Container backups -Blob $vmDataBlobName -WaitForComplete
}
}
}
此cmdlet
The cmdlet
启动AzureStorageBlobCopy -SrcContainer $ vmOSContainerName -SrcBlob $ vmOSBlobName -DestContainer $使用:storageContainer
抛出一个错误:
Error: Start-AzureStorageBlobCopy : Container name 'a1smallvm-a1smallvm-2015-08-11.vhd' is invalid. Valid names start and end with a lower case letter or a number and has in between a lower case letter, number or dash with no consecutive dashes and is 3 through 63 characters long.
该容器名称'a1smallvm-a1smallvm-2015-08-11.vhd这我得到遵循正确的命名格式,但仍为什么它给人一个错误说的名字是无效的。
虚拟机从门户创建的,它是一个A1型虚拟机,操作系统是CentOS的OpenLogic 6.5。
任何线索怎么了?
The container name 'a1smallvm-a1smallvm-2015-08-11.vhd' which I am getting follows the correct naming format but still why it's giving an error saying the name is invalid.The VM was created from the portal, it's an A1 type of VM, OS is CentOS "OpenLogic 6.5".Any clue what's wrong?
以下是从输出写输出的
OSDisk: Microsoft.WindowsAzure.Commands.ServiceManagement.Model.OSVirtualHardDisk
Data Disk:
StorageAccountName: portalvhds14510n2y65vnh
vmOSBlobName: a1smallvm-a1smallvm-2015-08-11.vhd
vmOSContainerName: a1smallvm-a1smallvm-2015-08-11.vhd
正确的脚本:
存储帐户名称必须相同,否则我们将不得不增加目标存储帐户的上下文。
Correct script:The storage account name has to be same or we will have to add the context of destination storage account.
$ storageAccountName = $ vmOSDisk.MediaLink.Host.Split('。')[0]
设置AzureSubscription -SubscriptionName $ SUBNAME -CurrentStorageAccount'$ storagenameAccountName
和索引段应 -2 不是 1
$ vmOSContainerName = $ vmOSDisk.MediaLink.Segments [-2] .Split('/')[0]
推荐答案
我不PowerShell的专家(我相信有这样做的更好的方法),但你可以做到以下几点:
I'm no PowerShell expert (and I am sure there are better ways of doing it) but you could do the following:
$vmOSContainerName = $vmOSDisk.MediaLink.AbsolutePath.Split('/')[1]
这将输出的VHD
这是您的blob容器的名字。
This will output vhds
which is the name of your blob container.
这篇关于在创建虚拟机天青快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!