private void DeleteBlobFolderOrFile(string filePathOrSourceFolderPath, bool isFolder = false) { if (!CheckIfBackupExists(filePathOrSourceFolderPath)) { BackupRestoreTrace.TraceSource.WriteWarning("AzureBlobRecoveryPointManager", "relativefilePathOrSourceFolderPath: {0} not found" , filePathOrSourceFolderPath); return; } if (!isFolder) { AzureBlobStoreHelper.DeleteBlob(AzureBlobStoreHelper.GetCloudBlockBlobRef(this.container, filePathOrSourceFolderPath)); } else { CloudBlobDirectory blobDirectory = AzureBlobStoreHelper.GetCloudBlobDirectoryRef(this.container, filePathOrSourceFolderPath); foreach (IListBlobItem blobItem in AzureBlobStoreHelper.GetBlobList(blobDirectory, true)) { if (blobItem is CloudBlockBlob) { CloudBlockBlob blob = (CloudBlockBlob)blobItem; AzureBlobStoreHelper.DeleteBlob(blob); } } } }
public List <string> EnumerateRecoveryPointMetadataFiles(string relativePath) { if (String.IsNullOrEmpty(relativePath)) { throw new ArgumentException(); } // Convert relative path to AzureStore format. string blobStoreRelativePath = AzureBlobStoreHelper.ConvertToAzureBlobStorePath(relativePath); try { CloudBlobDirectory blobDirectory = AzureBlobStoreHelper.GetCloudBlobDirectoryRef(this.container, blobStoreRelativePath); List <string> metadataBlobs = new List <string>(); foreach (IListBlobItem blobItem in AzureBlobStoreHelper.GetBlobList(blobDirectory, true)) { if (blobItem is CloudBlockBlob) { CloudBlockBlob blob = (CloudBlockBlob)blobItem; if (blob.Name.EndsWith(RecoveryPointMetadataFileExtension)) { metadataBlobs.Add(blob.Name); } } } return(metadataBlobs); } catch (Exception e) { throw new IOException(String.Format("Unable to enumerate metadata files from container:{0} and relative path: {1}.", this.container.Uri, blobStoreRelativePath), e); } }
public List <string> EnumerateRecoveryPointMetadataFiles(string relativePath, DateTime startDateTime, DateTime endDateTime, bool isLatestRequested, BRSContinuationToken continuationToken, int maxResults) { if (String.IsNullOrEmpty(relativePath)) { throw new ArgumentException("relativePath cannot be null"); } if (continuationToken == null) { throw new ArgumentException("continuationToken cannot be null"); } // Convert relative path to AzureStore format. string blobStoreRelativePath = AzureBlobStoreHelper.ConvertToAzureBlobStorePath(relativePath); BlobContinuationToken blobContinuationTokenFromQuery = null; if (!String.IsNullOrEmpty(continuationToken.IncomingContinuationToken)) { string[] continuationTokenList = new string[] { }; try { // continuationToen here equals targetlocation "+" nextMarker. continuationTokenList = continuationToken.IncomingContinuationToken.Split(new char[] { ContinuationTokenSeparatorChar }, 2); } catch (Exception ex) { throw new ArgumentException("continuationToken provided is not correct. Exception thrown: {0}", ex); } if (continuationTokenList.Count() != 2) { throw new ArgumentException("continuationToken provided is not correct. token: {0}", continuationToken.IncomingContinuationToken); } string targetLocation = continuationTokenList[0]; string nextMarker = continuationTokenList[1]; blobContinuationTokenFromQuery = new BlobContinuationToken(); blobContinuationTokenFromQuery.NextMarker = nextMarker; if (targetLocation == "Null") { blobContinuationTokenFromQuery.TargetLocation = null; } else { StorageLocation storageLocation; if (Enum.TryParse <StorageLocation>(targetLocation, out storageLocation)) { blobContinuationTokenFromQuery.TargetLocation = storageLocation; } else { throw new ArgumentException("targetLocation in continuationToken is not correct. {0} ", targetLocation); } } } Dictionary <string, string> latestInPartition = new Dictionary <string, string>(); try { CloudBlobDirectory blobDirectory = AzureBlobStoreHelper.GetCloudBlobDirectoryRef(this.container, blobStoreRelativePath); List <string> metadataBlobs = new List <string>(); int counter = 0; BlobContinuationToken finalBlobContinuationToken = null; BlobContinuationToken currentToken = blobContinuationTokenFromQuery; do { if (maxResults != 0 && counter == maxResults) { break; } int maxResultsQuery = MaximumCount; if (maxResults != 0 && counter + maxResultsQuery > maxResults) { maxResultsQuery = (maxResults - counter) * 2; } maxResultsQuery = (maxResultsQuery < MaximumCount) ? maxResultsQuery : MaximumCount; BlobResultSegment blobResultSegment = AzureBlobStoreHelper.GetBlobList(blobDirectory, true, currentToken, maxResultsQuery); currentToken = blobResultSegment.ContinuationToken; foreach (IListBlobItem blobItem in blobResultSegment.Results) { if (blobItem is CloudBlockBlob) { CloudBlockBlob blob = (CloudBlockBlob)blobItem; string blobName = blob.Name; if (blobName.EndsWith(RecoveryPointMetadataFileExtension)) { // Lets parse the files with respect to date here itself. // Let's parse the date time from file name ListBackupFile(startDateTime, endDateTime, blobName, metadataBlobs, latestInPartition, isLatestRequested, ref counter); } } } } while (currentToken != null); finalBlobContinuationToken = currentToken; if (finalBlobContinuationToken != null) { string nextMarkerFinal = finalBlobContinuationToken.NextMarker; string targetLocationFinal = "Null"; if (finalBlobContinuationToken.TargetLocation != null) { targetLocationFinal = finalBlobContinuationToken.TargetLocation.ToString(); } continuationToken.OutgoingContinuationToken = targetLocationFinal + ContinuationTokenSeparatorChar + nextMarkerFinal; } if (isLatestRequested) { List <string> newMetaDataFileList = new List <string>(); foreach (var tuple in latestInPartition) { newMetaDataFileList.Add(tuple.Value); } return(newMetaDataFileList); } return(metadataBlobs); } catch (Exception e) { throw new IOException(String.Format("Unable to enumerate metadata files from container:{0} and relative path: {1}.", this.container.Uri, blobStoreRelativePath), e); } }