Create neo4j databse from backup inside neo4j docker

喜欢而已 提交于 2019-12-18 12:37:49

问题


Neo4j is new to me. I have a backup of neo4j database and I would like to build a docker container by creating a database by using that backup.

I know I can use neo4j-admin restore --from=<backup-directory> [--database=<name>] [--force[=<true|false>]] command but am looking for something which a docker container would be able to use to recreate database when the container is created.

The documentation of the neo4j docker image uses an exiting database database inside container. But I need to restore a backup and create database from it.


回答1:


EXTENSION_SCRIPT official image hook

Neo4j's official image provides a hook so you can load data on startup. For that, you must define an environment variable named EXTENSION_SCRIPT at runtime, which points to your database restore script to run (See https://neo4j.com/developer/docker-23/).

Here is an example using docker-compose (this could also be done with a Dockerfile):

docker-compose.yml file :

version: '2'
services:
  neo4j:
    image: neo4j:3.2
    ports:
     - "7474:7474"
     - "7687:7687"
    environment:
     - EXTENSION_SCRIPT=/neo4j-data/neo4j-init.sh :
    volumes:
     - ./neo4j-data:/neo4j-data

Then, in your initialization script, you must restore the database once, the first time

neo4j-init.sh file :

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# do not run init script at each container strat but only at the first start
if [ ! -f /tmp/neo4j-import-done.flag ]; then
    /var/lib/neo4j/bin/neo4j-admin neo4j-admin restore --from=<backup-directory mount as a docker volume under /neo4j-data> [--database=<name>] [--force[=<true|false>]]
    touch /tmp/neo4j-import-done.flag
else
    echo "The import has already been made."
fi


来源:https://stackoverflow.com/questions/45166636/create-neo4j-databse-from-backup-inside-neo4j-docker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!