public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (databaseDocument == null) throw new ArgumentNullException("databaseDocument");
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey, null);
            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization<BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            bool enableIncrementalBackup;
            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
                (bool.TryParse(Database.Configuration.Settings["Raven/Esent/CircularLog"], out enableIncrementalBackup) == false || enableIncrementalBackup))
            {
                throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.Voron.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);
            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            if (databaseDocument.Settings.ContainsKey("Raven/StorageTypeName") == false)
                databaseDocument.Settings["Raven/StorageTypeName"] = TransactionalStorage.FriendlyName ?? TransactionalStorage.GetType().AssemblyQualifiedName;

            TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument);
        }
示例#2
0
        public override void LoadFor(DatabaseDocument _)
        {
            var session = ApplicationModel.Current.Server.Value.DocumentStore.OpenAsyncSession(ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name);

            session.Advanced.LoadStartingWithAsync <AuthorizationUser>("Authorization/Users", null).
            ContinueOnSuccessInTheUIThread(data =>
            {
                AuthorizationUsers.Clear();
                foreach (var authorizationUser in data)
                {
                    AuthorizationUsers.Add(authorizationUser);
                }
                foreach (var authorizationUser in data)
                {
                    OriginalAuthorizationUsers.Add(authorizationUser);
                }

                AuthorizationUsers.CollectionChanged += (sender, args) => HasUnsavedChanges = true;
            });

            session.Advanced.LoadStartingWithAsync <AuthorizationRole>("Authorization/Roles", null).
            ContinueOnSuccessInTheUIThread(data =>
            {
                AuthorizationRoles.Clear();
                foreach (var authorizationRole in data)
                {
                    AuthorizationRoles.Add(authorizationRole);
                }
                foreach (var authorizationRole in data)
                {
                    OriginalAuthorizationRoles.Add(authorizationRole);
                }

                AuthorizationRoles.CollectionChanged += (sender, args) => HasUnsavedChanges = true;
            });
        }
示例#3
0
        public void StartBackupOperation(DocumentDatabase docDb, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument documentDatabase)
        {
            if (new InstanceParameters(instance).Recovery == false)
                throw new InvalidOperationException("Cannot start backup operation since the recovery option is disabled. In order to enable the recovery please set the RunInUnreliableYetFastModeThatIsNotSuitableForProduction configuration parameter value to false.");

            var backupOperation = new BackupOperation(docDb, docDb.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, documentDatabase);
            Task.Factory.StartNew(backupOperation.Execute);
        }
示例#4
0
 public Task StartBackupAsync(string backupLocation, DatabaseDocument databaseDocument)
 {
     // No sync equivalent on IDatabaseCommands.
     throw new NotSupportedException();
 }
示例#5
0
        private void SetupDB(IDocumentStore store, string dbName, bool addReplicationTarget, string targetDbName)
        {
            try
            {
                store.DatabaseCommands.GlobalAdmin.DeleteDatabase(dbName, true);
            }
            catch (ErrorResponseException e)
            {
                if (e.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            var databaseDocument = new DatabaseDocument
            {
                Id       = dbName,
                Settings =
                {
                    { "Raven/ActiveBundles", "Replication"             },
                    { "Raven/DataDir",       "~\\Databases\\" + dbName }
                }
            };

            store.DatabaseCommands.EnsureDatabaseDocumentExists(databaseDocument);

            if (addReplicationTarget)
            {
                var replicationDestination = new Raven.Abstractions.Replication.ReplicationDestination()
                {
                    Url = SecondaryDocumentStore.Url,
                    TransitiveReplicationBehavior = TransitiveReplicationOptions.None,
                    Database = targetDbName
                };

                var newReplicationDocument = new Raven.Abstractions.Replication.ReplicationDocument()
                {
                    Destinations = new List <ReplicationDestination>()
                    {
                        replicationDestination
                    }
                };

                using (var session = store.OpenSession(dbName))
                {
                    session.Store(newReplicationDocument, @"Raven/Replication/Destinations");

                    session.SaveChanges();
                }
            }

            new RavenDocumentsByEntityName().Execute(
                store.DatabaseCommands.ForDatabase(dbName),
                store.Conventions
                );

            new DocsIndex().Execute(
                store.DatabaseCommands.ForDatabase(dbName),
                store.Conventions
                );
        }
示例#6
0
 public void CreateDatabase(DatabaseDocument databaseDocument)
 {
     AsyncHelpers.RunSync(() => asyncAdminServerClient.CreateDatabaseAsync(databaseDocument));
 }
示例#7
0
        public async Task <HttpResponseMessage> Restore()
        {
            if (EnsureSystemDatabase() == false)
            {
                return(GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest));
            }

            var restoreStatus = new RestoreStatus {
                Messages = new List <string>()
            };

            var restoreRequest = await ReadJsonObjectAsync <DatabaseRestoreRequest>();

            DatabaseDocument databaseDocument = null;

            var databaseDocumentPath = MaintenanceActions.FindDatabaseDocument(restoreRequest.BackupLocation);

            if (File.Exists(databaseDocumentPath))
            {
                var databaseDocumentText = File.ReadAllText(databaseDocumentPath);
                databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization <DatabaseDocument>();
            }

            var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
                                                                   : databaseDocument == null ? null : databaseDocument.Id;

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id))
                                                                ? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
                                                                : "A database name must be supplied if the restore location does not contain a valid Database.Document file";

                restoreStatus.Messages.Add(errorMessage);
                DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);

                return(GetMessageWithString(errorMessage, HttpStatusCode.BadRequest));
            }

            if (databaseName == Constants.SystemDatabase)
            {
                return(GetMessageWithString("Cannot do an online restore for the <system> database", HttpStatusCode.BadRequest));
            }

            var existingDatabase = Database.Documents.GetDocumentMetadata("Raven/Databases/" + databaseName, null);

            if (existingDatabase != null)
            {
                return(GetMessageWithString("Cannot do an online restore for an existing database, delete the database " + databaseName + " and restore again.", HttpStatusCode.BadRequest));
            }

            var ravenConfiguration = new RavenConfiguration
            {
                DatabaseName     = databaseName,
                IsTenantDatabase = true
            };

            if (databaseDocument != null)
            {
                foreach (var setting in databaseDocument.Settings)
                {
                    ravenConfiguration.Settings[setting.Key] = setting.Value;
                }
            }

            if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename)))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Voron.TransactionalStorage).AssemblyQualifiedName;
            }
            else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
            }

            ravenConfiguration.CustomizeValuesForTenant(databaseName);
            ravenConfiguration.Initialize();

            string documentDataDir;

            ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
            restoreRequest.DatabaseLocation  = ravenConfiguration.DataDirectory;
            DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);

            bool defrag;

            if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
            {
                restoreRequest.Defrag = defrag;
            }

            var task = Task.Factory.StartNew(() =>
            {
                MaintenanceActions.Restore(ravenConfiguration, restoreRequest,
                                           msg =>
                {
                    restoreStatus.Messages.Add(msg);
                    DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                                                   RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
                });

                if (databaseDocument == null)
                {
                    return;
                }

                databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
                if (restoreRequest.IndexesLocation != null)
                {
                    databaseDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation;
                }
                if (restoreRequest.JournalsLocation != null)
                {
                    databaseDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation;
                }
                databaseDocument.Id = databaseName;
                DatabasesLandlord.Protect(databaseDocument);
                DatabasesLandlord.SystemDatabase.Documents.Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument),
                                                               new RavenJObject(), null);

                restoreStatus.Messages.Add("The new database was created");
                DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                                               RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
            }, TaskCreationOptions.LongRunning);

            long id;

            Database.Tasks.AddTask(task, new object(), new TaskActions.PendingTaskDescription
            {
                StartTime = SystemTime.UtcNow,
                TaskType  = TaskActions.PendingTaskType.RestoreDatabase,
                Payload   = "Restoring database " + databaseName + " from " + restoreRequest.BackupLocation
            }, out id);


            return(GetMessageWithObject(new
            {
                OperationId = id
            }));
        }
示例#8
0
 public BackupOperation(DocumentDatabase database, IPersistentSource persistentSource, string src, string to, DatabaseDocument databaseDocument)
 {
     this.database         = database;
     this.persistentSource = persistentSource;
     this.src = src;
     this.to  = to;
     this.databaseDocument = databaseDocument;
 }
        public override void LoadFor(DatabaseDocument document)
        {
            PeriodicBackupSettings = new PeriodicBackupSettings();
            var session = ApplicationModel.Current.Server.Value.DocumentStore
                          .OpenAsyncSession(ApplicationModel.Current.Server.Value.SelectedDatabase.Value.Name);

            if (document.Settings.ContainsKey("Raven/AWSAccessKey") && document.SecuredSettings.ContainsKey("Raven/AWSSecretKey"))
            {
                PeriodicBackupSettings.AwsAccessKey = document.Settings["Raven/AWSAccessKey"];
                PeriodicBackupSettings.AwsSecretKey = document.SecuredSettings["Raven/AWSSecretKey"];
            }

            if (document.Settings.ContainsKey("Raven/AzureStorageAccount") && document.SecuredSettings.ContainsKey("Raven/AzureStorageKey"))
            {
                PeriodicBackupSettings.AzureStorageAccount = document.Settings["Raven/AzureStorageAccount"];
                PeriodicBackupSettings.AzureStorageKey     = document.SecuredSettings["Raven/AzureStorageKey"];
            }

            OriginalPeriodicBackupSettings = new PeriodicBackupSettings
            {
                AwsAccessKey        = PeriodicBackupSettings.AwsAccessKey,
                AwsSecretKey        = PeriodicBackupSettings.AwsSecretKey,
                AzureStorageAccount = PeriodicBackupSettings.AzureStorageAccount,
                AzureStorageKey     = PeriodicBackupSettings.AzureStorageKey
            };

            session.LoadAsync <PeriodicBackupSetup>(PeriodicBackupSetup.RavenDocumentKey).ContinueWith(task =>
            {
                PeriodicBackupSetup = task.Result;

                if (PeriodicBackupSetup == null)
                {
                    return;
                }

                OriginalPeriodicBackupSetup = new PeriodicBackupSetup
                {
                    AwsRegionEndpoint     = PeriodicBackupSetup.AwsRegionEndpoint,
                    AzureStorageContainer = PeriodicBackupSetup.AzureStorageContainer,
                    GlacierVaultName      = PeriodicBackupSetup.GlacierVaultName,
                    IntervalMilliseconds  = PeriodicBackupSetup.IntervalMilliseconds,
                    LocalFolderName       = PeriodicBackupSetup.LocalFolderName,
                    S3BucketName          = PeriodicBackupSetup.S3BucketName
                };

                HasDocument = true;
                if (string.IsNullOrWhiteSpace(PeriodicBackupSetup.LocalFolderName) == false)
                {
                    SelectedOption.Value = 0;
                }
                else if (string.IsNullOrWhiteSpace(PeriodicBackupSetup.GlacierVaultName) == false)
                {
                    SelectedOption.Value = 1;
                }
                else if (string.IsNullOrWhiteSpace(PeriodicBackupSetup.S3BucketName) == false)
                {
                    SelectedOption.Value = 2;
                }
                else if (string.IsNullOrWhiteSpace(PeriodicBackupSetup.AzureStorageContainer) == false)
                {
                    SelectedOption.Value = 3;
                }
                OnPropertyChanged(() => HasDocument);
                OnPropertyChanged(() => PeriodicBackupSetup);
            });
        }
示例#10
0
 public BackupOperation(DocumentDatabase database, string src, string to, bool incrementalBackup, DatabaseDocument databaseDocument)
 {
     instance = ((TransactionalStorage)database.TransactionalStorage).Instance;
     this.src = src;
     this.to  = to;
     this.incrementalBackup = incrementalBackup;
     this.databaseDocument  = databaseDocument;
     this.database          = database;
 }
示例#11
0
        public override void RespondToAdmin(IHttpContext context)
        {
            if (EnsureSystemDatabase(context) == false)
            {
                return;
            }

            var restoreRequest = context.ReadJsonObject <RestoreRequest>();
            var restoreStatus  = new List <string>();

            SystemDatabase.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);

            DatabaseDocument databaseDocument = null;

            if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Database.Document")))
            {
                var databaseDocumentText = File.ReadAllText(Path.Combine(restoreRequest.RestoreLocation, "Database.Document"));
                databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization <DatabaseDocument>();
            }

            var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
                                                                   : databaseDocument == null ? null : databaseDocument.Id;

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                context.SetStatusToBadRequest();

                var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id))
                                        ? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
                                        : "A database name must be supplied if the restore location does not contain a valid Database.Document file";

                context.WriteJson(new
                {
                    Error = errorMessage
                });

                restoreStatus.Add(errorMessage);
                SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                   RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);

                return;
            }

            if (databaseName == Constants.SystemDatabase)
            {
                context.SetStatusToBadRequest();
                context.WriteJson(new
                {
                    Error = "Cannot do an online restore for the <system> database"
                });

                restoreStatus.Add("Cannot do an online restore for the <system> database");
                SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                   RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
                return;
            }


            var ravenConfiguration = new RavenConfiguration
            {
                DatabaseName     = databaseName,
                IsTenantDatabase = true
            };

            if (databaseDocument != null)
            {
                foreach (var setting in databaseDocument.Settings)
                {
                    ravenConfiguration.Settings[setting.Key] = setting.Value;
                }
            }

            if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Managed.TransactionalStorage).AssemblyQualifiedName;
            }
            else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
            }

            ravenConfiguration.CustomizeValuesForTenant(databaseName);
            ravenConfiguration.Initialize();

            string documentDataDir;

            ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);


            var defrag = "true".Equals(context.Request.QueryString["defrag"], StringComparison.InvariantCultureIgnoreCase);

            Task.Factory.StartNew(() =>
            {
                DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, null,
                                         msg =>
                {
                    restoreStatus.Add(msg);
                    SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                       RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
                }, defrag);

                if (databaseDocument == null)
                {
                    restoreStatus.Add("Restore ended but could not create the datebase document, in order to access the data create a database with the appropriate name");
                    SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                       RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
                    return;
                }

                databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
                databaseDocument.Id = databaseName;
                server.Protect(databaseDocument);
                SystemDatabase.Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument),
                                   new RavenJObject(), null);

                restoreStatus.Add("The new database was created");
                SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                   RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
            }, TaskCreationOptions.LongRunning);
        }
示例#12
0
        public void StartBackupOperation(DocumentDatabase database, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (configuration.RunInMemory)
            {
                throw new InvalidOperationException("Backup operation is not supported when running in memory. In order to enable backup operation please make sure that you persistent the data to disk by setting the RunInMemory configuration parameter value to false.");
            }

            var backupOperation = new BackupOperation(database, persistenceSource, database.Configuration.DataDirectory, backupDestinationDirectory, databaseDocument);

            ThreadPool.QueueUserWorkItem(backupOperation.Execute);
        }
示例#13
0
		public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
		{
			var document = Get(BackupStatus.RavenBackupStatusDocumentKey, null);
			if (document != null)
			{
				var backupStatus = document.DataAsJson.JsonDeserialization<BackupStatus>();
				if (backupStatus.IsRunning)
				{
					throw new InvalidOperationException("Backup is already running");
				}
			}
			Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
			{
				Started = SystemTime.UtcNow,
				IsRunning = true,
			}), new RavenJObject(), null);
			IndexStorage.FlushMapIndexes();
			IndexStorage.FlushReduceIndexes();
			TransactionalStorage.StartBackupOperation(this, backupDestinationDirectory, incrementalBackup, databaseDocument);
		}
示例#14
0
        public override void RespondToAdmin(IHttpContext context)
        {
            if (EnsureSystemDatabase(context) == false)
            {
                return;
            }

            var match = urlMatcher.Match(context.GetRequestUrl());
            var db    = Uri.UnescapeDataString(match.Groups[1].Value);

            DatabaseDocument dbDoc;
            var docKey = "Raven/Databases/" + db;

            switch (context.Request.HttpMethod)
            {
            case "GET":
                if (db.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase))
                {
                    //fetch fake (empty) system database document
                    var systemDatabaseDocument = new DatabaseDocument {
                        Id = Constants.SystemDatabase
                    };
                    var serializedDatabaseDocument = RavenJObject.FromObject(systemDatabaseDocument);

                    context.WriteJson(serializedDatabaseDocument);
                }
                else
                {
                    dbDoc = GetDatabaseDocument(context, docKey, db);
                    context.WriteJson(dbDoc);
                }

                break;

            case "PUT":
                if (!db.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase))
                {
                    dbDoc = context.ReadJsonObject <DatabaseDocument>();
                    server.Protect(dbDoc);
                    var json = RavenJObject.FromObject(dbDoc);
                    json.Remove("Id");

                    Database.Put(docKey, null, json, new RavenJObject(), null);
                }
                else
                {
                    context.SetStatusToForbidden();                             //forbidden to edit system database document
                }
                break;

            case "DELETE":
                if (!db.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase))
                {
                    var configuration    = server.CreateTenantConfiguration(db);
                    var databasedocument = Database.Get(docKey, null);

                    if (configuration == null)
                    {
                        return;
                    }
                    Database.Delete(docKey, null, null);
                    bool result;
                    if (bool.TryParse(context.Request.QueryString["hard-delete"], out result) && result)
                    {
                        IOExtensions.DeleteDirectory(configuration.DataDirectory);
                        IOExtensions.DeleteDirectory(configuration.IndexStoragePath);

                        if (databasedocument != null)
                        {
                            dbDoc = databasedocument.DataAsJson.JsonDeserialization <DatabaseDocument>();
                            if (dbDoc != null && dbDoc.Settings.ContainsKey(Constants.RavenLogsPath))
                            {
                                IOExtensions.DeleteDirectory(dbDoc.Settings[Constants.RavenLogsPath]);
                            }
                        }
                    }
                }
                else
                {
                    context.SetStatusToForbidden();                             //forbidden to delete system database document
                }
                break;
            }
        }
示例#15
0
 public virtual void LoadFor(DatabaseDocument document)
 {
 }
示例#16
0
        protected BaseBackupOperation(DocumentDatabase database, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }
            if (backupSourceDirectory == null)
            {
                throw new ArgumentNullException("backupSourceDirectory");
            }
            if (backupDestinationDirectory == null)
            {
                throw new ArgumentNullException("backupDestinationDirectory");
            }

            this.database = database;
            this.backupSourceDirectory      = backupSourceDirectory.ToFullPath();
            this.backupDestinationDirectory = backupDestinationDirectory.ToFullPath();
            this.incrementalBackup          = incrementalBackup;
            this.databaseDocument           = databaseDocument;
        }
示例#17
0
        public override void Execute(object parameter)
        {
            new NewDatabase().ShowAsync()
            .ContinueOnSuccessInTheUIThread(newDatabase =>
            {
                var databaseName = newDatabase.DbName.Text;

                if (Path.GetInvalidPathChars().Any(databaseName.Contains))
                {
                    throw new ArgumentException("Cannot create a database with invalid path characters: " + databaseName);
                }
                if (ApplicationModel.Current.Server.Value.Databases.Count(s => s == databaseName) != 0)
                {
                    throw new ArgumentException("A database with the name " + databaseName + " already exists");
                }

                AssertValidName(databaseName);

                var bundlesModel    = new CreateSettingsModel();
                var bundlesSettings = new List <ChildWindow>();
                if (newDatabase.Encryption.IsChecked == true)
                {
                    bundlesSettings.Add(new EncryptionSettings());
                }
                if (newDatabase.Quotas.IsChecked == true || newDatabase.Versioning.IsChecked == true)
                {
                    bundlesModel = ConfigureSettingsModel(newDatabase);

                    var bundleView = new SettingsDialog()
                    {
                        DataContext = bundlesModel
                    };

                    var bundlesSettingsWindow = new ChildWindow()
                    {
                        Title   = "Setup bundles",
                        Content = bundleView,
                    };

                    bundlesSettingsWindow.KeyDown += (sender, args) =>
                    {
                        if (args.Key == Key.Escape)
                        {
                            bundlesSettingsWindow.DialogResult = false;
                        }
                    };

                    bundlesSettings.Add(bundlesSettingsWindow);
                }

                new Wizard(bundlesSettings).StartAsync()
                .ContinueOnSuccessInTheUIThread(bundlesData =>
                {
                    ApplicationModel.Current.AddNotification(new Notification("Creating database: " + databaseName));
                    var settings        = UpdateSettings(newDatabase, newDatabase, bundlesModel);
                    var securedSettings = UpdateSecuredSettings(bundlesData);

                    var databaseDocument = new DatabaseDocument
                    {
                        Id              = newDatabase.DbName.Text,
                        Settings        = settings,
                        SecuredSettings = securedSettings
                    };

                    string encryptionKey   = null;
                    var encryptionSettings = bundlesData.FirstOrDefault(window => window is EncryptionSettings) as EncryptionSettings;
                    if (encryptionSettings != null)
                    {
                        encryptionKey = encryptionSettings.EncryptionKey.Text;
                    }

                    DatabaseCommands.CreateDatabaseAsync(databaseDocument).ContinueOnSuccess(
                        () => DatabaseCommands.ForDatabase(databaseName).EnsureSilverlightStartUpAsync())
                    .ContinueOnSuccessInTheUIThread(() =>
                    {
                        var model = parameter as DatabasesListModel;
                        if (model != null)
                        {
                            model.ForceTimerTicked();
                        }
                        ApplicationModel.Current.AddNotification(
                            new Notification("Database " + databaseName + " created"));

                        HandleBundleAfterCreation(bundlesModel, databaseName, encryptionKey);

                        ExecuteCommand(new ChangeDatabaseCommand(), databaseName);
                    })
                    .Catch();
                });
            })
            .Catch();
        }
示例#18
0
 public void StartBackup(string backupLocation, DatabaseDocument databaseDocument, bool incremental, string databaseName)
 {
     asyncAdminServerClient.StartBackupAsync(backupLocation, databaseDocument, incremental, databaseName).WaitUnwrap();
 }
示例#19
0
        public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt(string storageName)
        {
            using (var db = new DocumentDatabase(new RavenConfiguration
            {
                DataDirectory = DataDir,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
                DefaultStorageTypeName = storageName,
                Settings =
                {
                    { "Raven/Esent/CircularLog",             "false" },
                    { "Raven/Voron/AllowIncrementalBackups", "true"  }
                }
            }))
            {
                db.SpinBackgroundWorkers();
                db.Indexes.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

                db.Documents.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
                db.Documents.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

                WaitForIndexing(db);

                var databaseDocument = new DatabaseDocument();
                db.Maintenance.StartBackup(BackupDir, false, databaseDocument);
                WaitForBackup(db, true);

                db.Documents.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

                WaitForIndexing(db);

                db.Maintenance.StartBackup(BackupDir, true, databaseDocument);
                WaitForBackup(db, true);
            }
            IOExtensions.DeleteDirectory(DataDir);

            var incrementalDirectories = Directory.GetDirectories(BackupDir, "Inc*");

            // delete 'index-files.required-for-index-restore' to make backup corrupted according to the reported error
            var combine = Directory.GetFiles(incrementalDirectories.First(), "index-files.required-for-index-restore", SearchOption.AllDirectories).First();

            File.Delete(combine);

            var sb = new StringBuilder();

            MaintenanceActions.Restore(new RavenConfiguration(), new RestoreRequest
            {
                BackupLocation   = BackupDir,
                DatabaseLocation = DataDir
            }, s => sb.Append(s));

            Assert.Contains(
                "could not be restored. All already copied index files was deleted." +
                " Index will be recreated after launching Raven instance",
                sb.ToString());

            using (var db = new DocumentDatabase(new RavenConfiguration {
                DataDirectory = DataDir
            }))
            {
                db.SpinBackgroundWorkers();
                QueryResult queryResult;
                do
                {
                    queryResult = db.Queries.Query("Raven/DocumentsByEntityName", new IndexQuery
                    {
                        Query    = "Tag:[[Users]]",
                        PageSize = 10
                    }, CancellationToken.None);
                } while (queryResult.IsStale);
                Assert.Equal(3, queryResult.Results.Count);
            }
        }
示例#20
0
        public Task StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument, ResourceBackupState state, CancellationToken token = default(CancellationToken))
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey, null);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            if (File.Exists(Path.Combine(backupDestinationDirectory, Constants.BackupFailureMarker)))
            {
                throw new InvalidOperationException("Backup failure marker was detected. In order to proceed remove old backup files or supply different backup directory.");
            }

            bool enableIncrementalBackup;

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
                (bool.TryParse(Database.Configuration.Settings[Constants.Esent.CircularLog], out enableIncrementalBackup) == false || enableIncrementalBackup))
            {
                throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.Voron.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started   = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);

            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            if (databaseDocument.Settings.ContainsKey("Raven/StorageTypeName") == false)
            {
                databaseDocument.Settings["Raven/StorageTypeName"] = TransactionalStorage.FriendlyName ?? TransactionalStorage.GetType().AssemblyQualifiedName;
            }

            var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, Database.WorkContext.CancellationToken);

            return(TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument, state, linkedTokenSource.Token)
                   .ContinueWith(_ => linkedTokenSource.Dispose()));
        }
示例#21
0
 private Task SendDatabaseUpdateInternalAsync(NodeConnectionInfo leaderNode, string databaseName, DatabaseDocument document)
 {
     return(PutAsync(leaderNode, "admin/cluster/commands/database/" + Uri.EscapeDataString(databaseName), document));
 }
示例#22
0
 public void StartBackup(string backupLocation, DatabaseDocument databaseDocument, bool incremental, string databaseName)
 {
     AsyncHelpers.RunSync(() => asyncAdminServerClient.StartBackupAsync(backupLocation, databaseDocument, incremental, databaseName));
 }
示例#23
0
        public override void RespondToAdmin(IHttpContext context)
        {
            if (EnsureSystemDatabase(context) == false)
            {
                return;
            }

            var restoreRequest = context.ReadJsonObject <RestoreRequest>();

            DatabaseDocument databaseDocument = null;

            if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Database.Document")))
            {
                var databaseDocumentText = File.ReadAllText(Path.Combine(restoreRequest.RestoreLocation, "Database.Document"));
                databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization <DatabaseDocument>();
            }

            var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
                                                                   : databaseDocument == null ? null : databaseDocument.Id;

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                context.SetStatusToBadRequest();
                context.WriteJson(new
                {
                    Error = "A database name must be supplied if the restore location does not contain a valid Database.Document file"
                });
                return;
            }

            var ravenConfiguration = new RavenConfiguration()
            {
                DatabaseName     = databaseName,
                IsTenantDatabase = true
            };

            if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Managed.TransactionalStorage).AssemblyQualifiedName;
            }
            else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
            }

            ravenConfiguration.CustomizeValuesForTenant(databaseName);
            ravenConfiguration.Initialize();

            string documentDataDir;

            ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);

            var restoreStatus = new List <string>();

            SystemDatabase.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, new TransactionInformation());
            DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, null,
                                     msg =>
            {
                restoreStatus.Add(msg);
                SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                   RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
            });

            if (databaseDocument == null)
            {
                return;
            }

            databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
            databaseDocument.Id = databaseName;
            SystemDatabase.Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument), new RavenJObject(), null);

            restoreStatus.Add("The new database was created");
            SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                               RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
        }
示例#24
0
        public void StartBackupOperation(DocumentDatabase docDb, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument documentDatabase)
        {
            if (new InstanceParameters(instance).Recovery == false)
            {
                throw new InvalidOperationException("Cannot start backup operation since the recovery option is disabled. In order to enable the recovery please set the RunInUnreliableYetFastModeThatIsNotSuitableForProduction configuration parameter value to true.");
            }

            var backupOperation = new BackupOperation(docDb, docDb.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, documentDatabase);

            ThreadPool.QueueUserWorkItem(backupOperation.Execute);
        }
示例#25
0
        public async Task <HttpResponseMessage> Restore()
        {
            if (EnsureSystemDatabase() == false)
            {
                return(GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest));
            }

            var restoreStatus = new RestoreStatus {
                State = RestoreStatusState.Running, Messages = new List <string>()
            };

            var restoreRequest = await ReadJsonObjectAsync <DatabaseRestoreRequest>();

            DatabaseDocument databaseDocument = null;

            var databaseDocumentPath = MaintenanceActions.FindDatabaseDocument(restoreRequest.BackupLocation);

            if (File.Exists(databaseDocumentPath))
            {
                var databaseDocumentText = File.ReadAllText(databaseDocumentPath);
                databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization <DatabaseDocument>();
            }

            var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
                                                                   : databaseDocument == null ? null : databaseDocument.Id;

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id))
                                                                ? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
                                                                : "A database name must be supplied if the restore location does not contain a valid Database.Document file";

                restoreStatus.Messages.Add(errorMessage);
                DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);

                return(GetMessageWithString(errorMessage, HttpStatusCode.BadRequest));
            }

            if (databaseName == Constants.SystemDatabase)
            {
                return(GetMessageWithString("Cannot do an online restore for the <system> database", HttpStatusCode.BadRequest));
            }

            var existingDatabase = Database.Documents.GetDocumentMetadata("Raven/Databases/" + databaseName, null);

            if (existingDatabase != null)
            {
                return(GetMessageWithString("Cannot do an online restore for an existing database, delete the database " + databaseName + " and restore again.", HttpStatusCode.BadRequest));
            }

            var ravenConfiguration = new RavenConfiguration
            {
                DatabaseName     = databaseName,
                IsTenantDatabase = true
            };

            if (databaseDocument != null)
            {
                foreach (var setting in databaseDocument.Settings)
                {
                    ravenConfiguration.Settings[setting.Key] = setting.Value;
                }
            }

            if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename)))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Voron.TransactionalStorage).AssemblyQualifiedName;
            }
            else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
            {
                ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
            }

            ravenConfiguration.CustomizeValuesForDatabaseTenant(databaseName);
            ravenConfiguration.Initialize();

            string documentDataDir;

            ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
            restoreRequest.DatabaseLocation  = ravenConfiguration.DataDirectory;

            string anotherRestoreResourceName;

            if (IsAnotherRestoreInProgress(out anotherRestoreResourceName))
            {
                if (restoreRequest.RestoreStartTimeout.HasValue)
                {
                    try
                    {
                        using (var cts = new CancellationTokenSource())
                        {
                            cts.CancelAfter(TimeSpan.FromSeconds(restoreRequest.RestoreStartTimeout.Value));
                            var token = cts.Token;
                            do
                            {
                                await Task.Delay(500, token);
                            }while (IsAnotherRestoreInProgress(out anotherRestoreResourceName));
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        return(GetMessageWithString(string.Format("Another restore is still in progress (resource name = {0}). Waited {1} seconds for other restore to complete.", anotherRestoreResourceName, restoreRequest.RestoreStartTimeout.Value), HttpStatusCode.ServiceUnavailable));
                    }
                }
                else
                {
                    return(GetMessageWithString(string.Format("Another restore is in progress (resource name = {0})", anotherRestoreResourceName), HttpStatusCode.ServiceUnavailable));
                }
            }
            Database.Documents.Put(RestoreInProgress.RavenRestoreInProgressDocumentKey, null, RavenJObject.FromObject(new RestoreInProgress
            {
                Resource = databaseName
            }), new RavenJObject(), null);

            DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);

            bool defrag;

            if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
            {
                restoreRequest.Defrag = defrag;
            }

            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    MaintenanceActions.Restore(ravenConfiguration, restoreRequest,
                                               msg =>
                    {
                        restoreStatus.Messages.Add(msg);
                        DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                                                       RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
                    });

                    if (databaseDocument == null)
                    {
                        return;
                    }

                    databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
                    if (restoreRequest.IndexesLocation != null)
                    {
                        databaseDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation;
                    }
                    if (restoreRequest.JournalsLocation != null)
                    {
                        databaseDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation;
                    }

                    bool replicationBundleRemoved = false;
                    if (restoreRequest.DisableReplicationDestinations)
                    {
                        replicationBundleRemoved = TryRemoveReplicationBundle(databaseDocument);
                    }

                    databaseDocument.Id = databaseName;
                    DatabasesLandlord.Protect(databaseDocument);
                    DatabasesLandlord
                    .SystemDatabase
                    .Documents
                    .Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument), new RavenJObject(), null);

                    restoreStatus.Messages.Add("The new database was created");
                    restoreStatus.State = RestoreStatusState.Completed;
                    DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                                                   RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);

                    if (restoreRequest.GenerateNewDatabaseId)
                    {
                        GenerateNewDatabaseId(databaseName);
                    }

                    if (replicationBundleRemoved)
                    {
                        AddReplicationBundleAndDisableReplicationDestinations(databaseName);
                    }
                }
                catch (Exception e)
                {
                    restoreStatus.State = RestoreStatusState.Faulted;
                    restoreStatus.Messages.Add("Unable to restore database " + e.Message);
                    DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
                                                                   RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
                    throw;
                }
                finally
                {
                    Database.Documents.Delete(RestoreInProgress.RavenRestoreInProgressDocumentKey, null, null);
                }
            }, TaskCreationOptions.LongRunning);

            long id;

            Database.Tasks.AddTask(task, new TaskBasedOperationState(task), new TaskActions.PendingTaskDescription
            {
                StartTime = SystemTime.UtcNow,
                TaskType  = TaskActions.PendingTaskType.RestoreDatabase,
                Payload   = "Restoring database " + databaseName + " from " + restoreRequest.BackupLocation
            }, out id);


            return(GetMessageWithObject(new
            {
                OperationId = id
            }));
        }
示例#26
0
		public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
		{
			var document = Get(BackupStatus.RavenBackupStatusDocumentKey, null);
			if (document != null)
			{
				var backupStatus = document.DataAsJson.JsonDeserialization<BackupStatus>();
				if (backupStatus.IsRunning)
				{
					throw new InvalidOperationException("Backup is already running");
				}
			}

			bool circularLogging;
			if (incrementalBackup &&
				TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
				(bool.TryParse(Configuration.Settings["Raven/Esent/CircularLog"], out circularLogging) == false || circularLogging))
			{
				throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
			}

			Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
			{
				Started = SystemTime.UtcNow,
				IsRunning = true,
			}), new RavenJObject(), null);
			IndexStorage.FlushMapIndexes();
			IndexStorage.FlushReduceIndexes();
			TransactionalStorage.StartBackupOperation(this, backupDestinationDirectory, incrementalBackup, databaseDocument);
		}
示例#27
0
        private static bool IsIncrementalBackupIsAllowed(DatabasesLandlord databaseLandlord, DatabaseDocument dbDoc)
        {
            // check if DatabaseDocument contains either of the incremental flags
            bool isVoronIncrementalBackup = dbDoc.Settings.ContainsKey("Raven/Voron/AllowIncrementalBackups");
            bool isEsentCircularLog       = dbDoc.Settings.ContainsKey("Raven/Esent/CircularLog");

            if (isVoronIncrementalBackup || isEsentCircularLog)
            {
                if (isEsentCircularLog && bool.TryParse(dbDoc.Settings["Raven/Esent/CircularLog"], out isEsentCircularLog))
                {
                    return((isEsentCircularLog) ? false : true);
                }
                else if (isVoronIncrementalBackup && bool.TryParse(dbDoc.Settings["Raven/Voron/AllowIncrementalBackups"], out isVoronIncrementalBackup))
                {
                    return(isVoronIncrementalBackup);
                }
            }
            // if not check if system configuration has one of the incremental flags up.
            string isVoronIncrementalBackupStr = databaseLandlord.SystemConfiguration.Settings["Raven/Voron/AllowIncrementalBackups"];
            string isEsentCircularLogStr       = databaseLandlord.SystemConfiguration.Settings["Raven/Esent/CircularLog"];

            if (isVoronIncrementalBackupStr != null || isEsentCircularLogStr != null)
            {
                if (isEsentCircularLogStr != null && bool.TryParse(isEsentCircularLogStr, out isEsentCircularLog))
                {
                    return((isEsentCircularLog) ? false : true);
                }
                else if (isVoronIncrementalBackupStr != null && bool.TryParse(isVoronIncrementalBackupStr, out isVoronIncrementalBackup))
                {
                    return(isVoronIncrementalBackup);
                }
            }
            return(false);
        }
示例#28
0
        public void ShouldAllowToChangeActiveBundles_IfSpecialMetadataSpecified()
        {
            using (var store = NewDocumentStore())
            {
                var dbDoc = new DatabaseDocument()
                {
                    Settings = new Dictionary <string, string>()
                    {
                        {
                            Constants.ActiveBundles, ""
                        }
                    }
                };

                store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_1", null, RavenJObject.FromObject(dbDoc), new RavenJObject(), null);

                dbDoc.Settings[Constants.ActiveBundles] = "Replication";

                Assert.DoesNotThrow(() => store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_1", null, RavenJObject.FromObject(dbDoc), new RavenJObject()
                {
                    {
                        Constants.AllowBundlesChange, "true"
                    }
                }, null));


                var dbDoc2 = new DatabaseDocument()
                {
                    Settings = new Dictionary <string, string>()
                    {
                        {
                            Constants.ActiveBundles, "Replication"
                        }
                    }
                };

                store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_2", null, RavenJObject.FromObject(dbDoc2), new RavenJObject(), null);

                dbDoc2.Settings[Constants.ActiveBundles] = "";

                Assert.DoesNotThrow(() => store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_2", null, RavenJObject.FromObject(dbDoc2), new RavenJObject()
                {
                    {
                        Constants.AllowBundlesChange, "true"
                    }
                }, null));

                var dbDoc3 = new DatabaseDocument()
                {
                    Settings = new Dictionary <string, string>()
                    {
                        {
                            Constants.ActiveBundles, "Replication"
                        }
                    }
                };

                store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_3", null, RavenJObject.FromObject(dbDoc3), new RavenJObject(), null);

                dbDoc3.Settings[Constants.ActiveBundles] = "SqlReplication";

                Assert.DoesNotThrow(() => store.SystemDatabase.Documents.Put("Raven/Databases/RavenDB_1344_3", null, RavenJObject.FromObject(dbDoc3), new RavenJObject()
                {
                    {
                        Constants.AllowBundlesChange, "true"
                    }
                }, null));
            }
        }
示例#29
0
 public static Task CreateDatabaseAsync(this IAsyncDatabaseCommands self, DatabaseDocument databaseDocument)
 {
     return(self.GlobalAdmin.CreateDatabaseAsync(databaseDocument));
 }
示例#30
0
        public void StartBackup(string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument)
        {
            if (databaseDocument == null)
            {
                throw new ArgumentNullException("databaseDocument");
            }
            var document = Database.Documents.Get(BackupStatus.RavenBackupStatusDocumentKey, null);

            if (document != null)
            {
                var backupStatus = document.DataAsJson.JsonDeserialization <BackupStatus>();
                if (backupStatus.IsRunning)
                {
                    throw new InvalidOperationException("Backup is already running");
                }
            }

            bool enableIncrementalBackup;

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Esent.TransactionalStorage &&
                (bool.TryParse(Database.Configuration.Settings["Raven/Esent/CircularLog"], out enableIncrementalBackup) == false || enableIncrementalBackup))
            {
                throw new InvalidOperationException("In order to run incremental backups using Esent you must have circular logging disabled");
            }

            if (incrementalBackup &&
                TransactionalStorage is Raven.Storage.Voron.TransactionalStorage &&
                Database.Configuration.Storage.Voron.AllowIncrementalBackups == false)
            {
                throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true");
            }

            Database.Documents.Put(BackupStatus.RavenBackupStatusDocumentKey, null, RavenJObject.FromObject(new BackupStatus
            {
                Started   = SystemTime.UtcNow,
                IsRunning = true,
            }), new RavenJObject(), null);
            Database.IndexStorage.FlushMapIndexes();
            Database.IndexStorage.FlushReduceIndexes();

            if (databaseDocument.Settings.ContainsKey("Raven/StorageTypeName") == false)
            {
                databaseDocument.Settings["Raven/StorageTypeName"] = TransactionalStorage.FriendlyName ?? TransactionalStorage.GetType().AssemblyQualifiedName;
            }

            TransactionalStorage.StartBackupOperation(Database, backupDestinationDirectory, incrementalBackup, databaseDocument);
        }
示例#31
0
 public static void CreateDatabase(this IDatabaseCommands self, DatabaseDocument databaseDocument)
 {
     self.GlobalAdmin.CreateDatabase(databaseDocument);
 }
示例#32
0
        protected InMemoryRavenConfiguration CreateConfiguration(
            string tenantId,
            DatabaseDocument document,
            string folderPropName,
            InMemoryRavenConfiguration parentConfiguration,
            Dictionary <string, string> clusterSettings)
        {
            var effectiveParentSettings = new NameValueCollection(parentConfiguration.Settings);

            if (clusterSettings != null)
            {
                foreach (var keyValuePair in clusterSettings)
                {
                    effectiveParentSettings[keyValuePair.Key] = keyValuePair.Value;
                }
            }

            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(effectiveParentSettings),
            };

            if (config.Settings["Raven/CompiledIndexCacheDirectory"] == null)
            {
                var compiledIndexCacheDirectory = parentConfiguration.CompiledIndexCacheDirectory;
                config.Settings["Raven/CompiledIndexCacheDirectory"] = compiledIndexCacheDirectory;
            }

            if (config.Settings[Constants.TempPath] == null)
            {
                config.Settings[Constants.TempPath] = parentConfiguration.TempPath;
            }

            SetupTenantConfiguration(config);

            config.CustomizeValuesForDatabaseTenant(tenantId);

            config.Settings["Raven/StorageEngine"] = parentConfiguration.DefaultStorageTypeName;

            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            config.Settings[folderPropName] = config.Settings[folderPropName].ToFullPath(parentConfiguration.DataDirectory);
            config.Settings[Constants.RavenEsentLogsPath] = config.Settings[Constants.RavenEsentLogsPath].ToFullPath(parentConfiguration.DataDirectory);
            config.Settings[Constants.RavenTxJournalPath] = config.Settings[Constants.RavenTxJournalPath].ToFullPath(parentConfiguration.DataDirectory);

            config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

            config.DatabaseName     = tenantId;
            config.IsTenantDatabase = true;

            config.Initialize();
            config.CopyParentSettings(parentConfiguration);
            return(config);
        }
示例#33
0
 public void CreateDatabase(DatabaseDocument databaseDocument)
 {
     asyncAdminServerClient.CreateDatabaseAsync(databaseDocument).WaitUnwrap();
 }
示例#34
0
        public Task StartBackupOperation(DocumentDatabase docDb, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument documentDatabase, ResourceBackupState state, CancellationToken cancellationToken)
        {
            if (new InstanceParameters(instance).Recovery == false)
            {
                throw new InvalidOperationException("Cannot start backup operation since the recovery option is disabled. In order to enable the recovery please set the RunInUnreliableYetFastModeThatIsNotSuitableForProduction configuration parameter value to false.");
            }

            var backupOperation = new BackupOperation(docDb, docDb.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, documentDatabase, state, cancellationToken);

            return(Task.Factory
                   .StartNew(backupOperation.Execute));
        }
示例#35
0
		public void StartBackupOperation(DocumentDatabase database, string backupDestinationDirectory, bool incrementalBackup,
			DatabaseDocument documentDatabase)
		{
			if (tableStorage == null) 
				throw new InvalidOperationException("Cannot begin database backup - table store is not initialized");
			
			var backupOperation = new BackupOperation(database, database.Configuration.DataDirectory,
		        backupDestinationDirectory, tableStorage.Environment, incrementalBackup,documentDatabase);
			
            Task.Factory.StartNew(backupOperation.Execute);
		}