Exemple #1
0
        public void Export()
        {
            int batchSize       = BatchSize == 0 ? DefualtBatchSize : BatchSize;
            var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize);

            storageExporter.ExportDatabase();
        }
Exemple #2
0
        public EsentExportOperation(string dataDirPath)
        {
            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, out storage);
                if (!success)
                {
                    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);
            }
        }
Exemple #3
0
        public void Export()
        {
            if (TableName != null)
            {
                using (var esentExportOperation = new EsentExportOperation(DatabaseDataDir, HasCompression, Encryption))
                {
                    esentExportOperation.ExportTable(TableName, OutputDumpPath);
                }
            }
            else
            {
                int batchSize = BatchSize == 0 ? DefaultBatchSize : BatchSize;

                using (var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize, DocumentsStartEtag, HasCompression, Encryption, JournalsPath, IsRavendbFs))
                {
                    if (IsRavendbFs)
                    {
                        storageExporter.ExportFilesystemAsAttachments();
                    }
                    else
                    {
                        storageExporter.ExportDatabase();
                    }
                }
            }
        }
Exemple #4
0
 public void Export()
 {
     if (TableName != null)
     {
         using (var esentExportOperation = new EsentExportOperation(DatabaseDataDir))
         {
             esentExportOperation.ExportTable(TableName, OutputDumpPath);
         }
     }
     else
     {
         int batchSize = BatchSize == 0 ? DefualtBatchSize : BatchSize;
         var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize);
         storageExporter.ExportDatabase();
     }
 }
Exemple #5
0
 public void Export()
 {
     if (TableName != null)
     {
         using (var esentExportOperation = new EsentExportOperation(DatabaseDataDir, HasCompression, Encryption))
         {
             esentExportOperation.ExportTable(TableName, OutputDumpPath);
         }
     }
     else
     {
         int batchSize       = BatchSize == 0 ? DefaultBatchSize : BatchSize;
         var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize, DocumentsStartEtag, HasCompression, Encryption);
         storageExporter.ExportDatabase();
     }
 }
 public void Export()
 {
     if (TableName != null)
     {
         using (var esentExportOperation = new EsentExportOperation(DatabaseDataDir))
         {
             esentExportOperation.ExportTable(TableName, OutputDumpPath);
         }
     }
     else
     {
         int batchSize       = BatchSize == 0 ? DefualtBatchSize : BatchSize;
         var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize);
         storageExporter.ExportDatabase();
     }
 }
 public void Export()
 {
     if (TableName != null)
     {
         using (var esentExportOperation = new EsentExportOperation(DatabaseDataDir, HasCompression, Encryption))
         {
             esentExportOperation.ExportTable(TableName, OutputDumpPath);
         }
     }
     else
     {
         int batchSize = BatchSize == 0 ? DefaultBatchSize : BatchSize;
         var storageExporter = new StorageExporter(DatabaseDataDir, OutputDumpPath, batchSize, DocumentsStartEtag, HasCompression, Encryption);
         storageExporter.ExportDatabase();
     }
 }
Exemple #8
0
        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]))
            {
                ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Directory {0} does not exists.\n", args[0]);
                return(false);
            }
            if (!StorageExporter.ValidateStorageExsist(args[0]))
            {
                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))
            {
                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))
            {
                ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "You don't have premissions to write to {0}.\n", args[1]);
            }
            if (args.Length % 2 != 0)
            {
                ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Wrong amount of arguments were passed.\n");
                return(false);
            }
            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;

                default:
                    ConsoleUtils.ConsoleWriteLineWithColor(ConsoleColor.Red, "Unidentified argument {0}.\n");
                    break;
                }
            }
            return(true);
        }
Exemple #9
0
        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);
        }