In the evolving landscape of blockchain technology, maintaining the the robustness and reliability of private networks are essential. Hyperledger Besu, an open-source Ethereum client designed for enterprise use, offers various methods for backing up and restoring data. This blog post provides a complete guide on how to efficiently backup and restore a private blockchain network using Besuensuring minimal downtime and data integrity.
Environment setup
Before embarking on the backup and recovery processes, it is essential to properly establish your network nodes. Here is a typical configuration using Besu version 24.3.0highlighting the importance of managing the Genesis file and data paths:
- Managing Genesis Files: The Genesis file defines the initial configuration of your blockchain and must be consistent across all nodes. It is prudent to store this file under source control to avoid discrepancies and ensure that all nodes start from the same initial state.
- Configuring the Data Path: Besu allows you to specify a data path using the –data-path command. It is recommended to set up a separate volume dedicated to blockchain data to simplify backups and strengthen security. The default data path is often found in the Besu installation directory, but for Docker installations it defaults to /opt/besu/database.
Each node initializes with the following basic command pattern:
besu –data-path=data –genesis-file=../genesis.json –bootnodes=
Recommended backup and restore process
To ensure data consistency and network integrity, follow a structured approach to backup and recovery operations:
Regular data backups: Perform periodic backups of the data directory to protection against corruption or data loss due to hardware failure. Methods can include automated scripts using cron and rsync jobs, archiving to cloud services like AWS S3, or creating tar.gz archives for manual storage.
Data restoration:
- Approach 1: Single recovery point
- Shut down the first node to ensure data consistency during backup.
- Copy the genesis.json file and take a backup of data/database, data/caches and DATABASE_METADATA.json from the stopped node.
- Restore these files to each node in the network, ensuring that the cryptographic keys (key and key.pub) remain unchanged because they are unique to each node.
- Restart the first node, followed by all other nodes.
- Approach 2: Synchronize all nodes to recover
- Shut down the first node and save the necessary files as in approach 1.
- Delete data/database, data/caches and DATABASE_METADATA.json from each node, leaving cryptographic keys intact.
- Restore the backup to the first node and restart it.
- Once the first node is up and running, start the remaining nodes. They will sync with the first node, allowing the network to resume block production and transactions.
Method not recommended
- Approach 3: Complete network backup
- Shut down all nodes simultaneously to take a snapshot of data from the entire network.
- Back up the entire data directory for each node.
- Restore the respective backups on each node.
- Restart all nodes simultaneously.
This approach, while simple, has risks of data inconsistency and requires precise timing, making it less favorable for most operational environments.
Handling Corrupt Data
If the log messages indicate a corrupted database, the cleanest way to recover is:
-
Stop the node.
-
Restore data from a previous backup.
-
Restart the node.
Effectively managing backups and restores in a private blockchain based on Hyperledger Besu is crucial to maintaining the health and integrity of network data. The recommended methods prioritize security, ensuring that each node is properly synchronized without compromising the security of each node. By following these structured approaches, administrators can protect their networks against data loss and ensure seamless continuity even in the event of a system outage.
For more details and updates on Besu features, refer to the official Hyperledger Besu documentation – https://besu.hyperledger.org/development/private-networks/how-to/backup