public StorageExporter(string databaseBaseDirectory, string databaseOutputFile, int batchSize, Etag documentsStartEtag, bool hasCompression, EncryptionConfiguration encryption, string journalsPath, bool isRavenFs) { HasCompression = hasCompression; Encryption = encryption; baseDirectory = databaseBaseDirectory; outputDirectory = databaseOutputFile; var ravenConfiguration = new RavenConfiguration { DataDirectory = databaseBaseDirectory, CacheDocumentsInMemory = false, Storage = { PreventSchemaUpdate = true, SkipConsistencyCheck = true, Voron = { JournalsStoragePath = journalsPath }, Esent = { JournalsStoragePath = journalsPath } } }; if (isRavenFs) { ravenConfiguration.FileSystem.DataDirectory = databaseBaseDirectory; } CreateTransactionalStorage(ravenConfiguration, isRavenFs); this.batchSize = batchSize; DocumentsStartEtag = documentsStartEtag; }
public EsentExportOperation(string dataDirPath, bool hasCompression, EncryptionConfiguration encryption) { var dbFullPath = Path.Combine(dataDirPath, "Data"); try { Api.JetCreateInstance(out instance, "instance"); var ravenConfiguration = new RavenConfiguration(); ravenConfiguration.DataDirectory = dataDirPath; ravenConfiguration.Storage.PreventSchemaUpdate = true; ITransactionalStorage storage; var success = StorageExporter.TryToCreateTransactionalStorage(ravenConfiguration, hasCompression, encryption, out storage); if (success == false) { ConsoleUtils.PrintErrorAndFail("Failed to create transactional storage"); } var configurator = new TransactionalStorageConfigurator(ravenConfiguration, (TransactionalStorage)storage); configurator.ConfigureInstance(instance, dataDirPath); storage.Dispose(); Api.JetInit(ref instance); Api.JetBeginSession(instance, out sesid, null, null); Api.JetAttachDatabase(sesid, dbFullPath, AttachDatabaseGrbit.None); Api.JetOpenDatabase(sesid, dbFullPath, null, out dbid, OpenDatabaseGrbit.None); } catch (Exception e) { ConsoleUtils.PrintErrorAndFail(e.Message, e.StackTrace); } }
public EsentExportOperation(string dataDirPath, bool hasCompression, EncryptionConfiguration encryption) { var dbFullPath = Path.Combine(dataDirPath, "Data"); try { Api.JetCreateInstance(out instance, "instance"); var ravenConfiguration = new RavenConfiguration(); ravenConfiguration.DataDirectory = dataDirPath; ravenConfiguration.Storage.PreventSchemaUpdate = true; ITransactionalStorage storage; var success = StorageExporter.TryToCreateTransactionalStorage(ravenConfiguration, hasCompression, encryption, out storage); if (success == false) ConsoleUtils.PrintErrorAndFail("Failed to create transactional storage"); var configurator = new TransactionalStorageConfigurator(ravenConfiguration, (TransactionalStorage)storage); configurator.ConfigureInstance(instance, dataDirPath); storage.Dispose(); Api.JetInit(ref instance); Api.JetBeginSession(instance, out sesid, null, null); Api.JetAttachDatabase(sesid, dbFullPath, AttachDatabaseGrbit.None); Api.JetOpenDatabase(sesid, dbFullPath, null, out dbid, OpenDatabaseGrbit.None); } catch (Exception e) { ConsoleUtils.PrintErrorAndFail(e.Message, e.StackTrace); } }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, bool hasCompression, EncryptionConfiguration encryption, bool isRavenFs, out ITransactionalStorage storage, out Database.FileSystem.Storage.ITransactionalStorage fileStorage) { storage = null; fileStorage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) { if (isRavenFs) { fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration); } else { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); } } else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data.jfm"))) { if (isRavenFs) { fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration); } else { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); } } if (storage == null && fileStorage == null) { return(false); } if (isRavenFs) { var filesOrderedPartCollection = new OrderedPartCollection <Database.FileSystem.Plugins.AbstractFileCodec>(); fileStorage.Initialize(new UuidGenerator(), filesOrderedPartCollection); return(true); } var orderedPartCollection = new OrderedPartCollection <AbstractDocumentCodec>(); if (encryption != null) { var documentEncryption = new DocumentEncryption(); documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType, encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize)); orderedPartCollection.Add(documentEncryption); } if (hasCompression) { orderedPartCollection.Add(new DocumentCompression()); } storage.Initialize(new SequentialUuidGenerator { EtagBase = 0 }, orderedPartCollection); return(true); }
public StorageExporter(string databaseBaseDirectory, string databaseOutputFile, int batchSize, Etag documentsStartEtag, bool hasCompression, EncryptionConfiguration encryption) { HasCompression = hasCompression; Encryption = encryption; baseDirectory = databaseBaseDirectory; outputDirectory = databaseOutputFile; var ravenConfiguration = new RavenConfiguration { DataDirectory = databaseBaseDirectory, CacheDocumentsInMemory = false, Storage = { PreventSchemaUpdate = true, SkipConsistencyCheck = true, } }; CreateTransactionalStorage(ravenConfiguration); this.batchSize = batchSize; DocumentsStartEtag = documentsStartEtag; }
public StorageExporter(string databaseBaseDirectory, string databaseOutputFile, int batchSize, Etag documentsStartEtag, bool hasCompression, EncryptionConfiguration encryption) { HasCompression = hasCompression; Encryption = encryption; baseDirectory = databaseBaseDirectory; outputDirectory = databaseOutputFile; var ravenConfiguration = new RavenConfiguration { DataDirectory = databaseBaseDirectory, Storage = { PreventSchemaUpdate = true, SkipConsistencyCheck = true } }; CreateTransactionalStorage(ravenConfiguration); this.batchSize = batchSize; DocumentsStartEtag = documentsStartEtag; }
private static bool ValidateArgs(string[] args, out StorgaeExporterConfiguration configuration) { configuration = null; if (args.Count() < 2) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Not enough arguments were provided.\n"); return(false); } if (Directory.Exists(args[0]) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Directory {0} does not exists.\n", args[0]); return(false); } if (StorageExporter.ValidateStorageExists(args[0]) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Directory {0} is not a valid RavenDB storage directory.\n", args[0]); return(false); } var outputDirectory = Path.GetDirectoryName(args[1]); if (Directory.Exists(outputDirectory) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Output directory {0} does not exists.\n", outputDirectory); return(false); } var permissionSet = new PermissionSet(PermissionState.None); var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, args[1]); permissionSet.AddPermission(writePermission); if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "You don't have premissions to write to {0}.\n", args[1]); } var currArgPos = 2; configuration = new StorgaeExporterConfiguration { DatabaseDataDir = args[0], OutputDumpPath = args[1] }; while (currArgPos < args.Length) { switch (args[currArgPos]) { case "-T": configuration.TableName = args[currArgPos + 1]; currArgPos += 2; break; case "-BatchSize": int batchSize; if (int.TryParse(args[currArgPos + 1], out batchSize) && batchSize > 0) { configuration.BatchSize = batchSize; currArgPos += 2; } else { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "BatchSize should be an integer number greater than 0 (BatchSize={0}).\n", args[currArgPos + 1]); return(false); } break; case "-DocumentsStartEtag": Etag etag; if (Etag.TryParse(args[currArgPos + 1], out etag) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "DocumentsStartEtag should be in a valid Etag format, we got {0}.\n", args[currArgPos + 1]); return(false); } configuration.DocumentsStartEtag = etag; currArgPos += 2; break; case "--Compression": configuration.HasCompression = true; currArgPos += 1; break; case "-Encryption": if (args.Length - currArgPos < 3) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Not enough parameters for encryption"); return(false); } var encryption = new EncryptionConfiguration(); var encryptionKey = args[currArgPos + 1]; if (encryption.TrySavingEncryptionKey(encryptionKey) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Encryption key should be in base64 string format, we got {0}.\n", args[currArgPos + 1]); return(false); } string algorithmType = args[currArgPos + 2]; if (encryption.TrySavingAlgorithmType(algorithmType) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Unknown encryption algorithm type, we got {0}.\n", args[currArgPos + 2]); return(false); } string preferedEncryptionKeyBitsSize = args[currArgPos + 3]; if (encryption.SavePreferedEncryptionKeyBitsSize(preferedEncryptionKeyBitsSize) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Encryption key bit size should be in an int, we got {0}.\n", args[currArgPos + 3]); return(false); } configuration.Encryption = encryption; currArgPos += 4; break; case "-JournalsPath": if (Directory.Exists(args[currArgPos + 1]) == false) { ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Specfied journals directory does not exist: {0}).\n", args[currArgPos + 1]); return(false); } configuration.JournalsPath = args[currArgPos + 1]; currArgPos += 2; break; default: ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Unidentified argument {0}.\n", args[currArgPos]); return(false); } } return(true); }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, bool hasCompression, EncryptionConfiguration encryption, out ITransactionalStorage storage) { storage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data"))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); if (storage == null) return false; var orderedPartCollection = new OrderedPartCollection<AbstractDocumentCodec>(); if (encryption != null) { var documentEncryption = new DocumentEncryption(); documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType, encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize)); orderedPartCollection.Add(documentEncryption); } if (hasCompression) { orderedPartCollection.Add(new DocumentCompression()); } storage.Initialize(new SequentialUuidGenerator {EtagBase = 0}, orderedPartCollection); return true; }