public static void Restore(RavenConfiguration configuration, DatabaseRestoreRequest restoreRequest, Action <string> output)
        {
            var databaseDocumentPath = FindDatabaseDocument(restoreRequest.BackupLocation);

            if (File.Exists(databaseDocumentPath) == false)
            {
                throw new InvalidOperationException("Cannot restore when the Database.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
            }

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

            string storage;

            if (databaseDocument.Settings.TryGetValue("Raven/StorageTypeName", out storage) == false)
            {
                storage = "esent";
            }

            if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseLocation))
            {
                configuration.DataDirectory = restoreRequest.DatabaseLocation;
            }

            using (var transactionalStorage = configuration.CreateTransactionalStorage(storage, () => { }))
            {
                transactionalStorage.Restore(restoreRequest, output);
            }
        }
Esempio n. 2
0
        private string GenerateIndexLocation(DatabaseRestoreRequest databaseRestoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration)
        {
            //If we got the index location in the request use that.
            if (databaseRestoreRequest.IndexesLocation != null)
            {
                return(databaseRestoreRequest.IndexesLocation);
            }

            if (globalConfiguration != null)
            {
                //If the system database uses the <database-name>\Indexes\ folder then we did not change the global index folder
                //We can safly create the index folder under the path of the database because this is where it is going to be looked for
                if (globalConfiguration.IndexStoragePath.EndsWith("\\System\\Indexes"))
                {
                    return(Path.Combine(_restoreRequest.DatabaseLocation, "Indexes"));
                }
                //system database restore with global config
                if (string.IsNullOrEmpty(configuration.DatabaseName))
                {
                    return(globalConfiguration.IndexStoragePath);
                }
                //If we got here than the global config has a value for index storage path, will just use that folder
                return($"{globalConfiguration.IndexStoragePath}\\Databases\\{configuration.DatabaseName}");
            }

            return(Path.Combine(_restoreRequest.DatabaseLocation, "Indexes"));
        }
Esempio n. 3
0
 protected BaseRestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action <string> output)
 {
     _restoreRequest  = restoreRequest;
     backupLocation   = restoreRequest.BackupLocation;
     databaseLocation = _restoreRequest.DatabaseLocation.ToFullPath();
     indexLocation    = (_restoreRequest.IndexesLocation ?? Path.Combine(_restoreRequest.DatabaseLocation, "Indexes")).ToFullPath();
     journalLocation  = (_restoreRequest.JournalsLocation ?? _restoreRequest.DatabaseLocation).ToFullPath();
     Configuration    = configuration;
     this.output      = output;
 }
Esempio n. 4
0
        public async Task <Operation> StartRestoreAsync(DatabaseRestoreRequest restoreRequest)
        {
            var request = adminRequest.CreateRestoreRequest();

            await request.WriteAsync(RavenJObject.FromObject(restoreRequest));

            var jsonResponse = await request.ReadResponseJsonAsync().ConfigureAwait(false);

            return(new Operation(innerAsyncServerClient, jsonResponse.Value <long>("OperationId")));
        }
Esempio n. 5
0
        public async Task <Operation> StartRestoreAsync(DatabaseRestoreRequest restoreRequest, CancellationToken token = default(CancellationToken))
        {
            using (var request = adminRequest.CreateRestoreRequest())
            {
                await request.WriteAsync(RavenJObject.FromObject(restoreRequest)).WithCancellation(token);

                var jsonResponse = await request.ReadResponseJsonAsync().WithCancellation(token).ConfigureAwait(false);

                return(new Operation((AsyncServerClient)innerAsyncServerClient.ForSystemDatabase(), jsonResponse.Value <long>("OperationId")));
            }
        }
Esempio n. 6
0
        public static void Restore(RavenConfiguration configuration, DatabaseRestoreRequest restoreRequest, Action <string> output)
        {
            var databaseDocumentPath = FindDatabaseDocument(restoreRequest.BackupLocation);

            if (File.Exists(databaseDocumentPath) == false)
            {
                throw new InvalidOperationException("Cannot restore when the Database.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
            }

            if (File.Exists(Path.Combine(restoreRequest.BackupLocation, Constants.BackupFailureMarker)))
            {
                throw new InvalidOperationException("Backup failure marker was detected. Unable to restore from given directory.");
            }

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

            string storage;

            if (databaseDocument.Settings.TryGetValue("Raven/StorageTypeName", out storage) == false)
            {
                if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename)))
                {
                    storage = InMemoryRavenConfiguration.VoronTypeName;
                }
                else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
                {
                    storage = InMemoryRavenConfiguration.EsentTypeName;
                }
                else
                {
                    storage = InMemoryRavenConfiguration.EsentTypeName;
                }
            }

            if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseLocation))
            {
                configuration.DataDirectory = restoreRequest.DatabaseLocation;
            }

            using (var transactionalStorage = configuration.CreateTransactionalStorage(storage, () => { }, () => { }))
            {
                transactionalStorage.Restore(restoreRequest, output);
            }
        }
Esempio n. 7
0
        protected async Task RestoreDatabaseAsync()
        {
            var backupDir = Path.Combine(@"C:\EmbeddedBackup\" + DatabaseGuid);

            if (!Directory.Exists(backupDir))
            {
                throw new DirectoryNotFoundException("Backup folder not found");
            }

            var restoreRequest = new DatabaseRestoreRequest
            {
                BackupLocation   = backupDir,
                DatabaseLocation = Path.Combine(EmbeddedDatabasePath, @"Databases\StudioHub"),
                DatabaseName     = "StudioHub"
            };

            Store.DatabaseCommands.GlobalAdmin.DeleteDatabase("StudioHub", true);

            var restoreOperation = Store.DatabaseCommands.GlobalAdmin.StartRestore(restoreRequest);
            await restoreOperation.WaitForCompletionAsync().ConfigureAwait(false);
        }
Esempio n. 8
0
        public static void Restore(AppSettingsBasedConfiguration configuration, DatabaseRestoreRequest restoreRequest, Action <string> output)
        {
            var databaseDocumentPath = FindDatabaseDocument(restoreRequest.BackupLocation);

            if (File.Exists(databaseDocumentPath) == false)
            {
                throw new InvalidOperationException("Cannot restore when the Database.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
            }

            if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
            {
                throw new StorageNotSupportedException("Esent is no longer supported. Use Voron instead.");
            }

            if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseLocation))
            {
                configuration.Core.DataDirectory = restoreRequest.DatabaseLocation;
            }

            using (var transactionalStorage = new TransactionalStorage(configuration, () => { }, () => { }, () => { }, () => { }))
            {
                transactionalStorage.Restore(restoreRequest, output);
            }
        }
Esempio n. 9
0
 public void Restore(DatabaseRestoreRequest restoreRequest, Action <string> output, InMemoryRavenConfiguration globalConfiguration)
 {
     new RestoreOperation(restoreRequest, configuration, globalConfiguration, output).Execute();
 }
Esempio n. 10
0
 public void Restore(DatabaseRestoreRequest restoreRequest, Action <string> output)
 {
     new RestoreOperation(restoreRequest, configuration, output).Execute();
 }
Esempio n. 11
0
 public RestoreOperation(DatabaseRestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, InMemoryRavenConfiguration globalConfiguration, Action <string> operationOutputCallback)
     : base(restoreRequest, configuration, globalConfiguration, operationOutputCallback)
 {
 }
Esempio n. 12
0
 public Operation StartRestore(DatabaseRestoreRequest restoreRequest)
 {
     return(AsyncHelpers.RunSync(() => asyncAdminServerClient.StartRestoreAsync(restoreRequest)));
 }
Esempio n. 13
0
 public Operation StartRestore(DatabaseRestoreRequest restoreRequest)
 {
     return(asyncAdminServerClient.StartRestoreAsync(restoreRequest).ResultUnwrap());
 }
Esempio n. 14
0
        public Task StartRestoreAsync(DatabaseRestoreRequest restoreRequest)
        {
            var request = adminRequest.CreateRestoreRequest();

            return(request.WriteAsync(RavenJObject.FromObject(restoreRequest)));
        }
Esempio n. 15
0
 public void StartRestore(DatabaseRestoreRequest restoreRequest)
 {
     asyncAdminServerClient.StartRestoreAsync(restoreRequest).WaitUnwrap();
 }