Question

I'm trying to setup PeriodicBackups for an existing database from code. The PeriodicBackups bundle has been enabled in the web.config.

I'm currently using this code:

            using (var session = systemStore.OpenSession())
            {
                var databaseDocument = session.Load<DatabaseDocument>("Raven/Databases/MyDatabase");
                if (databaseDocument != null)
                {
                    databaseDocument.Settings.Add("Raven/AzureStorageAccount", "MyStorageAccount");                        
                    databaseDocument.SecuredSettings.Add("Raven/AzureStorageKey", "abc123");
                    session.SaveChanges();
                }
            }

This results in the following settings for the database "MyDatabase":

{
  "Id": "MyDatabase",
  "Settings": {
    "Raven/DataDir": "~\\Databases\\MyDatabase",
    "Raven/AzureStorageAccount": "MyStorageAccount"
  },
  "SecuredSettings": {
    "Raven/AzureStorageKey": "<data could not be decrypted>"
  },
  "Disabled": false
}

And PeriodicBackups naturally don't work. I guess it's probably because of the AzureStorageKey that can't be decrypted. Am I supposed to encrypt the values I write to SecuredSettings myself? and if so, then how do I do that?

Was it helpful?

Solution

You cannot directly write to the sys docs in this manner when you have secure settings. You need to use the store.DatabaseCommands.Admin.CreateDatabase() method, which knows how to handle this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top