I need to chain some operations in order to migrate unencrypted data to an encrypted database:
- backup a database (BackupOperation)
- delete the database (DeleteDatabasesOperation)
- create an encrypted database with the same name (CreateDatabaseOperation)
- importing the ravendump's data to the new database (RestoreBackupOperation)
Everything works fine exept for the RestoreBackupOperation, which gives me this error :
Raven.Client.Exceptions.RavenException: System.ArgumentException: Cannot restore data to an existing database named MyDatabaseName
So obviously the RestoreOperation also creates the database and it conflicts with the one created the step before. I could do it using the UI, but the problem is that I need to import the data for 250+ databases, so it needs to be scripted.
I did not find anything in RavenDB's documentation regarding the import of datas from a ravendump file programatically. Is there any way for this process to work?
Here's the code :
private static async Task RestoreDatabase(string tenantName, IDocumentStore store, string backupLocaltion)
{
var config = new RestoreBackupConfiguration
{
DatabaseName = tenantName,
BackupLocation = backupLocaltion
};
await store.Maintenance.Server.SendAsync(new RestoreBackupOperation(config));
}
It works as long as the database does not exist to begin with.
Turns out RevenDB offers a Smuggler object to do just that :
Using this operation I'm able to import data to the encrypted database