public static CollectBlobs ( Logger log, Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container, string prefix, bool>.Func |
||
log | Logger | |
container | Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer | |
prefix | string | |
condition | bool>.Func | |
countEstimate | int | |
return | IList |
public override void ExecuteCommand() { var sourceClient = SourceStorage.CreateCloudBlobClient(); var sourceContainer = sourceClient.GetContainerReference(SourceContainer); if (!sourceContainer.Exists()) { Log.Warn("No blobs in container!"); return; } var destClient = DestinationStorage.CreateCloudBlobClient(); var destContainer = destClient.GetContainerReference(DestinationContainer); destContainer.CreateIfNotExists(); Log.Info("Collecting blob names in {0} to copy to {1}", SourceStorage.Credentials.AccountName, DestinationStorage.Credentials.AccountName); var blobs = Util.CollectBlobs( Log, sourceContainer, Prefix ?? String.Empty, condition: b => (!PackageBlobsOnly || (!b.Name.StartsWith("/") && String.Equals(b.Name.ToLowerInvariant(), b.Name, StringComparison.Ordinal))), countEstimate: 140000); var count = blobs.Count; int index = 0; Parallel.ForEach(blobs, new ParallelOptions { MaxDegreeOfParallelism = 10 }, blob => { int currentIndex = Interlocked.Increment(ref index); var percentage = (((double)currentIndex / (double)count) * 100); var destBlob = destContainer.GetBlockBlobReference(blob.Name); try { if (!destBlob.Exists() || Overwrite) { Log.Info("[{1:000000}/{2:000000}] ({3:000.00}%) Started Async Copy of {0}.", blob.Name, currentIndex, count, percentage); if (!WhatIf) { destBlob.StartCopyFromBlob(blob); } } else { Log.Info("[{1:000000}/{2:000000}] ({3:000.00}%) Skipped {0}. Blob already Exists", blob.Name, index, count, percentage); } } catch (StorageException stex) { if (stex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict && stex.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.PendingCopyOperation) { Log.Info("[{1:000000}/{2:000000}] ({3:000.00}%) Skipped {0}. Already being copied", blob.Name, index, count, percentage); } } catch (Exception ex) { Log.Error("Error processing {0}: {1}", blob.Name, ex.ToString()); throw; } }); Log.Info("Copies started. Run checkblobcopies with similar parameters to wait on blob copy completion"); }