示例#1
0
        public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup,
	                           FileSystemDocument filesystemDocument)
            : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, filesystemDocument)
        {
            instance = ((TransactionalStorage)filesystem.Storage).Instance;
            backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup");
	    }
示例#2
0
        public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory,
                               string backupDestinationDirectory, StorageEnvironment env, bool incrementalBackup,
                               FileSystemDocument fileSystemDocument)
            : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument)
        {
            if (env == null) throw new ArgumentNullException("env");

            this.env = env;
        }
        protected BaseBackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument filesystemDocument)
        {
            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;
        }
示例#4
0
        public async Task CreateFileSystemWhenExistingWillFail()
        {
            var client = NewAsyncClient();
            var adminClient = client.Admin;

            const string newFileSystemName = "testName_CreateFileSystemWhenExistingWillFail";

            var fileSystemSpec = new FileSystemDocument
            {
                Id = "Raven/FileSystem/" + newFileSystemName,
                Settings =
                 {
                     {Constants.FileSystem.DataDirectory, Path.Combine("~", Path.Combine("FileSystems", newFileSystemName))}
                 }
            };

            await adminClient.CreateFileSystemAsync(fileSystemSpec, newFileSystemName);

            var names = await adminClient.GetNamesAsync();
            Assert.Contains(newFileSystemName, names);

            bool throwsException = false;
            try
            {
                await adminClient.CreateFileSystemAsync(fileSystemSpec, newFileSystemName);
            }
            catch (InvalidOperationException)
            {
                throwsException = true;
            }

            Assert.True(throwsException);
        }
		public async Task CanRestoreBackupOfEncryptedFileSystem(string requestedStorage)
		{
			dataPath = NewDataPath("CanRestoreBackupOfEncryptedFileSystem", false);

			using (var server = CreateServer(8079, requestedStorage: requestedStorage, runInMemory: false, dataDirectory: dataPath))
			{
				var store = server.FilesStore;
				var fs1Doc = new FileSystemDocument()
				{
					Id = "FS1",
					Settings =
					{
						{Constants.FileSystem.DataDirectory, Path.Combine(server.Configuration.FileSystem.DataDirectory, "FS1")},
						{Constants.ActiveBundles, "Encryption"}
					},
					SecuredSettings = new Dictionary<string, string>
					{
						{
							"Raven/Encryption/Key", "arHd5ENxwieUCAGkf4Rns8oPWx3f6npDgAowtIAPox0="
						},
						{
							"Raven/Encryption/Algorithm", "System.Security.Cryptography.DESCryptoServiceProvider, mscorlib"
						},
					},
				};
				await store.AsyncFilesCommands.Admin.CreateFileSystemAsync(fs1Doc, "FS1");

				using (var session = store.OpenAsyncSession("FS1"))
				{
					session.RegisterUpload("test1.txt", StringToStream("Secret password"));
					session.RegisterUpload("test2.txt", StringToStream("Security guard"));
					await session.SaveChangesAsync();
				}

				await store.AsyncFilesCommands.ForFileSystem("FS1").Admin.StartBackup(backupDir, null, false, "FS1");
				WaitForBackup(store.AsyncFilesCommands.ForFileSystem("FS1"), true);

				string filesystemDir = Path.Combine(server.Configuration.FileSystem.DataDirectory, "FS2");

				await store.AsyncFilesCommands.Admin.StartRestore(new FilesystemRestoreRequest
				{
					BackupLocation = backupDir,
					FilesystemName = "FS2",
					FilesystemLocation = filesystemDir
				});

				SpinWait.SpinUntil(() => store.AsyncFilesCommands.Admin.GetNamesAsync().Result.Contains("FS2"),
							Debugger.IsAttached ? TimeSpan.FromMinutes(10) : TimeSpan.FromMinutes(1));

				using (var session = server.DocumentStore.OpenAsyncSession(Constants.SystemDatabase))
				{
					var fs2Doc = await session.LoadAsync<FileSystemDocument>(Constants.FileSystem.Prefix + "FS2");

					Assert.NotEqual(fs1Doc.SecuredSettings["Raven/Encryption/Key"], fs2Doc.SecuredSettings["Raven/Encryption/Key"]);
					Assert.NotEqual(fs1Doc.SecuredSettings["Raven/Encryption/Algorithm"], fs2Doc.SecuredSettings["Raven/Encryption/Algorithm"]);
				}

				using (var session = store.OpenAsyncSession("FS2"))
				{
					var test1 = StreamToString(await session.DownloadAsync("test1.txt"));

					Assert.Equal("Secret password", test1);

					var test2 = StreamToString(await session.DownloadAsync("test2.txt"));

					Assert.Equal("Security guard", test2);
				}
			}

			Close();

			EncryptionTestUtil.AssertPlainTextIsNotSavedInAnyFileInPath(new[]
			{
				"Secret password", "Security guard"
			}, dataPath, s => true);
		}
示例#6
0
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument fileSystemDocument)
        {
            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);
            Task.Factory.StartNew(backupOperation.Execute);
        }
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup,
            FileSystemDocument fileSystemDocument)
        {
            if (tableStorage == null)
                throw new InvalidOperationException("Cannot begin database backup - table store is not initialized");

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory,
                backupDestinationDirectory, tableStorage.Environment, incrementalBackup, fileSystemDocument);

            Task.Factory.StartNew(() =>
            {
                using (backupOperation)
                    backupOperation.Execute();
            });
        }
 private void EnsureFileSystemHasRequiredSettings(string id, FileSystemDocument fsDoc)
 {
     if (!fsDoc.Settings.ContainsKey(Constants.FileSystem.DataDirectory))
         fsDoc.Settings[Constants.FileSystem.DataDirectory] = "~/FileSystems/" + id;
 }