biofractal
biofractal

Reputation: 19153

RavenDB Backup: Checking the status using the HTTP API [/Raven/Backup/Status] Fails

I have successfully issued a Start-Backup request to my local RavenDB using an asynchronous HTTP WebRequest (C#). I can see the the backup files are being created in the backup-location I specified. This is good.

The Start-Backup call is asynchronous so I need some way to determine when the backup process is complete. Fortunately the RavenDB docs state:

You can check the status of the backup by querying the document with the key: "Raven/Backup/Status". The backup is completed when the IsRunning field in the document is set to false.

RavenDB Documentation

Can somebody please show me how to do this check?

I have tried issuing another HTTP request but it always returns with an status [400-Bad Request]. I would be happy to actually query the database using code for this doc but I do not know the type of the 'status document' so cannot call any generic db.Query<>() method and honestly, I am not sure how to query using a 'key'.

Here is the code I am using so far.

private void StartBackup(string backupLocation)
{
    var requestUri = new UriBuilder(Default.RavenUri){Path ="/admin/backup"};
    var formData = "{ 'BackupLocation': '" + backupLocation + "' }";
    var request = GetRequest(requestUri.Uri, formData);
    request.BeginGetResponse(asynchResult => CheckStatus(), null);

}

private void CheckStatus()
{
    var requestUri = new UriBuilder(Default.RavenUri){Path = "/Raven/Backup/Status"};
    var request = GetRequest(requestUri.Uri);
    var response = request.GetResponse();

}

private WebRequest GetRequest(Uri uri, string formData = null)
{
    var request = WebRequest.Create(uri);
    request.UseDefaultCredentials = true;
    request.PreAuthenticate = true;
    request.Credentials = CredentialCache.DefaultCredentials;

    if (formData == null)
    {
        request.Method = "GET";
        request.ContentLength = 0;
        return request;

    }

    request.Method = "POST";
    var data = Encoding.UTF8.GetBytes(formData);
    request.ContentLength = data.Length;
    request.ContentType = "application/x-www-form-urlencoded";
    using (var dataStream = request.GetRequestStream())
    {
        dataStream.Write(data, 0, data.Length);
    }
    return request;
}

Upvotes: 1

Views: 740

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

The Raven/Backup/Status is a document, not an endpoint, if you want to just grab the data over the wire, use:

 GET docs/Raven/Backup/Status

And it will work.

But you can also just use Raven.Backup.exe to do so.

Upvotes: 2

Related Questions