1
votes

I am attempting to copy a page blob from one storage account to another. The copy operation starts and the I see the blob in the destination storage account - however progress is always stuck at 0. I am using the java SDK and generating a SAS for the source. The SAS appears valid because I was able to download the src blob from the browser. Here is some of the sample code I am using

    CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
    CloudBlobClient strClient = account.createCloudBlobClient();
    CloudBlobContainer strBlobContainer = strClient.getContainerReference("data");    

    CloudStorageAccount backupAccount = CloudStorageAccount.parse(backupStorageConnectionString);
    CloudBlobClient backupClient = backupAccount.createCloudBlobClient();
    CloudBlobContainer backupBlobContainer = backupClient.getContainerReference("data");    


    String src = "SG-aztest10-703-disk-0-test.vhd";
    String target = "Tool-test4.vhd";
    com.microsoft.azure.storage.blob.CloudPageBlob srcBlob = strBlobContainer.getPageBlobReference(src, null);
    com.microsoft.azure.storage.blob.CloudPageBlob dstBlob = backupBlobContainer.getPageBlobReference(target, null);

    System.out.println("Copying src blob " +  " over dst blob " + dstBlob.getUri());
    String copyID = dstBlob.startCopyFromBlob(new URI(getSharedAccessURI(src, null, strBlobContainer)));
    System.out.println("Copy ID is " + copyID);

    dstBlob.downloadAttributes();
    CopyState state = dstBlob.getProperties().getCopyState();
    while(state.getStatus().equals(CopyStatus.PENDING))
    {
        System.out.println("Progress is " + state.getBytesCopied()/state.getTotalBytes());
        Thread.sleep(30000);

        dstBlob.downloadAttributes();
        state = dstBlob.getProperties().getCopyState();
    }

Here is the code I am using to generate the SAS token

public static String getSharedAccessURI(String blobName, String snapshotID, CloudBlobContainer container) throws Exception { //Get the srcBlob without the snapshot CloudPageBlob srcBlob = container.getPageBlobReference(blobName); SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();

    //Start Time = Current Time (UTC) - 15 minutes to account for Clock Skew
    //Expiry Time = Current Time (UTC) + 1 day
    sasPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ));
    sasPolicy.setSharedAccessStartTime(DateTime.now().minusMinutes(15).toDate());
    sasPolicy.setSharedAccessExpiryTime(DateTime.now().plusDays(1).toDate());
    String sasToken = srcBlob.generateSharedAccessSignature(sasPolicy, null);

    String sasURI = null;
    if (snapshotID != null)
    {
        sasURI = String.format("%s?snapshot=%s&%s", srcBlob.getUri().toString(), snapshotID, sasToken);
    }        
    else
    {
        sasURI = String.format("%s?%s", srcBlob.getUri().toString(), sasToken);
    }
    System.out.println("Shared access url is  - " + sasURI);
    return sasURI;
}
1
Here is a sample SAS url I am seeing - sgdevsouthcentralusvm.blob.core.windows.net/data/…Dharshan
After further tests, looks like the CopyStatus field is updated but the getBytesCopied() always returns 0 till the whole process is complete. Is this a bug in the JAVA SDK?Dharshan

1 Answers

0
votes

We use spare bandwidth to do async copies so the copy may not start until bandwidth is available. In that case, the copy progress field may remain 0 for quite some time while the copy status is pending. If the blob is small the progress field may go from 0 to complete in one shot as the copy is very fast. Even if the blob is large, your polling may miss the window during which the copy progress is between 0 and the content length.