Exemple #1
0
        public override void Execute()
        {
            ValidateRestorePreconditionsAndReturnLogsPath("RavenDB.Backup");

            Directory.CreateDirectory(Path.Combine(journalLocation, "logs"));
            Directory.CreateDirectory(Path.Combine(journalLocation, "temp"));
            Directory.CreateDirectory(Path.Combine(journalLocation, "system"));

            CombineIncrementalBackups();

            CopyIndexes();

            var dataFilePath = Path.Combine(databaseLocation, "Data.ravenfs");

            bool         hideTerminationException = false;
            JET_INSTANCE instance;

            Raven.Storage.Esent.TransactionalStorage.CreateInstance(out instance, "restoring " + Guid.NewGuid());
            try
            {
                Configuration.Settings["Raven/Esent/LogsPath"] = journalLocation;
                new TransactionalStorageConfigurator(Configuration).ConfigureInstance(instance, databaseLocation);
                Api.JetRestoreInstance(instance, backupLocation, databaseLocation, RestoreStatusCallback);
                var fileThatGetsCreatedButDoesntSeemLikeItShould =
                    new FileInfo(
                        Path.Combine(
                            new DirectoryInfo(databaseLocation).Parent.FullName, new DirectoryInfo(databaseLocation).Name + "Data"));

                Raven.Storage.Esent.TransactionalStorage.DisableIndexChecking(instance);

                if (fileThatGetsCreatedButDoesntSeemLikeItShould.Exists)
                {
                    fileThatGetsCreatedButDoesntSeemLikeItShould.MoveTo(dataFilePath);
                }

                if (_restoreRequest.Defrag)
                {
                    output("Esent Restore: Begin Database Compaction");
                    TransactionalStorage.Compact(Configuration, CompactStatusCallback);
                    output("Esent Restore: Database Compaction Completed");
                }
            }
            catch (Exception e)
            {
                output("Esent Restore: Failure! Could not restore database!");
                output(e.ToString());
                log.WarnException("Could not complete restore", e);
                hideTerminationException = true;
                throw;
            }
            finally
            {
                try
                {
                    Api.JetTerm(instance);
                }
                catch (Exception)
                {
                    if (hideTerminationException == false)
                    {
                        throw;
                    }
                }
            }
        }
Exemple #2
0
        public void Execute()
        {
            if (File.Exists(Path.Combine(backupLocation, "RavenDB.Backup")) == false)
            {
                output("Error: " + backupLocation + " doesn't look like a valid backup");
                output("Error: Restore Canceled");
                throw new InvalidOperationException(backupLocation + " doesn't look like a valid backup");
            }

            if (Directory.Exists(databaseLocation) && Directory.GetFileSystemEntries(databaseLocation).Length > 0)
            {
                output("Error: Database already exists, cannot restore to an existing database.");
                output("Error: Restore Canceled");
                throw new IOException("Database already exists, cannot restore to an existing database.");
            }

            if (Directory.Exists(databaseLocation) == false)
            {
                Directory.CreateDirectory(databaseLocation);
            }

            if (Directory.Exists(indexLocation) == false)
            {
                Directory.CreateDirectory(indexLocation);
            }

            var logsPath = databaseLocation;

            if (!string.IsNullOrWhiteSpace(configuration.Settings[Constants.RavenLogsPath]))
            {
                logsPath = configuration.Settings[Constants.RavenLogsPath].ToFullPath();

                if (Directory.Exists(logsPath) == false)
                {
                    Directory.CreateDirectory(logsPath);
                }
            }

            Directory.CreateDirectory(Path.Combine(logsPath, "logs"));
            Directory.CreateDirectory(Path.Combine(logsPath, "temp"));
            Directory.CreateDirectory(Path.Combine(logsPath, "system"));

            CombineIncrementalBackups();

            CopyAll(new DirectoryInfo(Path.Combine(backupLocation, "IndexDefinitions")),
                    new DirectoryInfo(Path.Combine(databaseLocation, "IndexDefinitions")));

            CopyIndexDefinitionsFromIncrementalBackups();

            CopyIndexes();

            var dataFilePath = Path.Combine(databaseLocation, "Data");

            bool         hideTerminationException = false;
            JET_INSTANCE instance;

            TransactionalStorage.CreateInstance(out instance, "restoring " + Guid.NewGuid());
            try
            {
                new TransactionalStorageConfigurator(configuration, null).ConfigureInstance(instance, databaseLocation);
                Api.JetRestoreInstance(instance, backupLocation, databaseLocation, RestoreStatusCallback);
                var fileThatGetsCreatedButDoesntSeemLikeItShould =
                    new FileInfo(
                        Path.Combine(
                            new DirectoryInfo(databaseLocation).Parent.FullName, new DirectoryInfo(databaseLocation).Name + "Data"));

                TransactionalStorage.DisableIndexChecking(instance);

                if (fileThatGetsCreatedButDoesntSeemLikeItShould.Exists)
                {
                    fileThatGetsCreatedButDoesntSeemLikeItShould.MoveTo(dataFilePath);
                }

                if (defrag)
                {
                    output("Esent Restore: Begin Database Compaction");
                    TransactionalStorage.Compact(configuration, CompactStatusCallback);
                    output("Esent Restore: Database Compaction Completed");
                }
            }
            catch (Exception e)
            {
                output("Esent Restore: Failure! Could not restore database!");
                output(e.ToString());
                log.WarnException("Could not complete restore", e);
                hideTerminationException = true;
                throw;
            }
            finally
            {
                try
                {
                    Api.JetTerm(instance);
                }
                catch (Exception)
                {
                    if (hideTerminationException == false)
                    {
                        throw;
                    }
                }
            }
        }