Reputation: 1759
I have some c# code to copy a blob from one storage account to another. I noticed that when I make the call to CloudBlob.StartCopyAsync
, the target blob's CopyState.Status
is set to CopyStatus.Pending
. Is there any way that I can get an updated status on the copy operation?
I have tried adding a await Task.Delay(TimeSpan.FromSeconds(10));
after the call, but when the delay finishes, the state still shows pending. If I then try to re-obtain the blob from the storage container, I get CopyStatus == null
.
Upvotes: 3
Views: 6200
Reputation: 6467
Polling for Copy Blob properties: we now provide the following additional properties that allow users to track the progress of the copy, using Get Blob Properties, Get Blob, or List Blobs:
x-ms-copy-status (or CopyStatus): The current status of the copy operation. It can be one of the following: pending: Copy operation is pending. success: Copy operation completed successfully. aborted: Copy operation was aborted by a client. failed: Copy operation failed to complete due to an error.
x-ms-copy-id (CopyId): The id returned by the copy operation which can be used to monitor the progress or abort a copy.
x-ms-copy-status-description (CopyStatusDescription): Additional error information that can be used for diagnostics.
x-ms-copy-progress (CopyProgress): The amount of the blob copied so far. This has the format X/Y where X=number of bytes copied and Y is the total number of bytes.
x-ms-copy-completion-time (CopyCompletionTime): The completion time of the last copy.
These properties can be monitored to track the progress of a copy operation that returns “pending” status. However, it is important to note that except for Put Page, Put Block and Lease Blob operations, any other write operation (i.e., Put Blob, Put Block List, Set Blob Metadata, Set Blob Properties) on the destination blob will remove the properties pertaining to the copy operation.
Please note that you need to periodically poll the copy state from Azure Storage server side, await Task.Delay(TimeSpan.FromSeconds(10));
does nothing actually.
public static void MonitorCopy(CloudBlobContainer destContainer)
{
bool pendingCopy = true;
while (pendingCopy)
{
pendingCopy = false;
var destBlobList = destContainer.ListBlobs(
true, BlobListingDetails.Copy);
foreach (var dest in destBlobList)
{
var destBlob = dest as CloudBlob;
if (destBlob.CopyState.Status == CopyStatus.Aborted ||
destBlob.CopyState.Status == CopyStatus.Failed)
{
// Log the copy status description for diagnostics
// and restart copy
Log(destBlob.CopyState);
pendingCopy = true;
destBlob.StartCopyFromBlob(destBlob.CopyState.Source);
}
else if (destBlob.CopyState.Status == CopyStatus.Pending)
{
// We need to continue waiting for this pending copy
// However, let us log copy state for diagnostics
Log(destBlob.CopyState);
pendingCopy = true;
}
// else we completed this pending copy
}
Thread.Sleep(waitTime);
};
}
Upvotes: 6