How to use snapshot

The snapshot is a state database snapshot of the node. This document describes how to generate a snapshot of the node state for fast recovery of a node.

Download the support package that supports snapshot

curl '' | bash

Creating a Snapshot

1. Restart the duration_node, specify the snapshot path

~/opt/gxb# ./programs/witness_node/witness_node --data-dir=trusted_node --rpc-endpoint= --state-snapshots-dir "/opt/gxchain/data/snapshots"

2. Execute the RPC command as shown below

~/opt/gxb# curl --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "create_snapshot", []], "id": 1}'


Execution result shows head_block_id value and snapshot location and file name when the corresponding snapshot is created

The head block id can be confirmed by cli_wallet get_block block_num command.

~/opt/gxb# curl --data '{ "jsonrpc": "2.0", "method": "call", "params": [0, "get_block_header", [10580657]], "id": 1 }'


Snapshot data is valid after the head block is confirmed as an irreversible block.

Recovering Snapshot Data

The blocks log must have log data after the block ID at the time of creation of the snapshot becomes the Irreversible Block and can not be recovered by restoring to the log file before the confirmation block.

In order to test the data recovery of Snapshot, we will forcibly terminate the witness_node that is currently in normal operation, and proceed with recovery.

kill -s SIGKILL $(pgrep witness_node)

When recovering to snapshot data, you must delete all files and directories except the blocks log file in the trusted_node directory.

~/opt/gxb# ls -al trusted_node/blockchain/
total 71624
drwxr-xr-x   4 root root     4096 Jan 14 17:30 .
drwxr-xr-x   5 root root     4096 Jan 14 17:25 ..
drwxr-xr-x   3 root root     4096 Nov 14  2017 database
-rw-r--r--   1 root root       12 Dec 12 19:16 db_version
drwxr-xr-x 257 root root     4096 Jan 14 17:30 object_database
~/opt/gxb# rm -rf trusted_node/blockchain/object_database

Now use snapshot to proceed with the recovery. Move snapshot data to blockchain directory.

~/opt/gxb# mv /opt/gxchain/data/snapshots/object_database-00a172b14a44015d35202ecabbdf1547be7fbbfe  trusted_node/blockchain/object_database

It performs additional replay for the remaining blocks(blocks after 10580657) based on the point at which index creation is completed and snapshot is made .

Then start witness_node

~/opt/gxb# ./programs/witness_node/witness_node --data-dir=trusted_node --rpc-endpoint= &
Last Updated: 2/27/2019, 3:33:52 PM