Hyperledger Fabric is gaining potential day by day. Many enterprises are trying fabric in their applications. When using large networks involving more number of peers and orderers, it is very essential to maintain a backup of the ledger data. It will help in case there is a network failure. It will also help in the development phase as one can use the backup data to perform future tests.
In this article, I will address how to take a backup and how to use the backup in a Hyperledger Fabric.
Location of Ledger Data in Containers#
Generally, the ledger data in a peer is stored in
/var/hyperledger/production/ location. And in an orderer, it is in
/var/hyperledger/production/orderer. We need to take a backup of these folders.
Steps to take Backup#
To take a backup, it is necessary to create space to store data. As the network runs inside Docker containers we shall use volumes to achieve this. I will be using a basic network with one peer, one orderer, one ca and one CouchDB. As we have one peer and one orderer, we need to create two volumes, say
backup_peer. We need to specify these as volumes in
docker-compose.yml file as below.
networks: basic: volumes: backup_peer: backup_orderer:
This will create two volumes at the time of starting a network.
The next step is to mount these volumes to the containers. For a peer, we can define volumes as shown below.
volumes: - backup_peer:/var/hyperledger/production
For an orderer, we can define volume as shown below.
volumes: - backup_orderer:/var/hyperledger/production/orderer
Now we are ready to start the network by executing docker-compose. All the data that we generate as part of the transactions will now get copied to the volumes. One can use the cloud to store the data in volumes.
Peer Backup Underhood#
In peers, ledger data gets stored in
production folder has three subfolders namely
chaincodes, ledgersData, transientStore, Inside
ledgersData we have six folders namely
bookkeeper, chains, configHistory, historyLeveldb, ledgerProvider, pvtdataStore. Inside
chains we have two other folders namely
chains folder has all the channel data, a folder with channel name and complete blockchain of that channel (file
Orderer Backup Underhood#
In the orderer, ledger data gets stored in
orderer has two folders namely
chains has folders with names of channel and
testchainid. All the folders have
blockfile_000000 in testchainid contains all the details of the channels. Rest of the
blockfile_000000 in other folders deals with ledger data of the channels.
Steps to Use Backup Data#
Now we have the backup data. You can find the volumes at
/var/lib/docker/volumes in your machine or else in the cloud if you stored there. Mount the end point of volumes to the
/var/hyperledger/production of peers and orderers in
Start the network by executing a docker-compose file. As the volumes are mounted, the ledger data will automatically get copied to the new network. There is no need to create channels and join peers, as all the required data is copied to respective folders in containers. Check whether the data is perfect or not by executing queries.
If you have any doubts or stuck somewhere you can comment below and let us know, we will try to answer as soon as possible. 😀