自动化Runbook中的Start-AzureStorageBlobCopy错误

时间:2014-11-26 16:15:49

标签: powershell azure automation virtual-machine azure-storage-blobs

我跟随this guide在Azure自动化中自动备份Linux VM。在初始运行测试中一切顺利,但第二次和所有后续测试都返回以下错误:

11/26/2014 11:03:45 AM, Error: Start-AzureStorageBlobCopy : One or more errors occurred.
At LinuxVMBackup:40 char:40
+ 
    + CategoryInfo          : CloseError: (:) [Start-AzureStorageBlobCopy], AggregateException
    + FullyQualifiedErrorId : 
AggregateException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.StartAzureStorageBlobCopy

这是Runbook:

workflow LinuxVMBackup
{
    param (
        [Parameter(Mandatory=$true)]
        [PSCredential]
        $Cred,

        [Parameter(Mandatory=$true)]
        [string]
        $subName,

        [Parameter(Mandatory=$true)]
        [string]
        $serviceName,

        [Parameter(Mandatory=$true)]
        [string]
        $vmName
    )

    # Login and get VM
    $null = Add-AzureAccount -Credential $Cred
    $null = Select-AzureSubscription -SubscriptionName $subName
    $vm = Get-AzureVM -ServiceName $serviceName -Name $vmName

    # Stop VM 
    $vm | Stop-AzureVM -StayProvisioned

    # Get OS and Data Disks
    $vmOSDisk = Get-AzureOSDisk -VM (Get-AzureVM -ServiceName $serviceName -Name $vmName)
    $vmDataDisks = Get-AzureDataDisk -VM (Get-AzureVM -ServiceName $serviceName -Name $vmName)

    # Get and set storage name
    $StorageAccountName = $vmOSDisk.MediaLink.Host.Split('.')[0]
    Set-AzureSubscription -CurrentStorageAccount $StorageAccountName -SubscriptionName $subName

    $backupContainerName = "backups"
    if (!(Get-AzureStorageContainer -Name $backupContainerName -ErrorAction SilentlyContinue)) {
      New-AzureStorageContainer -Name $backupContainerName -Permission Off
    }

    # Snapshot OS Disk
    $vmOSBlobName = $vmOSDisk.MediaLink.Segments[-1]
    $vmOSContainerName = $vmOSDisk.MediaLink.Segments[-2].Split('/')[0]
   #Error on this line
        Start-AzureStorageBlobCopy -SrcContainer $vmOSContainerName -SrcBlob $vmOSBlobName -DestContainer $backupContainerName 
   #Error on this line
    Get-AzureStorageBlobCopyState -Container $backupContainerName -Blob $vmOSBlobName -WaitForComplete

    #Snapshot Data Disks
    ForEach ($vmDataDisk in $vmDataDisks) {
      $vmDataBlobName = $vmDataDisk.MediaLink.Segments[-1]
      $vmDataContainerName = $vmDataDisk.MediaLink.Segments[-2].Split('/')[0]

      Start-AzureStorageBlobCopy -SrcContainer $vmDataContainerName -SrcBlob $vmDataBlobName -DestContainer $backupContainerName -Force
      Get-AzureStorageBlobCopyState -Container $backupContainerName -Blob $vmDataBlobName -WaitForComplete
    }

    #Get blobs in storage and output
    $insertedBlobs = Get-AzureStorageBlob -Container $backupContainerName
    Write-Output $insertedBlobs
    $vm | Start-AzureVM

}

我无法在网上找到任何内容,在Microsoft论坛上保存一个类似错误的答案,说明VM需要停止,所以我想可能在启动Start-AzureStorageBlobCopy时VM没有完全停止。我尝试使用已停止的VM进行测试但仍然出错。

感谢您的帮助。

1 个答案:

答案 0 :(得分:4)

鉴于错误仅在第一次成功复制后发生,可能发生的事情是Start-AzureStorageBlobCopy cmdlet正在尝试请求用户确认操作,因为它将覆盖现有数据。由于Azure自动化在非交互式会话中运行Runbook,因此无法询问用户确认,因此命令失败。

添加-Force应“强制”用户确认cmdlet并修复问题。您在Start-AzureStorageBlobCopy的第二个实例上有此参数,但不是第一个。

PS - 您应该将此Runbook放在runbook gallery中,以便其他人可以利用它!