Hyperledger Fabric doesn’t come with a Backup or restore data options from the box. The way to do it is to get the data from a running blockchain and restore it to a new one. If you want to know to get the backup then follow the blog here. The restoration assumes that the network is down and all the Docker images are removed. The crypto materials and channel artefacts are also deleted. The only thing that remains is the configured network in the docker-compose.yaml file. Now we will start restoring the blockchain by using the backup we have from our previous blockchain network.
Steps to Restore
The restore hyperledger fabric from backup, the process consists of 5 main steps.
- Copy the backup folders out.
- Configure docker-compose.yaml files for peers to mount from backup.
- Configure docker-compose.yaml files for orderer to mount from backup.
- Start the network with the new settings.
Lets go through each step one by one.
Copy the backup folders out
Copy the folders crypto-config/, channel-artifacts/, orderer/, peer0.org1/, peer1.org0/ from backup/ to blockchain-network/
$ cd backup/ && cp -r * ../ && cd ../
Configure docker-compose.yaml files for peers to mount from backup
Configure peer0 to mount files from localhost. In the peer0.org1.example.com service in the yaml file, look for the volumes section as shown below
Notice the part peer0.org1.example.com:/var/hyperledger/production That is where to mount. Change from
peer0.org1.example.com:/var/hyperledger/production
To
<local backup file>:/var/hyperledger/production
assuming the yaml file is in the same location as first-network/. The backup for peer0.org1/ has already been copied out. So the volume configuration will be:
./peer0.org1:/var/hyperledger/production
Configure peer1 to mount files from localhost. In the peer1.org1.example.com service in the yaml file, look for the volumes section as shown belowNotice the part peer1.org1.example.com:/var/hyperledger/production That is where to mount. Change from
peer1.org1.example.com:/var/hyperledger/production
To
<local backup file>:/var/hyperledger/production
Assuming the yaml file is in the same location as first-network/. The backup for peer1.org1/ has already been copied out. So the volume configuration will be:
./peer1.org1:/var/hyperledger/production
Configure docker-compose.yaml files for orderer to mount from backup
Configure orderer to mount files from localhost. In the orderer.example.com service in the yaml file, look for the volumes section as shown below
orderer.example.com:/var/hyperledger/production/orderer.
That is where to mount. Change from
orderer.example.com:/var/hyperledger/production/orderer
To
<local backup file>:/var/hyperledger/production/orderer
Assuming the yaml file is in the same location as first-network/. The backup for orderer/ has already been copied out. So the volume configuration will be:
./orderer:/var/hyperledger/production/orderer
Just to make sure, check all of the docker-compose files and and change there volume section to the backup folders.
Start the network
Previously the network was started using ./byfn.sh up command. Use the same command
$ ./byfn.sh up
or if the network was started using a different script, use it. You’ll notice the peers will automatically join the channel created previously before the network is brought down. The ledger data will be restored and the number of blocks will resume from where the previous network left off.
If you want us to help with restoring a blockchain network from a previously taken backup then contact your blockchain development company.