Neo4j 简明教程

Neo4j - Backup & Restore

在实时应用程序中,我们应该定期备份我们的应用程序数据库,这样我们可以在任何故障时恢复到工作状态。

In real-time applications, we should take backup of our application database regularly, so that we can restore to some working condition at any failure point.

此规则适用于 RDBMS 和 NoSQL 数据库。

This rule is applicable for both RDBMS and NoSQL databases.

在本节中,我们将讨论两项重要的 DBA 任务。

In this section, we are going to discuss about two important DBA tasks.

  1. How to back up a Neo4j Database.

  2. How to restore Neo4j Database to a specific backup.

Note - 这些步骤仅适用于 Windows 操作系统。我们应该使用类似的命令在其他操作系统中执行相同的步骤。

Note − These steps are applicable to Windows Operating System only. We should use similar kind of commands to do the same steps in other operating systems.

Neo4j Database Backup

Step 1 - 使用以下路径单击“Neo4j Community” -

Step 1 − Click "Neo4j Community" using the following path −

Windows “开始”按钮 → “所有程序” → “Neo4j Community” → “Neo4j Community”

Windows "Start" button → "All Programs" → "Neo4j Community" → "Neo4j Community"

默认情况下,它会选择 c:\Users\[username]\Documents\Neo4j\default.graphdb. 但如果我们愿意,我们可以将路径更改为不同的目录。

By default, it selects c:\Users\[username]\Documents\Neo4j\default.graphdb. However if we wish to, we can change the path to a different directory.

Step 2 - 在这里我们已经更改为我们的 Neo4j 数据库文件夹。

Step 2 − Here we have changed to our Neo4j Database folder.

C:\Ne04j2.0db

community setting

Step 3 - 点击“开始”按钮。

Step 3 − Click the "Start" button.

browse stop

服务器启动后,我们可以观察我们的 Neo4j 数据库文件是在指定目录中生成的。

Once the server starts, we can observe our Neo4j Database files are generated at a specified directory.

observe directory

在进行数据库备份之前,我们应该做的第一件也是最重要的事情是关闭 Neo4j 数据库服务器。

Before taking a database backup, the first and foremost thing we should do is shutdown the Neo4j Database server.

Step 4 - 点击“停止”按钮关闭服务器。

Step 4 − Click the "Stop" button to shut down the server.

community setting

Neo4j 数据库文件可在 C:\Ne04j2.0db 中找到。

Neo4j Database files are available at C:\Ne04j2.0db

observe directory

Step 5 - 打开命令提示符。

Step 5 − Open the command prompt.

command prompt

Step 6 − 在 C:\Neo4j 创建一个“Neo4jDbBackup-01”文件夹(此文件夹可以存在于文件系统中的任何位置)。

Step 6 − Create a folder "Neo4jDbBackup-01" at C:\Neo4j (This may be any location in your file system).

mkdir C:\Neo4j\Neo4jDbBackup-01
cmd mkdir

它会在指定的“C:\Neo4j\”文件系统位置创建新的“Neo4jDbBackup-01”文件夹。

It creates a new folder "Neo4jDbBackup-01" at the specified file system location "C:\Neo4j\"

new directory

Step 7 − 键入以下命令并按 Enter 键。

Step 7 − Type the following command and press Enter key.

copy C:\Ne04j2.0db C:\Neo4j\Neo4jDbBackup-01
backup command
copied statements

这意味着我们的文件已复制到所需的目标文件夹。访问该文件夹,并查看该文件夹是否包含我们的数据库文件。

This means our files are copied to the required destination folder. Access that folder and observe that the folder has our database files.

database files

Step 8 − 使用任何 Windows 压缩/解压工具,例如 WinZip、7 Zip 或 WinRAR 来压缩我们的数据库文件夹。

Step 8 − Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRAR to zip our Database folder.

zip folder

Step 9 − 现在已创建我们的 Neo4jDbBackup-01.zip 文件。如果文件系统中存在任何内存限制,请删除“C:\Neo4j\”中的“Neo4jDbBackup-01”文件夹。

Step 9 − Now our Neo4jDbBackup-01.zip file is created. If you have any memory constraints in your file system, then remove "Neo4jDbBackup-01" folder at "C:\Neo4j\"

memory constraint

Neo4j Database Restore

Step 1 − 关闭数据库服务器。请参阅前面的步骤以关闭服务器。

Step 1 − Shutdown the database server. Please refer to the previous steps to shut down the server.

community setting

Step 2 − 清空当前数据库文件夹。

Step 2 − Empty the current database folder.

current database

Step 3 − 使用任何 Windows 压缩/解压工具,例如 WinZip、7 Zip 或 WinRar 来解压我们的备份文件夹。

Step 3 − Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRar to unzip our backup folder.

extracting files

Step 4 − 打开命令提示符并执行以下命令。

Step 4 − Open the command prompt and execute the following command.

Copy C:\Neo4j\Neo4jDbBackup-01 C:\Ne04j2.0db
execute

现在我们可以看到我们的数据库文件夹包含正常工作的备份文件。

Now we can observe that our database folder contains working backup files

Step 5 − 通过单击“开始”按钮启动服务器。

Step 5 − Start the server by clicking the "Start" button.

community setting
browse stop

Step 6 − 执行一些 MATCH + RETURN 命令以验证是否已正确还原了数据库。

Step 6 − Execute some MATCH + RETURN commands to verify whether we have restored our database properly.