Create neo4j databse from backup inside neo4j docker

前端 未结 1 787
遥遥无期
遥遥无期 2020-12-30 15:28

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

相关标签:
1条回答
  • 2020-12-30 16:17

    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
    
    0 讨论(0)
提交回复
热议问题