簡體   English   中英

Azure將Blob復制到不同的高級存儲帳戶

[英]Azure Copy blob to different premium storage account

我正在嘗試將一個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);
}

不知道為什么會發生這種情況,因為我能夠通過其他工具(雲莓等)將blob從一個存儲帳戶復制到另一個存儲帳戶。

感謝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;

你能檢查blob是否仍然在Azure門戶中注冊為虛擬磁盤? 如果是這樣,請刪除磁盤引用但保留關聯的VHD,以便釋放該blob的租約。

如果您不想刪除Azure門戶中的虛擬磁盤引用,則可以為關聯的Blob創建Blob快照,並在復制Blob時將快照輸入為Blob源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM