从neo4j docker中的备份创建neo4j数据库 [英] Create neo4j databse from backup inside neo4j docker

查看:196
本文介绍了从neo4j docker中的备份创建neo4j数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Neo4j对我来说是新的.我有neo4j数据库的备份,我想通过使用该备份创建数据库来构建docker容器.

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.

我知道我可以使用neo4j-admin restore --from=<backup-directory> [--database=<name>] [--force[=<true|false>]]命令,但是我正在寻找Docker容器在创建容器时可以用来重新创建数据库的东西.

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.

neo4j docker映像的文档使用容器内的现有数据库数据库.但是我需要还原备份并从中创建数据库.

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.

推荐答案

EXTENSION_SCRIPT官方图片挂钩

Neo4j的官方映像提供了一个挂钩,因此您可以在启动时加载数据.为此,您必须在运行时定义一个名为EXTENSION_SCRIPT的环境变量,该变量指向要运行的数据库还原脚本(请参见

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/).

以下是使用docker-compose的示例(也可以使用Dockerfile完成):

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

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

#!/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

这篇关于从neo4j docker中的备份创建neo4j数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆