I'm trying to use the Azure Storage SDK for Java to copy the page blob of an Azure VM (that is Stopped and Deallocated) from one Azure subscription to another.
Here's the code I'm using:
public class BlobCopyExampleClean {
public static final String sourceStorageConnectionString =
"DefaultEndpointsProtocol=https;"
+ "AccountName=sourceStorageAccount;"
+ "AccountKey=key123";
public static final String destinationStorageConnectionString =
"DefaultEndpointsProtocol=https;"
+ "AccountName=destinationStorageAccount;"
+ "AccountKey=key321";
public static void main(String[] args) {
try {
CloudStorageAccount srcAccount = CloudStorageAccount.parse(sourceStorageConnectionString);
CloudBlobClient srcSrvClient = srcAccount.createCloudBlobClient();
CloudBlobContainer srcContainer = srcSrvClient.getContainerReference("vhds");
CloudStorageAccount destAccount = CloudStorageAccount.parse(destinationStorageConnectionString);
CloudBlobClient destSrvClient = destAccount.createCloudBlobClient();
CloudBlobContainer destContainer = destSrvClient.getContainerReference("vhds");
boolean result = destContainer.createIfNotExists();
CloudBlob srcBlob = srcContainer.getPageBlobReference("testvm-2015-11-06.vhd");
if (srcBlob.exists()) {
CloudBlob destBlob = destContainer.getPageBlobReference("testvm-2015-11-06-copied.vhd");
System.out.println("Starting blob copy...");
String copyJobId = destBlob.startCopyFromBlob(srcBlob);
CopyState copyState = destBlob.getCopyState();
while (copyState.getStatus().equals(CopyStatus.PENDING)) {
System.out.println("... copying ...");
Thread.sleep(30000);
}
System.out.println("Copy complete, status was: " + copyState.getStatus() + "!");
} else {
System.out.println("Source blob does not exist!");
}
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (StorageException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
No matter what I try I always get the following error returned to me:
Starting blob copy...
com.microsoft.azure.storage.StorageException: The specified resource does not exist.
at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:89)
at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175)
at com.microsoft.azure.storage.blob.CloudBlob.startCopy(CloudBlob.java:883)
at com.microsoft.azure.storage.blob.CloudBlob.startCopyFromBlob(CloudBlob.java:788)
at com.company.azure.storage.BlobCopyExampleClean.main(BlobCopyExampleClean.java:44)
I've tried using v1.3.1, v3.1.0 & v4.0.0 of the SDK library and get the same error using both blob.startCopyFromBlob() (v1.3.1 & v3.1.0) and blob.startCopy() (v4.0.0).
The page blob in question has no lease, as the Azure Management Portal says the lease status is "Unlocked" and it does exist, even the Azure API confirms this by entering the code block at line 42.
I've tried copying the blob to another storage account within the same subscription and that gives the same error too.
Looking at the exception in more detail the error code is "CannotVerifyCopySource".
Could not verify the copy source within the specified time. Examine the HTTP status code and message for more information about the failure.
. Can you please check the message? It should give you more information. – Gaurav Mantri