【问题标题】:Azure Copy blob to different premium storage accountAzure 将 blob 复制到不同的高级存储帐户
【发布时间】:2017-01-03 17:24:42
【问题描述】:

我正在尝试将一个 blob(特别是 vhd)从存储帐户复制到另一个存储帐户。我正在编写的应用程序具有对两个存储帐户的所有者访问权限,并且可以在这些存储帐户上运行其他操作。 vhd 上没有租约(未附加 VM)。我有以下代码,但得到 403 禁止响应。

StorageCredentials scSource = new StorageCredentials(SourceStorageName, strSourceStorageKey);
StorageCredentials scTarget = new StorageCredentials(TargetStorageName, strTargetStorageKey);
CloudStorageAccount csaSource = new CloudStorageAccount(scSource, true);
CloudStorageAccount csaTarget = new CloudStorageAccount(scTarget, true);
CloudBlobClient cbcSource = csaSource.CreateCloudBlobClient();
CloudBlobClient cbcTarget = csaTarget.CreateCloudBlobClient();
CloudBlobContainer bcSource = cbcSource.GetContainerReference(SourceContainer);
CloudBlobContainer bcTarget = cbcTarget.GetContainerReference(TargetContainer);
CloudBlob cbSource = bcSource.GetBlobReference(strSourceDiskName);
CloudBlob cbTarget = bcTarget.GetBlobReference(strTargetDiskName);
Task<string> tskCopy = cbTarget.StartCopyAsync(cbSource.Uri);
while (tskCopy.Status != TaskStatus.RanToCompletion)
{
    if (tskCopy.Exception != null)
    throw tskCopy.Exception;
    Thread.Sleep(2500);
}

不知道为什么会发生这种情况,因为我可以通过其他工具(cloud berry 等)将 blob 从一个存储帐户复制到另一个帐户。

【问题讨论】:

  • 能否请您检查源容器的ACL?源容器中用于复制的 blob 应该是公开可用的。
  • 高级存储帐户容器数据只能设置为帐户所有者的私有访问权限。
  • 在这种情况下,您需要在源 blob 上创建一个至少具有 Read 权限的 SAS URL,并将其用作源 URL 而不是 blob 的 URL。

标签: c# azure blob azure-blob-storage


【解决方案1】:

能否检查 blob 是否仍在 Azure 门户中注册为虚拟磁盘?如果是这样,请删除磁盘引用但保留关联的 VHD,以便释放该 blob 的租约。

如果不想在 Azure Portal 中删除虚拟磁盘引用,可以为关联的 blob 创建一个 blob 快照,并在复制 blob 时输入快照作为 blob 源。

【讨论】:

  • VHD 未附加到 VM 或 OS 磁盘。 VHD 不在经典存储帐户中,而是在 ARM 存储帐户中。
【解决方案2】:

感谢 Gaurav Mantri 为我指明了正确的方向。在查找共享访问签名后,我发现了这篇来自 Microsoft https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/

的文章

这段代码要具体:

SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;

// Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

// Return the URI string for the container, including the SAS token.
return blob.Uri + sasBlobToken;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-13
    • 2018-01-29
    • 2021-07-27
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 2022-01-11
    相关资源
    最近更新 更多