Using Snapshots

Snapshot functionality is a built-in feature of the Core that you can easily use with the integrated CLI. Snapshot makes a backup of the current DB state so you can recover from a previously made snapshot and get synced much faster than syncing from 0.

Getting Started

This function should be done at least once per month if you need to recover due to some failure down the road (database corruption, database integrity failure, …) or to quickly set up on additional servers.

Warning

All snapshot input data that represent block height are rounded down to the beginning of the round that contains given height.

Making use of this feature makes most sense once your node is fully synced (up to latest height). To make latest snapshot run this command:

1ark snapshot:dump

This will start up the snapshot process. Don’t interrupt it, as it might take a while, depending on the size of the blockchain. You’ll see a message, something along these lines, as time goes on:

1[2021-06-29 08:11:28.398] INFO : Connecting to database: ark_mainnet
2[2021-06-29 08:11:28.469] DEBUG: Connection established.
3[2021-06-29 08:11:28.473] INFO : Running DUMP for network: mainnet
4[2021-06-29 08:11:28.474] INFO : Start counting blocks, rounds and transactions
5[2021-06-29 08:11:28.525] INFO : Start running dump for 153 blocks, 153 rounds and 153 transactions

After it’s done, you’ll see this message informing you that the process to create the snapshot was shut down and you can now continue:

1Blocks: 100.00 % Transactions: 100.00 % Rounds: 100.00 %
2[2021-06-29 08:11:29.688] INFO : Snapshot is saved on location: .../ark-core/mainnet/snapshots/1-153/
3[2021-06-29 08:11:29.689] DEBUG: Disposing @arkecosystem/core-snapshots...
4[2021-06-29 08:11:29.689] DEBUG: Disposing @arkecosystem/core-database...
5[2021-06-29 08:11:29.689] DEBUG: Disconnecting from database
6[2021-06-29 08:11:29.690] DEBUG: Disconnected from database
7[2021-06-29 08:11:29.691] DEBUG: Disposing @arkecosystem/core-logger-pino...

This is it! You just made a backup of the blockchain.

You can see a list of all completed snapshots in this filepath (replace <network> with the network you operate on — mainnet,devnet,testnet):

1ls /home/ark/.local/share/ark-core/<network>/snapshots
2example:
3ls /home/ark/.local/share/ark-core/mainnet/snapshots
4//In our example it made backup of blockchain 1-153 which means
5from height 1 to height 153

Useful tip: next time you want to make a snapshot, you can start dump from height following latest stored snapshot. Lets use our snapshot we made in the previous step (directory filename 1-153) and increase height by 1, to prepare following snapshot. We’ll run the command, replacing the filename with yours, which can be obtained by running the command from previous paragraph ``ls /home/ark/.local/share/ark-core/<network>/snapshots to list files. Let’s run this to create new snapshot:

1ark snapshot:dump --start=154
2//replace 1-153 with your own folder from previously created snapshot.

We do recommend that you also take full (complete) snaps regularly.

Restoring from a Snapshot

The process for restoring from a previously made snapshot is pretty straightforward. We’ll again make use of the integrated CLI Snapshot.

First, let’s stop the ARK Relay process, if we have it currently running, with:

1ark relay:stop

After that we’ll run the restore command:

1ark snapshot:restore --blocks=<folder name>
2//replace <folder name> with your previously made latest snapshot
3in our case lets use 1-153 so we'd run this command to restore:
4ark snapshot:restore --blocks=1-153

You will see a message similar to this. It will take some time, so leave it running:

1[2021-06-29 08:26:19.515] INFO : Connecting to database: ark_testnet
2[2021-06-29 08:26:19.576] DEBUG: Connection established.
3[2021-06-29 08:26:19.582] INFO : Running RESTORE for network: testnet
4Blocks: 100.00 % Transactions: 100.00 % Rounds: 100.00 %
5[2021-06-29 08:26:21.026] INFO : Successfully restore 153 blocks, 153 transactions, 153 rounds
6[2021-06-29 08:26:21.027] DEBUG: Disposing @arkecosystem/core-snapshots...
7[2021-06-29 08:26:21.027] DEBUG: Disposing @arkecosystem/core-database...
8[2021-06-29 08:26:21.028] DEBUG: Disconnecting from database
9[2021-06-29 08:26:21.029] DEBUG: Disconnected from database
10[2021-06-29 08:26:21.030] DEBUG: Disposing @arkecosystem/core-logger-pino...

Restore command does not automatically clear the database. Use snapshot:rollback or snapshot:truncate command, to rollback or clear the database.

After it is completed, we need to start the relay process again for it to resync (if applicable) back to current height:

1ark relay:start

Rolling back a Blockchain

The rollback function is specifically useful if you forked, your node cannot seem to process new blocks, and you want to resync from the network from specified height.

First, let’s stop the ARK Relay process with:

1ark relay:stop

After that, we’ll make use of Snapshot command rollback — for this case we can use two commands:

Rolling back to a Specific Height

1ark snapshot:rollback --height=<height>
2 
3start to sync from the network. In our case lets say current
4blockchain height is 7,740,000 and if we want to go back 2,000 blocks
5we'll input 7738000 in <height> so we'll run. We'd run:
6 
7ark snapshot:rollback --height=7738000

You’ll see a message similar to this:

1[2021-06-29 08:41:03.467] INFO : Connecting to database: ark_testnet
2[2021-06-29 08:41:03.571] DEBUG: Connection established.
3[2021-06-29 08:41:03.575] INFO : Running ROLLBACK
4[2021-06-29 08:41:03.666] INFO : Last block height is: 7,740,000
5[2021-06-29 08:41:03.715] INFO : Rolling back chain to last finished round 151,725 with last block height 7,737,975
6[2021-06-29 08:41:03.716] DEBUG: Disposing @arkecosystem/core-snapshots...
7[2021-06-29 08:41:03.716] DEBUG: Disposing @arkecosystem/core-database...
8[2021-06-29 08:41:03.717] DEBUG: Disconnecting from database
9[2021-06-29 08:41:03.718] DEBUG: Disconnected from database
10[2021-06-29 08:41:03.718] DEBUG: Disposing @arkecosystem/core-logger-pino...

After it is finished, we need to start the relay process again for it to resync from the previously rolled back state and sync back up to the current height by running:

1ark relay:start

Rolling back to a Specific Block Number

1ark snapshot:rollback --number=<number>
2 
3//where we replace <number> with a number of blocks we want to
4rollback to and start to sync from the network. In our case lets say
5current blockchain height is 7,740,000 and if we want to go back
62,000 blocks we'll input 2000 in <number> so we'll run. We'd run:
7 
8ark snapshot:rollback --number=2000

You’ll see a message similar to this:

1[2021-06-29 08:41:03.467] INFO : Connecting to database: ark_testnet
2[2021-06-29 08:41:03.571] DEBUG: Connection established.
3[2021-06-29 08:41:03.575] INFO : Running ROLLBACK
4[2021-06-29 08:41:03.666] INFO : Last block height is: 7,740,000
5[2021-06-29 08:41:03.715] INFO : Rolling back chain to last finished round 151,725 with last block height 7,737,975
6[2021-06-29 08:41:03.716] DEBUG: Disposing @arkecosystem/core-snapshots...
7[2021-06-29 08:41:03.716] DEBUG: Disposing @arkecosystem/core-database...
8[2021-06-29 08:41:03.717] DEBUG: Disconnecting from database
9[2021-06-29 08:41:03.718] DEBUG: Disconnected from database
10[2021-06-29 08:41:03.718] DEBUG: Disposing @arkecosystem/core-logger-pino...

After it is finished, we need to start the relay process again for it to resync from the previously rolled back state and sync back up to the current height by running:

1ark relay:start

Let it sync back, and you are back in business!

Copying Snapshots Between Servers

If you want to copy a snapshot to another server you own to bring it quickly into sync or to store a copy in a different location, we can make use of SCP (Secure Copy Protocol) which supports secure file transfers between different hosts.

SCP allows files to be copied to / from / between different hosts. It uses SSH protocol for transfers and provides the same authentication and level of security as SSH.

If you want to copy files from one server to another, we’ll run this command where we need to replace <network> with the network you operate on (in our example mainnet), <folder-name> with snapshot name we are copying in our example it will be 1-7739894, <username> with username of the server we are copying to and <IP> with its IP address:

1scp -r /home/ark/.local/share/ark-core/<network>/snapshots/<folder-name> <username>@IP:/home/ark/.local/share/ark-core/<network>/snapshots/<folder-name>
2 
3// to put this into a practical example:
4 
5scp -r /home/ark/.local/share/ark-core/mainnet/snapshots/1-7739894 [email protected]:/home/ark/.local/share/ark-core/mainnet/snapshots/1-7739894

After this, you will enter yes to confirm you want to connect to the server and add it to the list of known hosts.

1The authenticity of host <IP> can’t be established.
2ECDSA key fingerprint is <key>
3Are you sure you want to continue connecting (yes/no)? yes

After that, you will be prompted for the password of the server you are connecting to:

1Warning: Permanently added '<ip>' (ECDSA) to the list of known hosts.
2[email protected]<ip>'s password: inputpasswordhere

Your files will begin copying from one server to another. Wait until it completes, and you are good to go! If you wish to restore from the snapshot on your second server, login to that server and follow “Restoring from the Snapshot” above.

Last updated 7 months ago
Edit Page
Share:
2022 © ARK.io | All Rights Reserved
An ARK.io Product