如何复制Azure的容器及放大器;斑点 [英] How to Copy Azure Containers & Blobs

查看:132
本文介绍了如何复制Azure的容器及放大器;斑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试所有的斑点复制到不同的存储:

  CloudBlobClient srcblobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobClient targetBlobClient = targetStorageAccount.CreateCloudBlobClient();的foreach(在srcblobClient.ListContainers CloudBlobContainer续())
{
    的foreach(IListBlobItem srcBlob在cont.ListBlobs(useFlatBlobListing:真))
    {
        VAR targetContainer = targetBlobClient.GetContainerReference(cont.Name);
        targetContainer.CreateIfNotExists();        乌里thisBlobUri = srcBlob.Uri;
        VAR serverBlob = srcblobClient.GetBlobReferenceFromServer(thisBlobUri);        ICloudBlob targetBlob = targetContainer.GetBlobReferenceFromServer(serverBlob.Name);        targetBlob.StartCopyFromBlob(thisBlobUri);
    }
}

我能看到的斑点和放大器的上市;被调用的复制方法 targetBlob.StartCopyFromBlob(thisBlobUri);

不过副本不会实际发生。任何想法?

P.S。我使用Azure存储SDK 4.3&安培;目标存储是存储发展

编辑2:

有关上述code远程Azure存储复制正常工作。


  

不过,对于仿真的存储,我得到400错误请求错误,努力营造容器中时:
          targetContainer.CreateIfNotExists();


我的模拟存储的版本是3.0,它似乎还有蔚蓝的SDK和放大器之间的冲突;模拟器版本。


  

其中存储客户端库版本的存储设备可以很好
  模拟器3.0?



解决方案

你得到这个错误的原因是确因版本不匹配的。如果我没有记错的话,存储模拟器版本3.0使用REST API版本 2013-08-15 ,其中作为存储客户端库的最新版本使用REST API版本 2014年2月14日(参考: HTTP ://msdn.microsoft.com/en-us/library/azure/dn744252.aspx )。你可以是使用较旧版本的存储客户端库。您可以通过安装的NuGet合适的版本。例如,如果你想安装的存储客户端库的版本3.2.1,您可以通过执行以下操作:


  

安装封装WindowsAzure.Storage -Version 3.2.1(参考: HTTP: //www.nuget.org/packages/WindowsAzure.Storage/3.2.1


请尝试一下,看看是否能解决这个问题。

另外看你的code,我也建议一些变化:


  • 我不会建议改变对斑点容器中的权限公开。这样的暴露你的Blob存储,使通过匿名访问可用它。我建议是,你创建您的源斑点SAS网址阅读权限,并利用这些SAS的URL复制。因为blob复制是异步的,我会建议保持SAS网址有效期为7天(复制操作的最大时间分配)。

  • 我看到你在做 GetBlobReferenceFromServer 两个源BLOB和BLOB目标。不推荐用于源一滴这种方法,因为它实际上使网络调用因而对于你已经通过上市得到了每个斑点。这是不建议目标的blob,因为此方法将抛出一个未找到(404)如果您的目标一滴不存在。

相反,我会建议是,你投你通过上市钻进适当BLOB类型(块或页面)中的斑点,然后获取SAS URL。如果你知道你所有的斑点是块斑点,你可以简单地扔在CloudBlockBlob对象,而不用担心铸造。

有一件事情我不知道的是网页斑点怎么会被复制。当你的存储帐户之间进行复制,页面BLOB被复制为一个页面斑点。不过,我还没有试过从一个存储账户,以发展存储帐户复制。但是,如果你没有斑点页,你不必担心它。)

I am attempting to copy all the blobs to different storage:

CloudBlobClient srcblobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobClient targetBlobClient = targetStorageAccount.CreateCloudBlobClient();

foreach (CloudBlobContainer cont in srcblobClient.ListContainers())
{
    foreach (IListBlobItem srcBlob in cont.ListBlobs(useFlatBlobListing: true))
    {                        
        var targetContainer = targetBlobClient.GetContainerReference(cont.Name);
        targetContainer.CreateIfNotExists();

        Uri thisBlobUri = srcBlob.Uri;
        var serverBlob = srcblobClient.GetBlobReferenceFromServer(thisBlobUri);

        ICloudBlob targetBlob = targetContainer.GetBlobReferenceFromServer(serverBlob.Name);

        targetBlob.StartCopyFromBlob(thisBlobUri);
    }
}

I am able to see the listing of blobs & copy method is being invoked targetBlob.StartCopyFromBlob(thisBlobUri);

However copy is not actually happening. Any Idea?

P.S. I am using Azure Storage SDK 4.3 & target storage is development storage.

EDIT 2:

For remote azure storage copy above code works fine.

However for Emulated storage I get 400 BadRequest error, when trying to create container: targetContainer.CreateIfNotExists();

My emulated storage version is 3.0, it seems there is conflict between azure SDK & emulator version.

Which version of storage client library works well with storage emulator 3.0?

解决方案

The reason you're getting this error is indeed because of version mismatch. If I am not mistaken, Storage Emulator version 3.0 uses REST API version 2013-08-15 where as the latest version of storage client library uses REST API version 2014-02-14 (Ref: http://msdn.microsoft.com/en-us/library/azure/dn744252.aspx). What you could is make use of an older version of storage client library. You can install appropriate version via Nuget. For example, if you want to install Storage Client Library version 3.2.1, you can do so by doing the following:

Install-Package WindowsAzure.Storage -Version 3.2.1 (Ref: http://www.nuget.org/packages/WindowsAzure.Storage/3.2.1)

Please try it out and see if that fixes the problem.

Also looking at your code, I would also recommend some changes:

  • I would not recommend changing the permission on Blob Container to Public. It kind of exposes your blob storage and makes it available via anonymous access. What I would recommend is that you create SAS URLs with Read Permission on your source blobs and copy using those SAS URLs. Since the blob copy is asynchronous, I would recommend keeping the SAS URL valid for 7 days (maximum time allocated for copy operation).
  • I see that you're doing GetBlobReferenceFromServer on both source blob and target blob. This method is not recommended for source blob as it actually makes a network call thus for each blob you already got through listing. It is not recommended on target blob because this method will throw a Not Found (404) if your target blob does not exist.

Instead what I would recommend is that you cast the blobs you got through listing into appropriate blob type (Block or Page) and then get SAS URL. If you know that all of your blobs are block blobs, you can simply cast them into CloudBlockBlob object without worrying about the casting.

One thing I am not sure of is how page blobs will get copied. When you're copying between storage accounts, a page blob gets copied as a page blob. However I have not tried copying from a storage account to development storage account. But if you don't have page blobs, you don't have to worry about it :).

这篇关于如何复制Azure的容器及放大器;斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆