public override BackupStatus GetStatusDoc() { var req = CreateRequest("/docs/" + BackupStatus.RavenFilesystemBackupStatusDocumentKey(parameters.Filesystem), "GET"); try { var json = (RavenJObject)req.ReadResponseJson(); return(json.JsonDeserialization <BackupStatus>()); } catch (WebException ex) { var res = ex.Response as HttpWebResponse; if (res == null) { throw new Exception("Network error"); } if (res.StatusCode == HttpStatusCode.NotFound) { return(null); } } return(null); }
public async Task <HttpResponseMessage> Backup() { var backupRequest = await ReadJsonObjectAsync <FilesystemBackupRequest>(); 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("Raven/Filesystems/" + FileSystem.Name, null); if (jsonDocument != null) { backupRequest.FileSystemDocument = jsonDocument.DataAsJson.JsonDeserialization <FileSystemDocument>(); backupRequest.FileSystemDocument.Id = FileSystem.Name; } } var transactionalStorage = FileSystem.Storage; var filesystemDocument = backupRequest.FileSystemDocument; var backupDestinationDirectory = backupRequest.BackupLocation; var document = Database.Documents.Get(BackupStatus.RavenFilesystemBackupStatusDocumentKey(FilesystemName), 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 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 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.RavenFilesystemBackupStatusDocumentKey(FilesystemName), null, RavenJObject.FromObject(new BackupStatus { Started = SystemTime.UtcNow, IsRunning = true, }), new RavenJObject(), null); if (filesystemDocument.Settings.ContainsKey("Raven/StorageTypeName") == false) { filesystemDocument.Settings["Raven/StorageTypeName"] = transactionalStorage.FriendlyName ?? transactionalStorage.GetType().AssemblyQualifiedName; } transactionalStorage.StartBackupOperation(DatabasesLandlord.SystemDatabase, FileSystem, backupDestinationDirectory, incrementalBackup, filesystemDocument); return(GetEmptyMessage(HttpStatusCode.Created)); }
protected void WaitForBackup(string fileStoreName, bool checkError) { Func <string, JsonDocument> getDocument = fsName => servers.First().SystemDatabase.Documents.Get(BackupStatus.RavenFilesystemBackupStatusDocumentKey(fsName), null); var done = SpinWait.SpinUntil(() => { // We expect to get the doc from database that we tried to backup var jsonDocument = getDocument(fileStoreName); if (jsonDocument == null) { return(true); } var backupStatus = jsonDocument.DataAsJson.JsonDeserialization <BackupStatus>(); if (backupStatus.IsRunning == false) { if (checkError) { var firstOrDefault = backupStatus.Messages.FirstOrDefault(x => x.Severity == BackupStatus.BackupMessageSeverity.Error); if (firstOrDefault != null) { Assert.True(false, string.Format("{0}\n\nDetails: {1}", firstOrDefault.Message, firstOrDefault.Details)); } } return(true); } return(false); }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15)); Assert.True(done); }