Пример #1
0
        bool CheckIfBackupExists(string fileOrFolderPath)
        {
            string    azBlobPath = AzureBlobStoreHelper.ConvertToAzureBlobStorePath(fileOrFolderPath);
            CloudBlob blob       = this.container.GetBlobReference(azBlobPath);

            return(blob.Exists());
        }
Пример #2
0
        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);
                    }
                }
            }
        }
Пример #3
0
        public DsmsAzureBlobRecoveryPointStore(Model.DsmsAzureBlobBackupStorageInfo dsmsAzureBlobStoreInformation) : base(dsmsAzureBlobStoreInformation)
        {
            this._storeInformation = dsmsAzureBlobStoreInformation;
            this.InitializeDsmsStorageHelper(this._storeInformation.StorageCredentialsSourceLocation);
            CloudStorageAccount cloudStorageAccount = (CloudStorageAccount)this.getStorageAccountMethodInfo.Invoke(this.dsmsStorageHelper, null);

            this.container = AzureBlobStoreHelper.GetContainer(cloudStorageAccount, this._storeInformation.ContainerName);
        }
Пример #4
0
        public List <string> EnumerateSubFolders(string relativePath)
        {
            if (String.IsNullOrEmpty(relativePath))
            {
                throw new ArgumentException();
            }

            // Convert relative path to AzureStore format.
            string blobStoreRelativePath = AzureBlobStoreHelper.ConvertToAzureBlobStorePath(relativePath);

            // TODO
            throw new NotImplementedException();
        }
Пример #5
0
        private async Task <List <string> > GetBackupLocationsInBackupChainInternalAsync(string backupLocation, CancellationToken cancellationToken)
        {
            var backupLocationList = new List <string>();
            var fullBackupLocation = backupLocation;

            // Check if backup exists
            if (!CheckIfBackupExists(fullBackupLocation))
            {
                throw new FabricElementNotFoundException(String.Format("Missing backup!! Couldn't find backup folder {0} which is there in backup chain", fullBackupLocation));
            }

            var recoveryPointMetadataFileName = GetRecoveryPointMetadataFileNameFromBackupLocation(fullBackupLocation);
            RecoveryPointMetadataFile recoveryPointMetadataFile = null;

            using (MemoryStream ms = new MemoryStream())
            {
                CloudBlockBlob blockBlob = AzureBlobStoreHelper.GetCloudBlockBlobRef(this.container, recoveryPointMetadataFileName);
                await AzureBlobStoreHelper.DownloadToStreamAsync(blockBlob, ms, cancellationToken);

                recoveryPointMetadataFile = await RecoveryPointMetadataFile.OpenAsync(ms, recoveryPointMetadataFileName, cancellationToken);
            }

            backupLocationList.Add(recoveryPointMetadataFile.BackupLocation);

            while (recoveryPointMetadataFile.ParentBackupId != Guid.Empty)
            {
                fullBackupLocation = recoveryPointMetadataFile.ParentBackupLocation;

                // Check if backup folder exists
                if (!CheckIfBackupExists(fullBackupLocation))
                {
                    throw new FabricElementNotFoundException(String.Format("Missing backup!! Couldn't find backup folder {0} which is there in backup chain", fullBackupLocation));
                }

                recoveryPointMetadataFileName = GetRecoveryPointMetadataFileNameFromBackupLocation(fullBackupLocation);
                using (MemoryStream ms = new MemoryStream())
                {
                    CloudBlockBlob blockBlob = AzureBlobStoreHelper.GetCloudBlockBlobRef(this.container, recoveryPointMetadataFileName);
                    await AzureBlobStoreHelper.DownloadToStreamAsync(blockBlob, ms, cancellationToken);

                    recoveryPointMetadataFile = await RecoveryPointMetadataFile.OpenAsync(ms, recoveryPointMetadataFileName, cancellationToken);

                    backupLocationList.Add(recoveryPointMetadataFile.BackupLocation);
                }
            }

            Debug.Assert(recoveryPointMetadataFile.BackupId == recoveryPointMetadataFile.BackupChainId, "Backup ID for root doesn't match with backup chain ID");
            return(backupLocationList);
        }
Пример #6
0
        public AzureBlobRecoveryPointStore(Model.AzureBlobBackupStorageInfo azureBlobStoreInformation) : base(azureBlobStoreInformation)
        {
            this._storeInformation = azureBlobStoreInformation;

            if (azureBlobStoreInformation.IsConnectionStringEncrypted)
            {
                using (var secureString = EncryptionUtility.DecryptText(azureBlobStoreInformation.ConnectionString))
                {
                    this.container = AzureBlobStoreHelper.GetContainer(UtilityHelper.ConvertToUnsecureString(secureString), this._storeInformation.ContainerName);
                }
            }
            else
            {
                this.container = AzureBlobStoreHelper.GetContainer(this._storeInformation.ConnectionString, this._storeInformation.ContainerName);
            }
        }
Пример #7
0
        private async Task <List <RestorePoint> > GetRecoveryPointDetailsInternalAsync(IEnumerable <string> metadataFiles, CancellationToken cancellationToken)
        {
            var backupList = new List <RestorePoint>();

            foreach (var metadataFile in metadataFiles)
            {
                cancellationToken.ThrowIfCancellationRequested();

                using (MemoryStream ms = new MemoryStream())
                {
                    CloudBlockBlob blockBlob = AzureBlobStoreHelper.GetCloudBlockBlobRef(this.container, metadataFile);
                    await AzureBlobStoreHelper.DownloadToStreamAsync(blockBlob, ms, cancellationToken);

                    var recoveryPointMetadataFile =
                        await RecoveryPointMetadataFile.OpenAsync(ms, metadataFile, cancellationToken);

                    var recoveryPoint = new RestorePoint()
                    {
                        BackupChainId        = recoveryPointMetadataFile.BackupChainId,
                        BackupId             = recoveryPointMetadataFile.BackupId,
                        ParentRestorePointId = recoveryPointMetadataFile.ParentBackupId,
                        BackupLocation       = recoveryPointMetadataFile.BackupLocation,
                        CreationTimeUtc      = recoveryPointMetadataFile.BackupTime,
                        BackupType           =
                            recoveryPointMetadataFile.ParentBackupId == Guid.Empty ? BackupOptionType.Full : BackupOptionType.Incremental,
                        EpochOfLastBackupRecord = new BackupEpoch
                        {
                            ConfigurationNumber = recoveryPointMetadataFile.EpochOfLastBackupRecord.ConfigurationNumber,
                            DataLossNumber      = recoveryPointMetadataFile.EpochOfLastBackupRecord.DataLossNumber
                        },
                        LsnOfLastBackupRecord  = recoveryPointMetadataFile.LsnOfLastBackupRecord,
                        PartitionInformation   = this.GetBackupServicePartitionInformationFromServicePartitionInformation(recoveryPointMetadataFile.PartitionInformation),
                        ServiceManifestVersion = recoveryPointMetadataFile.ServiceManifestVersion,
                    };

                    PopulateApplicationServiceAndPartitionInfo(recoveryPoint, metadataFile);

                    backupList.Add(recoveryPoint);
                }
            }

            return(backupList);
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        private static CloudBlobContainer GetContainerRef(string connectionString, string containerName)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            return(AzureBlobStoreHelper.GetContainerRef(storageAccount, containerName));
        }
Пример #10
0
        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);
            }
        }