ONgDB集群数据备份恢复方案

 

Here’s the table of contents:

  1. 数据备份恢复
    1. 备份命令
    2. 修改集群配置
    3. 远程热备命令
    4. 数据恢复脚本
    5. 参考文档

数据备份恢复

现有三台ONgDB服务器,2-CORE,1-REPLICA。备份操作采用远程备份的方式,不在生产服务器备份。

备份命令

ongdb@ip-10-20-0-157:~/ongdb-enterprise-3.5.17$ ./bin/neo4j-admin backup
Missing argument 'backup-dir'
usage: neo4j-admin backup --backup-dir=<backup-path> --name=<graph.db-backup>
                          [--from=<address>] [--protocol=<any|catchup|common>]
                          [--fallback-to-full[=<true|false>]]
                          [--timeout=<timeout>] [--pagecache=<8m>]
                          [--check-consistency[=<true|false>]]
                          [--cc-report-dir=<directory>]
                          [--additional-config=<config-file-path>]
                          [--cc-graph[=<true|false>]]
                          [--cc-indexes[=<true|false>]]
                          [--cc-label-scan-store[=<true|false>]]
                          [--cc-property-owners[=<true|false>]]
environment variables:
    NEO4J_CONF    Path to directory which contains neo4j.conf.
    NEO4J_DEBUG   Set to anything to enable debug output.
    NEO4J_HOME    Neo4j home directory.
    HEAP_SIZE     Set JVM maximum heap size during command execution.
                  Takes a number and a unit, for example 512m.
Perform an online backup from a running Neo4j enterprise server. Neo4j's backup
service must have been configured on the server beforehand.
All consistency checks except 'cc-graph' can be quite expensive so it may be
useful to turn them off for very large databases. Increasing the heap size can
also be a good idea. See 'neo4j-admin help' for details.
For more information see:
https://neo4j.com/docs/operations-manual/current/backup/
options:
  --backup-dir=<backup-path>               Directory to place backup in.
  --name=<graph.db-backup>                 Name of backup. If a backup with this
                                           name already exists an incremental
                                           backup will be attempted.
  --from=<address>                         Host and port of Neo4j.
                                           [default:localhost:6362]
  --protocol=<any|catchup|common>          Preferred backup protocol
                                           [default:any]
  --fallback-to-full=<true|false>          If an incremental backup fails backup
                                           will move the old backup to
                                           <name>.err.<N> and fallback to a full
                                           backup instead. [default:true]
  --timeout=<timeout>                      Timeout in the form <time>[ms|s|m|h],
                                           where the default unit is seconds.
                                           [default:20m]
  --pagecache=<8m>                         The size of the page cache to use for
                                           the backup process. [default:8m]
  --check-consistency=<true|false>         If a consistency check should be
                                           made. [default:true]
  --cc-report-dir=<directory>              Directory where consistency report
                                           will be written. [default:.]
  --additional-config=<config-file-path>   Configuration file to supply
                                           additional configuration in. This
                                           argument is DEPRECATED. [default:]
  --cc-graph=<true|false>                  Perform consistency checks between
                                           nodes, relationships, properties,
                                           types and tokens. [default:true]
  --cc-indexes=<true|false>                Perform consistency checks on
                                           indexes. [default:true]
  --cc-label-scan-store=<true|false>       Perform consistency checks on the
                                           label scan store. [default:true]
  --cc-property-owners=<true|false>        Perform additional consistency checks
                                           on property ownership. This check is
                                           *very* expensive in time and memory.
                                           [default:false]

修改集群配置

# Enable online backups to be taken from this database.
dbms.backup.enabled=true
# By default the backup service will only listen on localhost.
# To enable remote backups you will have to bind to an external
# network interface (e.g. 0.0.0.0 for all interfaces).
# The protocol running varies depending on deployment. In a Causal Clustering environment this is the
# same protocol that runs on causal_clustering.transaction_listen_address.
dbms.backup.address=0.0.0.0:6362
causal_clustering.transaction_listen_address=:6000

远程热备命令

每周从集群备份数据

#!/usr/bin/env bash
###################  backup shell
###################  delay 1s/1m/1h/1d
DELAY=7d
echo backup shell execute delay is:${DELAY}
###################  execute clean log
while [ 1 ]; do
   DATE=$(date "+%Y-%m-%d")
   echo backup date:${DATE}
   echo backup time:$(date "+%Y-%m-%d %H:%M:%S")
   ./bin/neo4j-admin backup --protocol=catchup --from=10.20.13.200:6000 --backup-dir=./data/backup/ --name=graph.db-backup-${DATE}
   sleep ${DELAY}
done
################### background execution this backup shell
# START_BACKUP_SERVER:
# nohup ./ongdb-backup.sh > ongdb-backup.file 2>&1 &
# STOP_BACKUP_SERVER:
# kill -9 `ps -ef|grep ongdb-backup.sh|grep -v grep|awk '{print $2}'`

数据恢复脚本

bin/neo4j-admin restore --from=/mnt/backup/graph.db-backup-2020-10-28 --database=graph.db --force=false
ongdb@ip-10-20-0-157:~/ongdb-enterprise-3.5.17$ bin/neo4j-admin restore
Missing argument 'from'
usage: neo4j-admin restore --from=<backup-directory> [--database=<name>]
                           [--force[=<true|false>]]
environment variables:
    NEO4J_CONF    Path to directory which contains neo4j.conf.
    NEO4J_DEBUG   Set to anything to enable debug output.
    NEO4J_HOME    Neo4j home directory.
    HEAP_SIZE     Set JVM maximum heap size during command execution.
                  Takes a number and a unit, for example 512m.
Restore a backed up database.
options:
  --from=<backup-directory>   Path to backup to restore from.
  --database=<name>           Name of database. [default:graph.db]
  --force=<true|false>        If an existing database should be replaced.
                              [default:false]

参考文档

https://neo4j.com/docs/operations-manual/3.5/backup/