Docker下如何导入导出neo4j数据

[摘要] 运行在Docker容器中的neo4j数据库,如何使用 neo4j-admin restore|dump 进行导入导出操作?

neo4j 官方文档有说明,使用 neo4j-admin restore / dump 导出和恢复数据库的时候需要停掉数据,否则会报数据库正在使用的错误:
command failed: the database is in use — stop Neo4j and try again

官方文档这样说:
Restore the database graph.db from the backup located in /mnt/backup/graph.db-backup. Note that the database to be restored must be shut down.

neo4j-home> bin/neo4j stop
neo4j-home> bin/neo4j-admin restore --from=/mnt/backup/graph.db-backup --database=graph.db --force
neo4j-home> bin/neo4j start

但是问题来了,容器里面entrypoint默认是启动的neo4j的进程:

# ps aux|grep neo4j
1 root      0:01 /sbin/tini -g -- /docker-entrypoint.sh neo4j
7 neo4j     3:16 /usr/lib/jvm/java-1.8-openjdk/jre/bin/java -cp /var/lib/neo4j/plugins:/var/lib/neo4j/conf:/var/lib/neo4j/lib/*:/var/lib/neo4j/plugins/* -server -Xms512M -Xmx512M -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -XX:+DisableExplicitGC -Djdk.tls.ephemeralDHKeySize=2048 -Djdk.tls.rejectClientInitiatedRenegotiation=true -Dunsupported.dbms.udc.source=tarball -Dfile.encoding=UTF-8 org.neo4j.server.CommunityEntryPoint --home-dir=/var/lib/neo4j --config-dir=/var/lib/neo4j/conf

现在进入容器shudown的话,neo4j容器会停掉(docker-run)或者重启数据库(docker-compose),所以这里采用的迂回的方法:

(1)停掉neo4j容器

docker stop neo4j-container

(2)使用docker run启动一个带有TTY新的容器,如果使用了数据持久化,需要使用-v参数带上volume

docker run \
-v /data/deploy/nlpdemo/neo4j-data-persistence:/data \
--name neo4j-container-dump \
-it \
neo4j /bin/bash

(3)导入或者导出数据库

#dump
neo4j-admin dump --database=graph.db --to=/backups/graph.db/2019-01-10.dump

#restore
neo4j-admin load --from=/backups/graph.db/2019-01-10.dump --database=graph.db --force

(4)关闭临时容器,重启原容器

u2

Related Posts

rancher v2.x 初体验

rancher v2x

Read more

sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached

Python3 + Flask + mysql5.7搭建的w…

Read more

You Missed

本地AI时代来临:Ollama + MemPalace工作流深度指南

  • u2
  • 4月 21, 2026
  • 37 views

Raycast深度解析:这个让Mac效率重装升级的东西,到底值不值?

  • u2
  • 4月 14, 2026
  • 64 views

GitHub 25K+星标!Onyx:开源可自托管的企业级AI聊天与RAG平台

  • u2
  • 4月 8, 2026
  • 157 views

InternVL-U 统一多模态模型

  • u2
  • 4月 3, 2026
  • 138 views
InternVL-U 统一多模态模型

Everything Claude Code:开源 Agent 性能优化框架

  • u2
  • 3月 31, 2026
  • 174 views

MiroFish:群体智能预测引擎,让未来在数字沙盘中预演

  • u2
  • 3月 29, 2026
  • 244 views