2017-02-22 3 views

Antwort

1

Acording zum javadocs von Azure Storage SDK für Java, die Methode listBlobs(String prefix, boolean useFlatBlobListing, EnumSet<BlobListingDetails> listingDetails, BlobRequestOptions options, OperationContext opContext) mit BlobListingDetails.SNAPSHOTS für einen Behälter mit allen Blobs aufzuzählen, die snapshot blob sind durch das Verfahren zum Filtern isSnapshot().

Hier ist mein Beispielcode unten.

String accountName = "<your-storage-account-name>"; 
String accountKey = "<your-storage-account-key>"; 
String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s"; 
String connectionString = String.format(storageConnectionString, accountName, accountKey); 
CloudStorageAccount account = CloudStorageAccount.parse(connectionString); 
CloudBlobClient client = account.createCloudBlobClient(); 
// List all containers of a storage account 
Iterable<CloudBlobContainer> containers = client.listContainers(); 
String prefix = null; 
boolean useFlatBlobListing = true; 
// Specify the blob list which include snapshot blob 
EnumSet<BlobListingDetails> listingDetails = EnumSet.of(BlobListingDetails.SNAPSHOTS); 
BlobRequestOptions options = null; 
OperationContext opContext = null; 
for (CloudBlobContainer container : containers) { 
    Iterable<ListBlobItem> blobItems = container.listBlobs(prefix, useFlatBlobListing, listingDetails, options, 
        opContext); 
    for (ListBlobItem blobItem : blobItems) { 
     if (blobItem instanceof CloudBlob) { 
      CloudBlob blob = (CloudBlob) blobItem; 
      // Check a blob whether be a snapshot blob 
      if (blob.isSnapshot()) { 
       System.out.println(blobItem.getStorageUri()); 
      } 
     } 
    } 
} 

Wenn Sie die REST-API zur Implementierung dieser Anforderungen verwenden möchten, gehen Sie wie folgt vor.

  1. Verwenden Sie List Containers für ein Speicherkonto, um alle Container aufzulisten.
  2. Verwenden List Blobs mit dem URL-Parameter include={snapshots} als Unterabschnitt Blob and Snapshot List der reference sagte, alle Blobs eines Containers, Snapshot Blob, dann alle Snapshot Blobs zu filtern.
Verwandte Themen