public BackupOperation(DocumentDatabase database, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument, ResourceBackupState state, CancellationToken cancellationToken) : base(database, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, databaseDocument, state, cancellationToken) { instance = ((TransactionalStorage)database.TransactionalStorage).Instance; backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup"); }
public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument filesystemDocument, ResourceBackupState state, CancellationToken token) : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, filesystemDocument, state, token) { instance = ((TransactionalStorage)filesystem.Storage).Instance; backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup"); }
protected BaseBackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument filesystemDocument, ResourceBackupState state, CancellationToken token) { if (filesystem == null) { throw new ArgumentNullException("filesystem"); } if (filesystemDocument == null) { throw new ArgumentNullException("filesystemDocument"); } if (backupSourceDirectory == null) { throw new ArgumentNullException("backupSourceDirectory"); } if (backupDestinationDirectory == null) { throw new ArgumentNullException("backupDestinationDirectory"); } this.filesystem = filesystem; this.backupSourceDirectory = backupSourceDirectory.ToFullPath(); this.backupDestinationDirectory = backupDestinationDirectory.ToFullPath(); this.incrementalBackup = incrementalBackup; this.filesystemDocument = filesystemDocument; this.state = state; this.token = token; }
protected BaseBackupOperation(DocumentDatabase database, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument databaseDocument, ResourceBackupState state, CancellationToken cancellationToken) { 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; this.state = state; this.cancellationToken = cancellationToken; }
public BackupOperation(DocumentDatabase database, string backupSourceDirectory, string backupDestinationDirectory, StorageEnvironment env, bool incrementalBackup, DatabaseDocument databaseDocument, ResourceBackupState state, CancellationToken cancellationToken) : base(database, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, databaseDocument, state, cancellationToken) { if (env == null) { throw new ArgumentNullException("env"); } this.env = env; }
public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, StorageEnvironment env, bool incrementalBackup, FileSystemDocument fileSystemDocument, ResourceBackupState state, CancellationToken token) : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument, state, token) { if (env == null) { throw new ArgumentNullException("env"); } this.env = env; }
public Task StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument fileSystemDocument, ResourceBackupState state, CancellationToken token) { 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(filesystem, systemDatabase.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument, state, token); return(Task.Factory.StartNew(backupOperation.Execute)); }
public Task StartBackupOperation(DocumentDatabase database, string backupDestinationDirectory, bool incrementalBackup, DatabaseDocument documentDatabase, ResourceBackupState state, CancellationToken cancellationToken) { 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, state, cancellationToken); return(Task.Factory.StartNew(() => { using (backupOperation) backupOperation.Execute(); })); }
public async Task <HttpResponseMessage> Backup() { var backupRequest = await ReadJsonObjectAsync <FilesystemBackupRequest>().ConfigureAwait(false); var incrementalString = InnerRequest.RequestUri.ParseQueryString()["incremental"]; bool incrementalBackup; if (bool.TryParse(incrementalString, out incrementalBackup) == false) { incrementalBackup = false; } if (backupRequest.FileSystemDocument == null && FileSystem.Name != null) { var jsonDocument = DatabasesLandlord.SystemDatabase.Documents.Get(Constants.FileSystem.Prefix + FileSystem.Name, null); if (jsonDocument != null) { backupRequest.FileSystemDocument = jsonDocument.DataAsJson.JsonDeserialization <FileSystemDocument>(); FileSystemsLandlord.Unprotect(backupRequest.FileSystemDocument); backupRequest.FileSystemDocument.Id = FileSystem.Name; } } var transactionalStorage = FileSystem.Storage; var filesystemDocument = backupRequest.FileSystemDocument; var backupDestinationDirectory = backupRequest.BackupLocation; RavenJObject document = null; try { FileSystem.Storage.Batch(accessor => document = accessor.GetConfig(BackupStatus.RavenBackupStatusDocumentKey)); } catch (FileNotFoundException) { // ok, there isn't another backup in progress } if (document != null) { var backupStatus = document.JsonDeserialization <BackupStatus>(); if (backupStatus.IsRunning) { throw new InvalidOperationException("Backup is already running"); } } HttpResponseMessage message; if (!HasPermissions(backupDestinationDirectory, out message)) { return(message); } bool enableIncrementalBackup; if (incrementalBackup && transactionalStorage is Storage.Esent.TransactionalStorage && (bool.TryParse(FileSystem.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 Storage.Voron.TransactionalStorage && FileSystem.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"); } FileSystem.Storage.Batch(accessor => accessor.SetConfig(BackupStatus.RavenBackupStatusDocumentKey, RavenJObject.FromObject(new BackupStatus { Started = SystemTime.UtcNow, IsRunning = true, }))); if (filesystemDocument.Settings.ContainsKey(Constants.FileSystem.Storage) == false) { filesystemDocument.Settings[Constants.FileSystem.Storage] = transactionalStorage.FriendlyName.ToLower() ?? transactionalStorage.GetType().AssemblyQualifiedName; } var cts = new CancellationTokenSource(); var state = new ResourceBackupState(); var task = transactionalStorage.StartBackupOperation(DatabasesLandlord.SystemDatabase, FileSystem, backupDestinationDirectory, incrementalBackup, filesystemDocument, state, cts.Token); task.ContinueWith(_ => cts.Dispose()); long id; SystemDatabase.Tasks.AddTask(task, state, new TaskActions.PendingTaskDescription { StartTime = SystemTime.UtcNow, TaskType = TaskActions.PendingTaskType.BackupFilesystem, Description = "Backup to: " + backupRequest.BackupLocation }, out id, cts); return(GetMessageWithObject(new { OperationId = id }, HttpStatusCode.Accepted)); }
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())); }