Neo4j数据进行备份、还原

一、neo4j备份方式

neo4j数据库的备份还原分为两种: offline 和 online。

Offline backup
- dump
Dump a database into a single-file archive.
- load
Load a database from an archive created with the dump command.

Online backup
- backup
Perform an online backup from a running Neo4j enterprise server.
- restore
Restore a backed up database.

二、offline backup

在对Neo4j数据进行备份、还原、迁移的操作时,首先要关闭neo4j;
cd %NEO4J_HOME%/bin
./neo4j stop
数据备份到文件
./neo4j-admin  dump --database=graph.db --to=/home/2018.dump
之后,进行数据还原,将生成的存储文件拷贝到另一个相同版本的环境中,
(测试中可以进行清空Neo4j库操作:match (n) detach delete n )
还原、迁移之前 ,关闭neo4j服务。操作同上;
数据导入:
./neo4j-admin load --from=/home/2016-10-02.dump --database=graph.db --force
重启服务:
./neo4j start

或者

bin/neo4j console

  • 验证数据
    load执行完后,需要验证下看是否正确。首先确认规模性统计数字一致。比如节点数、关系数等等。然后再用一些测试样例MATCH回来仔细核查确认。最好是能维护一个测试验证集,自动跑一遍。

如果数据有问题,可以到neo4j.conf文件中,查看dbms.allow_format_migration=true这行是否生效,使之生效。

三、online backup

1.1. Backup commands

A Neo4j database can be backed up in online mode, using the backup command of neo4j-admin.

Syntax

neo4j-admin backup --backup-dir=<backup-path> --name=<graph.db-backup>
                    [--from=<address>] [--protocol=<any|catchup|common>]
                    [--fallback-to-full[=<true|false>]]
                    [--pagecache=<pagecache>]
                    [--timeout=<timeout>]
                    [--check-consistency[=<true|false>]]
                    [--additional-config=<config-file-path>]
                    [--cc-graph[=<true|false>]]
                    [--cc-indexes[=<true|false>]]
                    [--cc-label-scan-store[=<true|false>]]
                    [--cc-property-owners[=<true|false>]]
                    [--cc-report-dir=<directory>]

Options

Option Default Description

--backup-dir

 
Directory to place backup in.


--name

 
Name of backup. If a backup with this name already exists an incremental backup will be attempted.


--from


localhost:6362


Host and port of Neo4j.


--protocol


any


Protocol over which to perform backup. If set to any, then catchup will be tried first. If that fails, then it will attempt to fall back to common. It is recommended to set this option explicitly. Set it to catchup for Causal Cluster backups, and to common for HA or single-instance backups. For more information, see Section 7.3.6, “Backup scenarios and examples”.


--fallback-to-full


true


If an incremental backup fails backup will move the old backup to <name>.err.<N> and fallback to a full backup instead.


--pagecache


8M


The size of the page cache to use for the backup process.


--timeout


20m


Timeout in the form <time>[ms|s|m|h], where the default unit is seconds. This is a debugging option that should only be used if instructed to by Neo4j Professional Services.


--check-consistency


true


If a consistency check should be made.


--additional-config

 
Configuration file to supply additional configuration in.


--cc-graph


true


Perform checks between nodes, relationships, properties, types and tokens.


--cc-indexes


true


Perform checks on indexes.


--cc-label-scan-store


true


Perform checks on the label scan store.


--cc-property-owners


false


Perform additional checks on property ownership. This check is very expensive in time and memory.


--cc-report-dir


.


Directory where consistency report will be written.

1.2. Full backups

A full backup is performed whenever there is no backup directory specified.

Example 7.1. Back up a database

In this example, set environment variables in order to control memory usage.

The page cache is defined by using the command line option --pagecache. Further, the HEAP_SIZE environment variable will specify the maximum heap size allocated to the backup.

Now you can perform a full backup:

$neo4j-home> export HEAP_SIZE=2G
$neo4j-home> mkdir /mnt/backup
$neo4j-home> bin/neo4j-admin backup --from=192.168.1.34 --backup-dir=/mnt/backup --name=graph.db-backup --pagecache=4G
Doing full backup...
2017-02-01 14:09:09.510+0000 INFO  [o.n.c.s.StoreCopyClient] Copying neostore.nodestore.db.labels
2017-02-01 14:09:09.537+0000 INFO  [o.n.c.s.StoreCopyClient] Copied neostore.nodestore.db.labels 8.00 kB
2017-02-01 14:09:09.538+0000 INFO  [o.n.c.s.StoreCopyClient] Copying neostore.nodestore.db
2017-02-01 14:09:09.540+0000 INFO  [o.n.c.s.StoreCopyClient] Copied neostore.nodestore.db 16.00 kB
...
...
...

If you do a directory listing of /mnt/backup you will now see that you have a backup of Neo4j called graph-db.backup.

1.3. Incremental backups

An incremental backup is performed whenever an existing backup directory is specified, and the transaction logs are present since the last backup. The backup command will then copy any new transactions from Neo4j and apply them to the backup. The result will be an updated backup that is consistent with the current server state.

The transaction log files should be rotated and pruned based on the provided configuration. For example, setting dbms.tx_log.rotation.retention_policy=3 files will keep backup transaction logs to 3 files. You can use the --additional-config parameter to override this configuration.

Example 7.2. Perform an incremental backup

This example assumes that you have performed a full backup as per the previous example. In the same way as before, make sure to control the memory usage.

To perform an incremental backup you need to specify the location of your previous backup:

$neo4j-home> export HEAP_SIZE=2G
$neo4j-home> bin/neo4j-admin backup --from=192.168.1.34 --backup-dir=/mnt/backup --name=graph.db-backup --fallback-to-full=true --check-consistency=true --pagecache=4G
Destination is not empty, doing incremental backup...
Backup complete.

The incremental backup will fail if the existing directory does not contain a valid backup and --fallback-to-full=false. It will also fail if the required transaction logs have been removed and --fallback-to-full=false. Setting --fallback-to-full=true is a safeguard which will result in a full backup in case an incremental backup cannot be performed.

It is important to note that --check-consistency is true by default. For a quicker incremental backup we can set this to --check-consistency=false and --fallback-to-full=false.

 
When copying outstanding transactions, the server needs access to the transaction logs.

These logs are maintained by Neo4j and are automatically removed after a period of time, based on the parameter dbms.tx_log.rotation.retention_policy.

When designing your backup strategy it is important to configure dbms.tx_log.rotation.retention_policy such that transaction logs are kept between incremental backups.

1.4. Exit codes

neo4j-admin backup will exit with different codes depending on success or error. In the case of error, this includes details of what error was encountered.

Table 7.4. Neo4j Admin backup exit codes
Code Description

0


Success.


1


Backup failed.


2


Backup succeeded but consistency check failed.


3


Backup succeeded but consistency check found inconsistencies.

Restore a backup

This section describes how to restore from a backup of a Neo4j database.

This section includes:

2.1. Restore commands

A Neo4j database can be restored using the restore command of neo4j-admin.

Syntax

neo4j-admin restore --from=<backup-directory> [--database=<name>] [--force[=<true|false>]]

Options

Option Default Description

--from

 
Path to backup to restore from.


--database


graph.db


Name of database.


--force


false


If an existing database should be replaced.

2.2. Restore a single database

To restore from a backup, follow these steps:

  1. If the database is running, shut it down.
  2. Run neo4j-admin restore.
  3. Start up the database.

Example 7.3. Restore a single database

Restore the database graph.db from the backup located in /mnt/backup/graph.db-backup. Note that the database to be restored must be shut down.

neo4j-home> bin/neo4j stop
neo4j-home> bin/neo4j-admin restore --from=/mnt/backup/graph.db-backup --database=graph.db --force
neo4j-home> bin/neo4j start

2.3. Restore a Causal Cluster

To restore from a backup in a Causal Cluster, follow these steps:

  1. Shut down all database instances in the cluster.
  2. Run the neo4j-admin unbind command on each of the Core Servers.
  3. Restore the backup on each instance, using neo4j-admin restore.
  4. If you are restoring onto new hardware, please review the Causal Clustering settings in neo4j.conf.

    In particular, check the settings causal_clustering.initial_discovery_members, causal_clustering.minimum_core_cluster_size_at_formation, and causal_clustering.minimum_core_cluster_size_at_runtime, and ensure that they correctly reflect the new setup.

  5. Start the database instances.

转载自:

https://blog.csdn.net/c1052981766/article/details/79530061

https://www.jianshu.com/p/9095e29974a6

https://neo4j.com/docs/operations-manual/current/backup/performing/

原文地址:https://www.cnblogs.com/xibuhaohao/p/11161942.html

时间: 2024-10-15 12:02:03

Neo4j数据进行备份、还原的相关文章

MySQL数据的备份还原及数据修复

在日常的生产环境中为什么要进行备份??备份可以使生产中的数据进行有效的灾难恢复:硬件故障.软件故障.自然灾害.误操作测试等数据丢失场景. 备份注意要点能容忍最多丢失多少数据恢复数据需要在多长时间内完成需要恢复哪些数据还原要点做还原测试,用于测试备份的可用性还原演练备份类型完全备份.不分备份完全备份:整个数据集部分备份:只备份数据子集,如部分库或表增量备份.差异备份增量备份:仅备份最近一次完全备份或增量备份(如果存在增量)以来变化的数据,备份较快,还原复杂差异备份:仅备份最近一次完全备份以来变化的

mysql innobackupex xtrabackup 大数据量 备份 还原(转)

原文:http://blog.51yip.com/mysql/1650.html 作者:海底苍鹰 大数据量备份与还原,始终是个难点.当MYSQL超10G,用mysqldump来导出就比较慢了.在这里推荐xtrabackup,这个工具比mysqldump要快很多. 一.Xtrabackup介绍 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtra

根据用户通过数据泵备份还原ORACLE数据库,

1.首先,解释几个词语 directory:一般创建directory都是为了用数据泵导入/导出数据用,其实directory还有很多别的用处,本文不做阐述 schemas:  你用“用户 user”来理解就很容易了,每个模式(user)下可以有一套互不干扰的对象.你如果想要访问其他模式的对象, 需要指定schema的name,实际就是指定username. 如,你要访问模式scott的表emp,而你所在的模式(用户)是tiger, 那你要这样写: select * from scott.emp

mysql数据的备份还原三种方法

MySQL的备份和恢复: 为什么要对数据做备份?    数据备份主要是用于灾难恢复和测试要求,灾难恢复指硬件故障,软件故障,自然灾害,黑客攻击以及误操作: 备份分为以下几类: 完全备份:既对所有数据做备份 部分备份:仅对数据库中一张或多张表做备份 差异备份:备份上次备份后变化的数据部分,和增量备份区别在于差异备份只可以相对完全备份做备份 增量备份:仅备份上次完全备份或增量备份之后变化的数据部分 热备份:在线备份,读写操作不受影响 温备份:在线备份,读操作继续,但写操作不允许: 冷备份:离线备份,

MSSQLDatabase 部分表的数据 批量备份 还原

情景:测试环境中数据库部分表新增数万条数据(数据通过检测)要导进生产机的数据库. 在测试环境导出数据(生成脚本)如下图选择要备份的表: 在设置脚本编写选项时注意: 由于生产环境已经有数据库 我这里选仅限数据足矣. 导出成功: 按正常套路就会把得到的**.sql复制到生产环境执行,打完收工的节奏.可惜MSSQL会提示数据过大没法一次执行! 我的解决办法是在cmd里面执行: sqlcmd -S "192.168.0.1" -U "databaseUser" -P &qu

手把手教你实现Java权限管理系统 前端篇(十六):系统备份还原

系统备份还原 在很多时候,我们需要系统数据进行备份还原.我们这里就使用MySql的备份还原命令实现系统备份还原的功能. 后台接口准备 系统备份还原是对数据库的备份还原,所以必须有后台接口的支持,我们准备好了接口,相关内容可以查阅后台篇. backup:系统备份创建接口,会在服务端_backup目录下生成以时间戳相关的备份目录,目录下有MySQL的备份SQL. delete:系统备份删除接口,传入页面查询得到的备份名称作为参数,删除服务端备份记录. findRecord:系统备份查询接口,查询所有

Mysql数据的备份与还原

数据的备份: 1:简单的数据备份(单表备份) 通过 select 语句,将查询到的数据,以文本文件的形式,存储起来! select 字段列表 into file 文件地址 from 表名 where 其他的 select 子句! select * into outfile 'e:/VIP/stu.txt' from select_student; 默认的字段之间的分隔符,使用制表符,而记录之间的分隔符,使用换行符! 但是,在数据存储时是可以被设置的! 例: select * into outfi

SQL Server 大数据搬迁之文件组备份还原实战

原文:SQL Server 大数据搬迁之文件组备份还原实战 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) 注意事项(Attention) 疑问(Questions) 参考文献(References) 二.背景(Contexts) 有一个数据库大概在700G左右,需要从服务器A搬迁到服务器B,两台服务器网络传输速度可以达到8MB/s,怎么做才能更

MySQL中使用innobackupex、xtrabackup进行大数据的备份和还原

大数据量备份与还原,始终是个难点.当MYSQL超10G,用mysqldump来导出就比较慢了.在这里推荐xtrabackup,这个工具比mysqldump要快很多. 本文还参考了:http://blog.chinaunix.net/uid-20682026-id-3319204.html xtrabackup备份恢复测试 一.Xtrabackup介绍 1.Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具I