neo4j数据提供了备份数据的多种方法,可以参考官方文档
我最喜欢的是使用apoc备份为json文件的方式:
具体命令为
CALL apoc.export.json.all("all.json",{useTypes:true});
可能的报错
第一次执行可能会遭遇如下报错:
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke procedure `apoc.export.json.all`: Caused by: java.lang.RuntimeException: Export to files not enabled, please set apoc.export.file.enabled=true in your apoc.conf.
Otherwise, if you are running in a cloud environment without filesystem access, use the `{stream:true}` config and null as a 'file' parameter to stream the export back to your client.
这种情况下你需要到neo4j安装位置的config目录下创建一个apoc.conf
文件,并在其中添加apoc.export.file.enabled=true
重启neo4j服务.\bin\neo4j.bat restart
,再次执行备份命令即可。备份文件默认位于 import
目录下。
使用命令备份
备份命令
.\neo4j-admin database dump neo4j --to-path=.\import
恢复命令
.\neo4j-admin database load --from-path=.\import neo4j
注意,这种方式做迁移的化需要保持neo4j版本一致,否则会报如下错误:
Failed to load database ‘xxx’: The loaded database ‘xxx’ is of a newer version than the current binaries. Downgrade is not supported.
注意,这种方式只支持离线迁移,即执行命令前需要停用当前库
感觉有点呆
Reference
https://neo4j.com/docs/operations-manual/current/backup-restore/
https://neo4j.com/docs/apoc/current/export/json/
https://community.neo4j.com/t/how-to-set-apoc-import-file-enable-true/34726/3