从Azure Blob复制到AWS S3存储桶

时间:2015-11-07 11:36:48

标签: powershell azure amazon-web-services amazon-s3 azure-storage-blobs

我正在尝试编写一个PowerShell脚本,该脚本可以递归地从Azure Blob复制到Amazon AWS S3 Bucket但是没有太大的成功。

有人能帮助我吗?

$container_name = @("<ContainerItemName>")
$connection_string = 'DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>'

$storage_account = New-AzureStorageContext -ConnectionString $connection_string

$S3Bucket = "<BucketName>"

foreach ($container_item in $container_name)
{
    $blobs = Get-AzureStorageBlob -Container $container_item -Context $storage_account

    foreach ($blob in $blobs)
    {
        $item = Get-AzureStorageBlobContent -Container $container_item -Blob $blob.Name -Context $storage_account
        Write-S3Object -BucketName $S3Bucket -KeyPrefix $container_item\ -Folder $item -Force
    }
}

2 个答案:

答案 0 :(得分:1)

一种选择是使用Azure存储数据移动库。您可以在此处下载示例代码:https://github.com/Azure/azure-storage-net-data-movement/tree/master/samples/S3ToAzureSample。以下文章包含有关数据移动库的更多信息:https://azure.microsoft.com/en-us/blog/introducing-azure-storage-data-movement-library-preview-2/

答案 1 :(得分:0)

我没有玩过AWS PowerShell Cmdlet(所以我可能错了)但是快速浏览一下他们的文档here,我认为你需要首先在本地计算机上保存blob然后再指定您Write-S3Object cmdlet -File参数中的路径。

将Azure Blob下载到目录:

Get-AzureStorageBlobContent -Container containername -Blob blob -Destination C:\test\

假设blob的名称是blob.png,请将其上传到S3:

Write-S3Object -BucketName $S3Bucket -KeyPrefix $container_item\ -File "C:\test\blob.png" -Force
相关问题