RavenDB Import / Export failing on Server but working on Embedded

400 views Asked by At

I am looking at writing an import / export routine for RavenDB so that I can develop on a full server instance locally but can run embedded on the website due to resource contraints. I want to be able to admin functions in a locked down section of the site to allow for backups and restores from files. But I also want to be able to restore a production data set into a local server instance for debugging and development purposes.

As part of this I have been investigating using v2.5.2750 the ISmugglerApi interface and specifically the Raven.Database.Smuggler.DataDumper and the Raven.Smuggler.SmugglerApi implementations.

I can backup and restore using an Embedded instance fine. I can backup the server instance fine and import this file into the Embedded instance. However restoring into the Server database is where the issue occurs.

The code which I am using is as follows:

Restore code:

        SmugglerOptions smugglerOptions = new SmugglerOptions { BackupPath = Server.MapPath(ServerMapPath) };
        switch (Context)
        {
            case Context.Embedded:
                DataDumper dumper = new DataDumper(((EmbeddableDocumentStore)MvcApplication.Store).DocumentDatabase, smugglerOptions);
                var embeddedImport = dumper.ImportData(smugglerOptions);
                await embeddedImport;
                break;

            case Context.Server:
                var connectionStringOptions = new RavenConnectionStringOptions
                {
                    ApiKey = Configuration.ApiKey,
                    DefaultDatabase = Configuration.DefaultDatabase,
                    Url = Configuration.DefaultUrl
                };

                var smugglerApi = new SmugglerApi(smugglerOptions, connectionStringOptions);
                var serverImport = smugglerApi.ImportData(smugglerOptions);
                await serverImport;
                break;
        }

Backup code:

        SmugglerOptions smugglerOptions = new SmugglerOptions { BackupPath = Server.MapPath(ServerMapPath) };
        switch (Context)
        {
            case Context.Embedded:
                DataDumper dumper = new DataDumper(((EmbeddableDocumentStore)MvcApplication.Store).DocumentDatabase, smugglerOptions);
                var embeddedExport = dumper.ExportData(null, smugglerOptions, false);
                await embeddedExport;
                break;

            case Context.Server:
                var connectionStringOptions = new RavenConnectionStringOptions
                {
                    ApiKey = Configuration.ApiKey,
                    DefaultDatabase = Configuration.DefaultDatabase,
                    Url = Configuration.DefaultUrl
                };

                var smugglerApi = new SmugglerApi(smugglerOptions, connectionStringOptions);
                var serverExport = smugglerApi.ExportData(null, smugglerOptions, false);
                await serverExport;
                break;
        }

ServerMapPath is currently a const string for the name of the file which is in the App_Data folder.

The Configuration.* is a simple static class to read out the values from the web.config for the required settings.

Context is a configuration option to specify the type of environment which this is running in.

When I run the restore into the Server database configuration I get the following:

The remote server returned an error: (400) Bad Request.

[WebException: The remote server returned an error: (400) Bad Request.] System.Net.HttpWebRequest.GetResponse() +6592536
Raven.Client.Connection.HttpJsonRequest.ReadJsonInternal(Func`1 getResponse) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:349

[InvalidOperationException:

Could not figure out what to do

Your request didn't match anything that Raven knows to do, sorry...

]
Raven.Client.Connection.HttpJsonRequest.HandleErrors(WebException e) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:513 Raven.Client.Connection.HttpJsonRequest.ReadJsonInternal(Func`1 getResponse) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:355 Raven.Client.Connection.HttpJsonRequest.ReadResponseJson() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\HttpJsonRequest.cs:239 Raven.Client.Document.RemoteBulkInsertOperation.GetAuthToken() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\RemoteBulkInsertOperation.cs:151 Raven.Client.Document.d_b.MoveNext() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\RemoteBulkInsertOperation.cs:0 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Raven.Client.Document.d
_3.MoveNext() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\RemoteBulkInsertOperation.cs:100 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 Raven.Client.Document.d__18.MoveNext() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\RemoteBulkInsertOperation.cs:281

[AggregateException: One or more errors occurred.]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +83
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) +71 Raven.Smuggler.d_6.MoveNext() in c:\Builds\RavenDB-Stable\Raven.Smuggler\SmugglerApi.cs:87
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 Raven.Abstractions.Smuggler.d
_26.MoveNext() in c:\Builds\RavenDB-Stable\Raven.Abstractions\Smuggler\SmugglerApiBase.cs:322 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 SampleApplication.Controllers.d__15.MoveNext() in c:\Src\Random\RavenImportExport\SampleApplication\Controllers\HomeController.cs:105 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 lambda_method(Closure , Task ) +23
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +33 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +68
System.Web.Mvc.Async.<>c_DisplayClass34.b_33(IAsyncResult asyncResult) +16
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.b_3c() +50 System.Web.Mvc.Async.<>c_DisplayClass45.b_3e() +225 System.Web.Mvc.Async.<>c_DisplayClass30.b_2f(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c
_DisplayClass28.b_19() +26 System.Web.Mvc.Async.<>c_DisplayClass1e.b_1b(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.b
_1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +54
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.b_15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +54
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.b
_4(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +54
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129

What am I doing wrong?

0

There are 0 answers