迁移单实例

本章介绍了将单个实例直接从 Neo4j 3.5 迁移到 4.x 所需的步骤。

将单个实例从 Neo4j 3.5 迁移到 4.x 需要停机。因此,建议在类生产环境中进行测试迁移,以获取停机时间的相关信息。

先决条件

确保您已完成 迁移检查清单 上的所有任务。

准备迁移

  1. 确认您已关闭 Neo4j DBMS。您可以检查 neo4j.log 文件。

  2. 安装您想要迁移到的 Neo4j 版本。有关如何安装所用发行版的更多信息,请参阅 Operations Manual → Installation

  3. 使用您在 准备供新安装使用的全新 neo4j.conf 文件 一节中准备好的文件替换 neo4j.conf 文件。

  4. 复制所有用于加密的文件,例如私钥、公有证书,以及受信任和已吊销目录的内容(位于 <NEO4J_HOME>/certificates/ 中)。

    如果您的旧安装修改了以 dbms.directories.* 开头的配置或 dbms.active_database 设置,请确认新的 neo4j.conf 文件已正确配置以找到这些目录。

  5. 如果您使用自定义插件,请确保它们已更新并与新版本兼容,然后将它们放入 /plugins 目录中。

迁移数据

使用 4.0 Neo4j Admin 工具迁移您的 3.5 Neo4j 数据存储。neo4j-admin copy 命令还会删除任何不一致的节点、属性和关系,并且不会将它们复制到新创建的存储中。

  1. <NEO4J_HOME> 文件夹中,运行以下命令来复制数据存储。您需要指定旧存储的位置以及目标更新数据库的名称。

    bin/neo4j-admin copy --from-path=/path/to/3.5.x/graph.db --to-database=<db_name>
    Starting to copy store, output will be saved to:  $NEO4J_HOME/logs/neo4j-admin-copy-2020-11-26.16.07.19.log
    2020-11-26 16:07:19.939+0000 INFO [StoreCopy] ### Copy Data ###
    2020-11-26 16:07:19.940+0000 INFO [StoreCopy] Source: /path/to/3.5.x/graph.db (page cache 8m)
    2020-11-26 16:07:19.940+0000 INFO [StoreCopy] Target:  $NEO4J_HOME/data/databases/database (page cache 8m)
    2020-11-26 16:07:19.940+0000 INFO [StoreCopy] Empty database created, will start importing readable data from the source.
    2020-11-26 16:07:21.661+0000 INFO [o.n.i.b.ImportLogic] Import starting
    
    Import starting 2020-11-26 16:07:21.699+0000
      Estimated number of nodes: 50.00 k
      Estimated number of node properties: 50.00 k
      Estimated number of relationships: 0.00
      Estimated number of relationship properties: 50.00 k
      Estimated disk space usage: 2.680MiB
      Estimated required memory usage: 8.598MiB
    
    (1/4) Node import 2020-11-26 16:07:22.220+0000
      Estimated number of nodes: 50.00 k
      Estimated disk space usage: 1.698MiB
      Estimated required memory usage: 8.598MiB
    .......... .......... .......... .......... ..........   5% ∆239ms
    .......... .......... .......... .......... ..........  10% ∆1ms
    .......... .......... .......... .......... ..........  15% ∆1ms
    .......... .......... .......... .......... ..........  20% ∆0ms
    .......... .......... .......... .......... ..........  25% ∆1ms
    .......... .......... .......... .......... ..........  30% ∆0ms
    .......... .......... .......... .......... ..........  35% ∆0ms
    .......... .......... .......... .......... ..........  40% ∆1ms
    .......... .......... .......... .......... ..........  45% ∆0ms
    .......... .......... .......... .......... ..........  50% ∆1ms
    .......... .......... .......... .......... ..........  55% ∆0ms
    .......... .......... .......... .......... .........-  60% ∆51ms
    .......... .......... .......... .......... ..........  65% ∆0ms
    .......... .......... .......... .......... ..........  70% ∆0ms
    .......... .......... .......... .......... ..........  75% ∆1ms
    .......... .......... .......... .......... ..........  80% ∆0ms
    .......... .......... .......... .......... ..........  85% ∆0ms
    .......... .......... .......... .......... ..........  90% ∆1ms
    .......... .......... .......... .......... ..........  95% ∆0ms
    .......... .......... .......... .......... .......... 100% ∆0ms
    
    (2/4) Relationship import 2020-11-26 16:07:22.543+0000
      Estimated number of relationships: 0.00
      Estimated disk space usage: 1006KiB
      Estimated required memory usage: 15.60MiB
    (3/4) Relationship linking 2020-11-26 16:07:22.879+0000
      Estimated required memory usage: 7.969MiB
    (4/4) Post processing 2020-11-26 16:07:23.272+0000
      Estimated required memory usage: 7.969MiB
    -......... .......... .......... .......... ..........   5% ∆356ms
    .......... .......... .......... .......... ..........  10% ∆0ms
    .......... .......... .......... .......... ..........  15% ∆1ms
    .......... .......... .......... .......... ..........  20% ∆0ms
    .......... .......... .......... .......... ..........  25% ∆0ms
    .......... .......... .......... .......... ..........  30% ∆1ms
    .......... .......... .......... .......... ..........  35% ∆0ms
    .......... .......... .......... .......... ..........  40% ∆0ms
    .......... .......... .......... .......... ..........  45% ∆1ms
    .......... .......... .......... .......... ..........  50% ∆0ms
    .......... .......... .......... .......... ..........  55% ∆0ms
    .......... .......... .......... .......... ..........  60% ∆0ms
    .......... .......... .......... .......... ..........  65% ∆1ms
    .......... .......... .......... .......... ..........  70% ∆0ms
    .......... .......... .......... .......... ..........  75% ∆0ms
    .......... .......... .......... .......... ..........  80% ∆0ms
    .......... .......... .......... .......... ..........  85% ∆0ms
    .......... .......... .......... .......... ..........  90% ∆0ms
    .......... .......... .......... .......... ..........  95% ∆1ms
    .......... .......... .......... .......... .......... 100% ∆0ms
    
    
    IMPORT DONE in 2s 473ms.
    Imported:
      1 nodes
      0 relationships
      1 properties
    Peak memory usage: 15.60MiB
    2020-11-26 16:07:24.140+0000 INFO [o.n.i.b.ImportLogic] Import completed successfully, took 2s 473ms. Imported:
      1 nodes
      0 relationships
      1 properties
    2020-11-26 16:07:24.668+0000 INFO [StoreCopy] Import summary: Copying of 100704 records took 4 seconds (25176 rec/s). Unused Records 100703 (99%) Removed Records 0 (0%)
    2020-11-26 16:07:24.669+0000 INFO [StoreCopy] ### Extracting schema ###
    2020-11-26 16:07:24.669+0000 INFO [StoreCopy] Trying to extract schema...
    2020-11-26 16:07:24.920+0000 INFO [StoreCopy] ... found 1 schema definitions. The following can be used to recreate the schema:
    2020-11-26 16:07:24.922+0000 INFO [StoreCopy]
    
    CALL db.createIndex('index_5c0607ad', ['Person'], ['name'], 'native-btree-1.0', {`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.min`: [-1000000.0, -1000000.0],`spatial.wgs-84.min`: [-180.0, -90.0],`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian.max`: [1000000.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84.max`: [180.0, 90.0]})
    2020-11-26 16:07:24.923+0000 INFO [StoreCopy] You have to manually apply the above commands to the database when it is stared to recreate the indexes and constraints. The commands are saved to $NEO4J_HOME/logs/neo4j-admin-copy-2020-11-26.16.07.19.log as well for reference.

    使用直接路径时,索引不会自动迁移,因此您必须重新创建它们。运行存储迁移后,neo4j-admin copy 命令会提取模式并生成一系列命令,您可以使用这些命令在新的 4.x 存储上重建模式。重建模式的命令也会保存在位于 /logs 目录中的迁移日志文件中。

  2. 启动服务器。

    bin/neo4j start

    systemctl start neo4j

    复制数据库不会自动创建它。因此,如果您在 Cypher Shell 或 Neo4j Browser 中执行 SHOW DATABASES,它将不会显示。

  3. 登录到 Cypher® Shell 命令行控制台,将活动数据库更改为 system (:USE system;),然后创建 <db_name> 数据库。有关 Cypher Shell 命令行界面 (CLI) 及其使用方法的更多信息,请参阅 Operations Manual → Cypher Shell

    CREATE DATABASE <db_name>;
  4. 使用新数据库 (:USE <db_name>;),重建 neo4j-admin copy 命令识别出的任何索引或约束。

    CALL db.createIndex('index_5c0607ad', ['Person'], ['name'], 'native-btree-1.0', {`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.min`: [-1000000.0, -1000000.0],`spatial.wgs-84.min`: [-180.0, -90.0],`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian.max`: [1000000.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84.max`: [180.0, 90.0]});

迁移后任务

在迁移完成后立即进行完整备份是一种良好的做法。

© . This site is unofficial and not affiliated with Neo4j, Inc.