Пример #1
0
        private IEnumerable <BackupItemReference> GetReverseBackupSequence(
            DateTime?minBackupEndTime, DateTime?restoreTargetTime, SupportedBackupType backupType)
        {
            var reverseFileSequence = BackupFileCatalog.GetReverseBackupSequence(restoreTargetTime, backupType);

            return(GetReverseBackupSequence(minBackupEndTime, restoreTargetTime, reverseFileSequence));
        }
Пример #2
0
        /// <summary>
        ///     Factory method creating catalog for calendar month folders and default 'month-day-day' file naming convention.
        /// </summary>
        public static BackupFileCatalog CreateDefaultMonthDayDayCatalog(string databaseBackupFolder)
        {
            Check.DoRequireArgumentNotNull(databaseBackupFolder, "databaseBackupFolder");

            var namingConvention = BackupDirectoryNamingConvention.CreateDefaultMonthDayDayConvention();

            var result = new BackupFileCatalog(namingConvention, databaseBackupFolder);

            return(result);
        }
Пример #3
0
        /// <summary>
        ///     Set EndTime to start of the next file of the same type where it has not yet been set explicitly.
        /// </summary>
        /// <param name="objectSequence">
        ///     Must be sorted chronologically
        /// </param>
        public static void InferEndTimeWhereNotDefinedExplicitly(List <BackupFileInfo> objectSequence)
        {
            var supportedBackupTypes = Enumerable.Cast <SupportedBackupType>(
                Enum.GetValues(typeof(SupportedBackupType)))
                                       .Where(t => t != SupportedBackupType.None);

            foreach (var tp in supportedBackupTypes)
            {
                var filesOfTheSameType = objectSequence.Where(o => o.BackupType == tp).ToList();
                BackupFileCatalog.InferEndTimeWhereNotDefinedExplicitly(filesOfTheSameType);
            }
        }
Пример #4
0
        /// <summary>
        ///     Factory method creating catalog for calendar month folders and given file naming convention.
        /// </summary>
        /// <param name="fileNamingConvention">
        ///     File naming convention to use.
        /// </param>
        public static BackupFileCatalog CreateMonthlyCatalog(string databaseBackupFolder, IBackupFileNamingConvention fileNamingConvention)
        {
            Check.DoRequireArgumentNotNull(databaseBackupFolder, "databaseBackupFolder");
            Check.DoRequireArgumentNotNull(fileNamingConvention, "fileNamingConvention");


            var namingConvention = BackupDirectoryNamingConvention.CreateMonthlyConvention(fileNamingConvention);

            var result = new BackupFileCatalog(namingConvention, databaseBackupFolder);

            return(result);
        }
Пример #5
0
        /// <summary>
        ///     Verified sequence of backup items to restore to achieve configured outcome.
        ///     Never returns null.
        /// </summary>
        /// <param name="lastDatabaseBackupItem"></param>
        /// <returns></returns>
        private List <BackupItem> GetLogBackupItems(BackupItem lastDatabaseBackupItem, DateTime?targetTime)
        {
            Check.DoRequireArgumentNotNull(lastDatabaseBackupItem, "lastDatabaseBackupItem");

            var result = new List <BackupItem>(1000);

            var logFiles = BackupFileCatalog.GetLogBackupsSequence(lastDatabaseBackupItem.BackupStartTime);

            // need only first log backup after target time; flag indicates that file is already processed
            var targetReached = false;
            var fileIterator  = logFiles.GetEnumerator();

            var lastBackupItem = lastDatabaseBackupItem;

            while (!targetReached && fileIterator.MoveNext())
            {
                var header = ParseBackupHeader(fileIterator.Current.FileInfo);

                if (header != null)
                {
                    var itemIterator = header.ValidItems.GetEnumerator();

                    while (!targetReached && itemIterator.MoveNext())
                    {
                        var item = itemIterator.Current;

                        Check.DoAssertLambda(CheckSequence(lastBackupItem, item, false), () =>
                                             $"Item #{item.Position} in file {item.FileInfo.Name} cannot be applied after item #{lastBackupItem.Position} in" +
                                             $" file {lastBackupItem.FileInfo.Name}");
                        lastBackupItem = item;

                        result.Add(item);

                        targetReached = (targetTime.HasValue && item.BackupStartTime > targetTime.Value);
                    }
                }
            }

            return(result);
        }