Backup from hyperledger Fabric seems impossible since blockchain is immutable and it can never be turned down. Well this case is true for the public blockchains but not for the case for permissioned blockchains like hyperledger fabric. Hyperledger fabric is a private blockchain that follows the different mechanism than the most public blockchain system that we know today.

Hyperledger fabric is mostly used for a custom private blockchain deployment and with that sometimes it is required to migrate this blockchain system to a newer version or to get moved to a newer server.For these reasons we might have to take backup from our current system.

For this tutorial and example we are going to assume that the blockchain we started was started using the first-network provided by Fabric Samples. The directory is defined as below.

If you are here reading about how to take backup from your blockchain then you already know how to run the blockchain.

You need to identify all your peers and all orderer’s in order to be able to take backup from.

Backup from Hyperledger Fabric

There are four main items that are needed for the backup to work. Only with these four items available, would you be able to recreate the network.

  1. Crypto materials (public/private keys and certificates)
  2. Channel artifacts (genesis block and channel blocks)
  3. Peer backup files
  4. Orderer backup files

These four items are the key to recreating a network even if the network is completely down. If the network has couchdb as the configures db, it does not matter if you wish to backup the couchdb files or not because the peers will keep the couchdb in sync once they have their blocks.

$ docker ps

backup from hyperledger Fabric

Okay so now we will start taking the backup.

Steps to Backup  

The steps should be performed in the order for a successful backup of the whole system.

Create a backup folder

The first step is to create a directory anywhere on your system to store backup in it. I am making the backup directory in the same folder as my blockchain.

$ mkdir backup

Create a copy of the crypto materials.

Before bringing up the network, you will have to generate the crypto materials using the crypto-config.yaml file. This will generate a folder, crypto-config/ , containing all the public and private keys as well as the certificates. Copy the crypto-config/ folder into the backup/ folder.

backup from hyperledger Fabric

 $ cp –r crypto-config/ backup/

Create a copy of the channel artefacts.

Before bringing up the network, you will have to generate the channel artifacts using the configtx.yaml file. This will generate the orderer genesis block(genesis.block), channel configuration transaction(channel.tx) and anchor peer update transaction(Org1MSPanchors.tx) files in the channel-artifacts/ folder. Copy the channel-artifacts/ folder onto the backup/ folder

backup from hyperledger Fabric

$ cp –r channel-artifacts/ backup/

Extract peers files for backup.

Extract data from peer0. The ledger data, block data and chaincode used are stored in the /var/hyperledger/production/ folder in the peer. In this folder, there are three main folders:

  1. Chaincodes/
  2. LedgerData/
  3. TransientStore/

These three folders are required to recreate the peer. Thus, copy everything inside the /var/hyperledger/production/ folder into backup/peer0.org1/ folder.

$ docker cp backup/peer0.org1/

You have to follow the same steps for all of the peers that you have created in your network. Since every peer has the ledger data.

Extract orderer files for backup.

Extract data from orderer. The block files and channel configuration details are stored in the /var/hyperledger/production/orderer/ folder in the orderer. In this folder, there are two main folders:

  1. Chains/
  2. Index/

These two folders are required to recreate the orderer. Thus, copy everything inside the /var/hyperledger/production/orderer/ folder into backup/orderer/ folder.

$ docker cp backup/orderer/

Now we have backed up all the important files necessary to recreate the network.

Now your backup is ready to be deployed into another network.

If you want help regarding taking backups and deploying them onto a new system then consult your blockchain development company.

Leave a Reply

Your email address will not be published. Required fields are marked *