Azure Powershell将azure存储帐户复制到另一个azure存储帐户

时间:2016-04-11 17:29:37

标签: powershell azure azure-storage-blobs

我正在尝试使用自动化PowerShell脚本将所有容器和文件从一个帐户复制到另一个帐户。脚本运行正常,但我看不到输出,也没有目标文件。

如何更正此脚本,以便将一个azure存储帐户上的所有容器和文件复制到另一个存储帐户,根据需要创建容器?

#Define the source storage account and context.
$SourceStorageAccountName = "importantthings"
$SourceStorageAccountKey = "[mysourcekeyhere]"
$SourceContext = New-AzureStorageContext -StorageAccountName     
$SourceStorageAccountName -StorageAccountKey $SourceStorageAccountKey

#Define the destination storage account and context.
$DestStorageAccountName = "dailybackup"
$DestStorageAccountKey = "[mydestkeyhere]"
$DestContext = New-AzureStorageContext -StorageAccountName $DestStorageAccountName -StorageAccountKey $DestStorageAccountKey
$Containers = Get-AzureStorageContainer -Prefix group -Context $SourceContext
foreach ($Container in $Containers) {
        $DestContainer = New-AzureStorageContainer -Name $Container.Name -Context $DestContext -Force #-Permission Off 
        #Get a reference to blobs in the source container.
        $blob = Get-AzureStorageBlob -Container $Container.Name -Context $SourceContext | Start-CopyAzureStorageBlob -destcontainer $DestContainer.Name #–destblob $blob.name #-srccontainer $Container.Name 
        $blob | Get-AzureStorageBlobCopyState –WaitForComplete  

}

第一个错误是:

New-AzureStorageContainer : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error 
Message: Server failed to authenticate the request. Make sure the value of     Authorization header is formed correctly 
including the signature.
At line:19 char:21
+ ... Container = New-AzureStorageContainer -Name $Container.Name -Context  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [New-AzureStorageContainer], StorageException
+ FullyQualifiedErrorId : 

StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.NewAzureStorageContainerCommand

1 个答案:

答案 0 :(得分:1)

解决方案是确保您拥有存储帐户的正确存储帐户密钥。 愚蠢的错误。