简体   繁体   中英

How can I tell when CopyDirectoryAsync from Microsoft.WindowsAzure.Storage.DataMovement.TransferManager has finished?

I am trying to copy many containers from one Azure blob storage account to another blob storage account.

I am using the Microsoft.WindowsAzure.Storage.DataMovement library for C# and the TransferManager.CopyDirectoryAsync method.

I have no problems discovering all my containers, but when I try and copy a container, I get no feedback about blobs that have been copied. I want to copy millions of blobs so I want feedback for when this is finished. I am using an asynchronous server-side copy, IE isServiceCopy = true

I am calling

return await TransferManager.CopyDirectoryAsync(sourceDirectory, 
destinationDirectory, true, options, null).ConfigureAwait(false);

and since I am awaiting I am expecting it not to pass from this line until the copy is complete. But it passes almost immediately, and if I inspect the NumberOfFilesTransferred on the TransferStatus result it is always 0 . Even if I check the result repeatedly in a while loop this number never changes from 0 . However, if I check in the Azure portal, all the expected files have been copied successfully.

I have also tried setting the ProgressHandler on DirectoryTransferContext , and it gets called a few times, but all the properties are 0 .

Does anyone know why I am not getting any feedback from the copy?

Thanks in advance. Chris

This is incorrect:

CloudBlobDirectory sourceDirectory = sourceContainer.GetDirectoryReference(".");
CloudBlobDirectory destinationDirectory = destinationContainer.GetDirectoryReference(".");

Note that Azure Blob Storage doesn't have a real folder hierarchy, the argument here is actually a prefix of the blobs within a blob container. Therefore, please change the code to:

CloudBlobDirectory sourceDirectory = sourceContainer.GetDirectoryReference(string.Empty);
CloudBlobDirectory destinationDirectory = destinationContainer.GetDirectoryReference(string.Empty);

You can poll the CopyState of the blob. For details see https://stackoverflow.com/a/42255582

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM