title: How to recover a corrupt Neo4j Graph Database
body: <p>I am currently using spring data neo4j 2.1.0 (community edition).</p>
  
  <p>Occasionally I manage either to corrupt the database and/or database indexes.</p>
  
  <p>I have gathered the following recovery step but would like to have a
  more definitive set for future use.</p>
  
  <p>To recover a corrupt database.
  I currently delete the following files in the database data directory
  this process alone seems to work 90% of the time:</p>
  
  <p>nioneo_logical.log.v* (wildcard for numbers)</p>
  
  <p>nioneo_logical.log.active</p>
  
  <p>I would like to know if any other files can be removed from the data 
  directory to aid recovery and especially if any of the files in the data\index directory
  can be removed (without the necessity to rebuild indexes).</p>
  
  <p>Help much appreciated.</p>
  
  <p>messages.log</p>
  
  <pre><code>2013-12-16 10:41:40,516 ERROR [neo4j.index]: Failed to load index provider lucene
  org.neo4j.graphdb.NotFoundException: Target file[lucene.log.v3] already exists
      at org.neo4j.kernel.impl.util.FileUtils.renameFile(FileUtils.java:192) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.DefaultFileSystemAbstraction.renameFile(DefaultFileSystemAbstraction.java:77) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog.renameLogFileToRightVersion(XaLogicalLog.java:683) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog.renameIfExists(XaLogicalLog.java:181) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog.open(XaLogicalLog.java:150) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.impl.transaction.xaframework.XaContainer.openLogicalLog(XaContainer.java:64) ~[neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.index.impl.lucene.LuceneDataSource.&lt;init&gt;(LuceneDataSource.java:232) ~[neo4j-lucene-index-1.8.jar:1.8]
      at org.neo4j.index.lucene.LuceneIndexProvider.load(LuceneIndexProvider.java:72) ~[neo4j-lucene-index-1.8.jar:1.8]
      at org.neo4j.kernel.InternalAbstractGraphDatabase$DefaultKernelExtensionLoader.loadIndexImplementations(InternalAbstractGraphDatabase.java:1171) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.InternalAbstractGraphDatabase$DefaultKernelExtensionLoader.init(InternalAbstractGraphDatabase.java:1143) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:382) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:82) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:116) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:227) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.EmbeddedGraphDatabase.&lt;init&gt;(EmbeddedGraphDatabase.java:79) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.EmbeddedGraphDatabase.&lt;init&gt;(EmbeddedGraphDatabase.java:70) [neo4j-kernel-1.8.jar:1.8]
      at org.neo4j.kernel.EmbeddedGraphDatabase.&lt;init&gt;(EmbeddedGraphDatabase.java:55) [neo4j-kernel-1.8.jar:1.8]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.6.0_27]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [na:1.6.0_27]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [na:1.6.0_27]
      at java.lang.reflect.Constructor.newInstance(Unknown Source) [na:1.6.0_27]
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:108) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1002) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:906) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:484) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:353) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:982) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:878) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:734) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:665) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:518) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:319) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:833) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) [spring-beans-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [spring-context-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [spring-context-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.context.support.FileSystemXmlApplicationContext.&lt;init&gt;(FileSystemXmlApplicationContext.java:140) [spring-context-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at org.springframework.context.support.FileSystemXmlApplicationContext.&lt;init&gt;(FileSystemXmlApplicationContext.java:84) [spring-context-3.0.7.RELEASE.jar:3.0.7.RELEASE]
      at com.ci.server.ContextManager.initSinkServer(ContextManager.java:120) [CiDataConverter-0.0.1-SNAPSHOT.jar:na]
      at com.ci.server.Server.buildContext(Server.java:263) [CiDataConverter-0.0.1-SNAPSHOT.jar:na]
      at com.ci.server.Server.runServer(Server.java:76) [CiDataConverter-0.0.1-SNAPSHOT.jar:na]
      at com.ci.server.ServerMain.main(ServerMain.java:21) [CiDataConverter-0.0.1-SNAPSHOT.jar:na]
  2013-12-16 10:41:40,524 DEBUG [neo4j.diagnostics]: --- SHUTDOWN diagnostics START ---
  2013-12-16 10:41:40,524 DEBUG [neo4j.diagnostics]: --- SHUTDOWN diagnostics END ---
  </code></pre>
  
  <p>My Application Log file</p>
  
  <pre><code>SEVERE: Error initialising Neo4J context: 
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ciFinDomainServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private GelatoData.domainFinService.impl.FinancialRepository GelatoData.domainFinService.impl.CiFinDomainServiceImpl.financialRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.config.Neo4jConfiguration#0': Cannot resolve reference to bean 'graphDatabaseService' while setting bean property 'graphDatabaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDatabaseService' defined in file [C:\app\Gelato\server\etc\GelatoServerData.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.neo4j.kernel.EmbeddedGraphDatabase]: Constructor threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Target file[nioneo_logical.log.v2] already exists
  Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'mappingInfrastructure': Requested bean is currently in creation: Is there an unresolvable circular reference?
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      at org.springframework.context.support.FileSystemXmlApplicationContext.&lt;init&gt;(FileSystemXmlApplicationContext.java:140)
      at org.springframework.context.support.FileSystemXmlApplicationContext.&lt;init&gt;(FileSystemXmlApplicationContext.java:84)
      at com.ci.server.ContextManager.initSinkServer(ContextManager.java:120)
      at com.ci.server.Server.buildContext(Server.java:263)
      at com.ci.server.Server.runServer(Server.java:76)
      at com.ci.server.ServerMain.main(ServerMain.java:21)
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private GelatoData.domainFinService.impl.FinancialRepository GelatoData.domainFinService.impl.CiFinDomainServiceImpl.financialRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.config.Neo4jConfiguration#0': Cannot resolve reference to bean 'graphDatabaseService' while setting bean property 'graphDatabaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphDatabaseService' defined in file [C:\app\Gelato\server\etc\GelatoServerData.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.neo4j.kernel.EmbeddedGraphDatabase]: Constructor threw exception; nested exception is org.neo4j.graphdb.NotFoundException: Target file[nioneo_logical.log.v2] already exists
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
      ... 16 more
  </code></pre>
  
  <p>Neo4j data directory contents</p>
  
  <pre><code> Volume in drive C is OS
   Volume Serial Number is 8861-7230
  
   Directory of C:\app_data\gelato\data
  
  16/12/2013  10:49    &lt;DIR&gt;          .
  16/12/2013  10:49    &lt;DIR&gt;          ..
  25/11/2013  13:12                11 active_tx_log
  16/12/2013  10:38    &lt;DIR&gt;          index
  25/11/2013  13:42             1,571 index.db
  25/11/2013  13:14                 0 lock
  16/12/2013  10:41           289,837 messages.log
  16/12/2013  10:41                54 neostore
  16/12/2013  10:41                 9 neostore.id
  10/12/2013  17:32            25,164 neostore.nodestore.db
  16/12/2013  10:41                 9 neostore.nodestore.db.id
  16/12/2013  10:41         5,535,000 neostore.propertystore.db
  25/11/2013  13:14               128 neostore.propertystore.db.arrays
  16/12/2013  10:41                 9 neostore.propertystore.db.arrays.id
  16/12/2013  10:41                 9 neostore.propertystore.db.id
  10/12/2013  17:32             1,044 neostore.propertystore.db.index
  16/12/2013  10:41                 9 neostore.propertystore.db.index.id
  10/12/2013  17:32             1,026 neostore.propertystore.db.index.keys
  16/12/2013  10:41                 9 neostore.propertystore.db.index.keys.id
  10/12/2013  17:32         3,379,456 neostore.propertystore.db.strings
  16/12/2013  10:41                 9 neostore.propertystore.db.strings.id
  10/12/2013  17:32         1,132,461 neostore.relationshipstore.db
  16/12/2013  10:41                 9 neostore.relationshipstore.db.id
  16/12/2013  10:41                10 neostore.relationshiptypestore.db
  16/12/2013  10:41                 9 neostore.relationshiptypestore.db.id
  10/12/2013  17:32               114 neostore.relationshiptypestore.db.names
  16/12/2013  10:41                 9 neostore.relationshiptypestore.db.names.id
  16/12/2013  10:42               612 nioneo_logical.log.2
  16/12/2013  10:41                 4 nioneo_logical.log.active
  10/12/2013  14:32           353,479 nioneo_logical.log.v0
  10/12/2013  17:32        14,659,211 nioneo_logical.log.v1
  10/12/2013  17:18        26,214,477 nioneo_logical.log.v2
  25/11/2013  13:12         2,022,220 rrd
  16/12/2013  10:40               176 tm_tx_log.1
                32 File(s)     53,616,145 bytes
                 3 Dir(s)  881,749,417,984 bytes free
  </code></pre>
  
  <p>Neo4j Index contents</p>
  
  <pre><code> Volume in drive C is OS
   Volume Serial Number is 8861-7230
  
   Directory of C:\app_data\gelato\data\index
  
  16/12/2013  10:49    &lt;DIR&gt;          .
  16/12/2013  10:49    &lt;DIR&gt;          ..
  16/12/2013  10:38    &lt;DIR&gt;          lucene
  16/12/2013  10:41                40 lucene-store.db
  16/12/2013  10:41                16 lucene.log.1
  16/12/2013  10:40                 4 lucene.log.active
  25/11/2013  13:13               382 lucene.log.v0
  25/11/2013  13:44        26,945,214 lucene.log.v1
  10/12/2013  17:32           392,983 lucene.log.v2
  10/12/2013  17:18        26,214,420 lucene.log.v3
  10/12/2013  17:18        26,214,553 lucene.log.v4
                 9 File(s)     79,767,612 bytes
                 3 Dir(s)  881,749,921,792 bytes free
  </code></pre>