startCopyFromBlob操作停留在0进度

时间:2015-01-25 08:44:42

标签: azure azure-storage

我正在尝试将页面blob从一个存储帐户复制到另一个存储帐户。复制操作开始,我看到目标存储帐户中的blob - 但是进度总是停留在0.我正在使用java SDK并为源生成SAS。 SAS似乎有效,因为我能够从浏览器下载src blob。以下是我正在使用的一些示例代码

    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();
    }

以下是我用来生成SAS令牌的代码

public static String getSharedAccessURI(String blobName,String snapshotID,CloudBlobContainer container)抛出异常     {         //获取没有快照的srcBlob         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 个答案:

答案 0 :(得分:0)

我们使用备用带宽来执行异步复制,因此在带宽可用之前,副本可能无法启动。在这种情况下,复制进度字段可能在复制状态未决时保持0一段时间。如果blob很小,则进度字段可以在一次拍摄中从0到完成,因为复制非常快。即使blob很大,您的轮询也可能会错过复制进度介于0和内容长度之间的窗口。