-1
我想通過使用Java將現有的自定義映像從Azure經典存儲帳戶複製到Azure ARM存儲帳戶。 (使用Java編程azCopy試行)如何使用Java將映像從Azure存儲帳戶複製到ARM存儲帳戶?
我想通過使用Java將現有的自定義映像從Azure經典存儲帳戶複製到Azure ARM存儲帳戶。 (使用Java編程azCopy試行)如何使用Java將映像從Azure存儲帳戶複製到ARM存儲帳戶?
這聽起來像你想實現以下使用Java編程azCopy
cmdlet的。
斑點:Copy single blob across Storage accounts
AzCopy /來源:https://sourceaccount.blob.core.windows.net/mycontainer1 /目的地:https://destaccount.blob.core.windows.net/mycontainer2/SourceKey:KEY1/DestKey:鍵2 /Pattern:abc.txt
作爲參考,這是我的使用Java編程實現上述cmdlet的代碼示例,這取決於Azure Storage Client SDK for Java。
複製的關鍵方法是CloudBlob.startCopy
。
import java.net.URI;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.HashMap;
import java.util.Map;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.StorageUri;
import com.microsoft.azure.storage.blob.CloudBlob;
import com.microsoft.azure.storage.blob.CloudBlockBlob;
public class AzCopySample {
private static final String STORAGE_CONNECTION_STRING_TEMPLATE = "DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;";
public static CloudBlob genBlobReference(Map<String, String> cmdOptions, String option) throws URISyntaxException, InvalidKeyException, StorageException {
URI uri = new URI(cmdOptions.get(option));
String host = uri.getHost();
String account = host.substring(0, host.indexOf("."));
String key = cmdOptions.get(option+"Key");
String connectionString = String.format(STORAGE_CONNECTION_STRING_TEMPLATE, account, key);
StorageCredentials credentials = StorageCredentials.tryParseCredentials(connectionString);
StorageUri storageUri = new StorageUri(uri);
CloudBlob blob = new CloudBlockBlob(storageUri, credentials);
return blob;
}
public static void main(String[] args) throws URISyntaxException, InvalidKeyException, StorageException {
String command = "AzCopy /Source:https://sourceaccount.blob.core.windows.net/mycontainer1 /Dest:https://destaccount.blob.core.windows.net/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt";
String[] cmdItems = command.split(" ");
Map<String, String> cmdOptions = new HashMap<>();
for(int i = 1; i < cmdItems.length; i++) {
String cmdItem = cmdItems[i];
int index = cmdItem.indexOf(":");
String key = cmdItem.substring(0, index);
String value = cmdItem.substring(index+1);
cmdOptions.put(key, value);
}
CloudBlob source = genBlobReference(cmdOptions, "/Source");
CloudBlob dest = genBlobReference(cmdOptions, "/Dest");
dest.startCopy(source.getUri());
}
}
嗨,彼得,非常感謝您的幫助。但我掙扎着錯誤「線程中的異常」主「com.microsoft.azure.storage.StorageException:服務器未能驗證請求。請確保授權標頭的值包括簽名正確形成。」你可以幫我嗎 ? – CodeFunda
其他給我代碼複製經典存儲圖像到ARM存儲.... – CodeFunda