2012-02-06 15 views
4

我在RavenDB網站上閱讀Backup and Restore文檔,並在我的代碼中嘗試過。如何將DocumentDatabase.StartBackup()與RavenDB EmbeddableDocumentStore結合使用?

在DOC我們:

Initiating a backup

When running in embedded mode, all you need is to call the method DocumentDatabase.StartBackup().

的上面的一行代碼就不會出現錯誤編譯:

An object reference is required for the non-static field, method, or property 
'Raven.Database.DocumentDatabase.StartBackup(string, bool)' 

所以,我想這只是測試:

new DocumentDatabase(_documentStore.Configuration). 
               StartBackup(@"~\App_Data\Backup", true); 

代碼編譯,但當應用程序啓動時,我得到這個錯誤:

Could not open transactional storage: C:\Project\trunk\MyApp\App_Data\Database\Data 

有人可以分享一些工作代碼,有關如何做一個在線嵌入式文檔商店的完整備份?如果不使用RavenDB服務器,甚至可能嗎?

我唯一的選擇是做數據庫文件夾的手動備份?

回答

4

Leniel, 您需要使用StartBackup方法您正在運行的實際實例。 如果您正在使用EmbeddableDocumentStore,您需要:

embeddableDocumentStore.DocumentDatabase.StartBackup(...); 
+1

哦,我明白了。現在我知道我做錯了什麼。我將嵌入式文檔存儲變量聲明爲「private static IDocumentStore _documentStore;'。然後我試圖找到DocumentDatabase成員,但我找不到它。我很害怕... hehehe將它更改爲'private static EmbeddableDocumentStore _documentStore;'它就在那裏。再次感謝Ayende ......你是那個人! :-) – 2012-02-06 14:33:24

+0

只需跟進Ayende:我應該在哪裏調用StartBackup()?我把它放在'_documentStore.Initialize();'之後,只是爲了測試,它創建了Backup文件夾,但它只包含2個文件夾:IndexDefinitions和Index。數據沒有備份... – 2012-02-06 14:45:57

+0

有趣的一段時間後,我看到它只是創建了一個名爲新文件夾與3個文件:Data,Data.pat和RVN00002.log。我是否需要在發生故障時恢復數據庫? :) – 2012-02-06 15:04:06

相關問題