/// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public DatabaseRestorer(IBackupFileCatalog backupCatalog, string databaseName, MultiRestorer multiRestorer)
        {
            Check.DoRequireArgumentNotNull(backupCatalog, "backupCatalog");
            _backupCatalog = backupCatalog;
            _databaseName  = databaseName;
            _multiRestorer = multiRestorer;

            _preExistingDatabase = Database != null;
        }
示例#2
0
        public RestorePlanner(IBackupFileCatalog backupFileCatalog, ISqlServerProxy sqlServerProxy, string databaseName)
        {
            Check.DoRequireArgumentNotNull(backupFileCatalog, "backupFileCatalog");
            Check.DoRequireArgumentNotNull(sqlServerProxy, "sqlServerProxy");
            Check.DoRequireArgumentNotNull(databaseName, "databaseName");

            BackupFileCatalog = backupFileCatalog;
            SqlServerProxy    = sqlServerProxy;
            DatabaseName      = databaseName;
        }
        public void TestTargetStartOfMonth()
        {
            var catalog = BackupFileCatalog.CreateDefaultMonthDayDayCatalog(TestSession.TestDbBackupDir.FullName);

            IBackupFileCatalog icatalog = catalog;

            // 1 second before the start of the 2nd day of the second month
            var targetTime = TestSession.StartDate.AddMonths(2);
            // log backup of the day prior to the target time will be necessary
            var logBackupCountApplicable = (int)(TestSession.StartDate.AddMonths(TestSession.TestBckupPeriodMonths) - TestSession.StartDate.AddMonths(2).AddDays(-1)).TotalDays;

            var fullBackups = icatalog.GetReverseBackupSequence(targetTime, SupportedBackupType.Full);
            var diffBackups = icatalog.GetReverseBackupSequence(targetTime, SupportedBackupType.Diff);

            Assert.IsNotNull(fullBackups);
            Assert.IsNotNull(diffBackups);

            var lastFull = fullBackups.FirstOrDefault();
            var lastDiff = diffBackups.FirstOrDefault();

            Assert.IsNotNull(lastFull);
            Assert.IsNotNull(lastDiff);

            Assert.AreEqual(SupportedBackupType.Full, lastFull.BackupType);
            Assert.AreEqual(SupportedBackupType.Diff, lastDiff.BackupType);

            var lastBackupMonthStart = TestSession.StartDate.AddMonths(1);
            var lastBackupDayStart   = lastBackupMonthStart.AddMonths(1).AddDays(-1);

            Assert.AreEqual(lastBackupMonthStart, lastFull.StartTime);
            Assert.AreEqual(lastBackupDayStart, lastDiff.StartTime);

            var logBackups = icatalog.GetLogBackupsSequence(lastBackupDayStart);

            Assert.IsNotNull(logBackups);
            var logBackupsList = logBackups.ToList();

            Assert.AreEqual(logBackupCountApplicable, logBackupsList.Count);

            var firstLog = logBackups.First();

            Assert.IsNotNull(firstLog);
            Assert.AreEqual(lastBackupDayStart, firstLog.StartTime);
            Assert.AreEqual(lastBackupDayStart.AddDays(1), firstLog.EndTime);

            var secondLog = logBackups.Skip(1).First();

            Assert.IsNotNull(secondLog);
            Assert.AreEqual(lastBackupDayStart.AddDays(1), secondLog.StartTime);
            Assert.AreEqual(lastBackupDayStart.AddDays(2), secondLog.EndTime);
        }
        public void TestLatest()
        {
            var catalog = BackupFileCatalog.CreateDefaultMonthDayDayCatalog(TestSession.TestDbBackupDir.FullName);

            IBackupFileCatalog icatalog = catalog;

            var fullBackups = icatalog.GetReverseBackupSequence(null, SupportedBackupType.Full);
            var diffBackups = icatalog.GetReverseBackupSequence(null, SupportedBackupType.Diff);

            Assert.IsNotNull(fullBackups);
            Assert.IsNotNull(diffBackups);

            var lastFull = fullBackups.FirstOrDefault();
            var lastDiff = diffBackups.FirstOrDefault();

            Assert.IsNotNull(lastFull);
            Assert.IsNotNull(lastDiff);

            Assert.AreEqual(SupportedBackupType.Full, lastFull.BackupType);
            Assert.AreEqual(SupportedBackupType.Diff, lastDiff.BackupType);

            var lastBackupMonthStart = TestSession.StartDate.AddMonths(TestSession.TestBckupPeriodMonths - 1);
            var lastBackupDayStart   = lastBackupMonthStart.AddMonths(1).AddDays(-1);

            Assert.AreEqual(lastBackupMonthStart, lastFull.StartTime);
            Assert.AreEqual(lastBackupDayStart, lastDiff.StartTime);

            var logBackups = icatalog.GetLogBackupsSequence(lastBackupDayStart);

            Assert.IsNotNull(logBackups);
            var logBackupsList = logBackups.ToList();

            Assert.AreEqual(1, logBackupsList.Count);

            var lastLog = logBackups.First();

            Assert.IsNotNull(lastLog);
            Assert.AreEqual(lastBackupDayStart, lastLog.StartTime);
            Assert.AreEqual(lastBackupDayStart.AddDays(1), lastLog.EndTime);
        }