DEV Community

CoinMonks
CoinMonks

Posted on • Originally published at Medium on

How To Take a Backup For Your Hyperledger Fabric Network

This article will demonstrate different ways to get a backup for your fabric network. To deploy the same hyperledger fabric network with previously submitted data in a different host. Two ways, the first one is taking a backup from the fabric docker containers. The second one is to copy all transactions and configure docker-compose files to binds our docker containers volumes.

Docker Backup Methods (Naive One)

All hyperledger fabric components are running throw docker container. So you can save running containers and place them wherever you want by following these steps. I don’t recommend this way as it is a workaround, but it may be easier for you if you are a DevOps developer. And don’t have much experience with blockchain.

Some issues you may face

1- Saving container volumes and associate them again may be complicated. Especially with hyperledger fabric, you could have more than twenty containers to manage.

2- Lose the latest transactions. Suppose you stopped the containers while some transaction is processing.

3- You can’t effectively manage your network again. Now you need to everything throw docker container commands.

Saving All Transactions And Network Components

The following method is better than the first one. It will offer you the best way to copy your blockchain and redeploy it. The first step is to create a backup folder.

mkdir backup
cd backup
Enter fullscreen mode Exit fullscreen mode

Now we need to copy three things:

1- channel-artifacts

2- system-genesis-block

3- organization.

 sudo cp -aR ~/<Your-Project-Location>/channel-artifacts/ .
 sudo cp -aR ~/<Your-Project-Location>/system-genesis-block/ .
 sudo cp -aR ~/<Your-Project-Location>/organizations/ .
Enter fullscreen mode Exit fullscreen mode

Then Copy docker containers for peers and order.

mkdir orderer peer0.org1 peer0.org2

docker cp peer0.org1.example.com:/var/hyperledger/production/ peer0.org1/

docker cp peer0.org2.example.com:/var/hyperledger/production/ peer0.org2/

docker cp orderer.example.com:/var/hyperledger/production/orderer/ .
Enter fullscreen mode Exit fullscreen mode

Suppose you want to copy your backup file from a remote host to your localhost. You may face issues as some files have secure root access.

sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

Use the secure copy command to download the backup directory.

scp -i ../<FILE>.pem -r ubuntu@<ipAddress>:<location>/backup/ .
Enter fullscreen mode Exit fullscreen mode

And that’s it now you successfully had a backup for your blockchain. The next steps are for recovering your blockchain.

Rest script permissions

chmod 774 organizations/ccp-* organizations/fabric-ca/registerEnroll.sh organizations/cryptogen/*
Enter fullscreen mode Exit fullscreen mode

Copy your backup content to your hyperledger fabric network directory.

cd <network-location>/
sudo cp -Ra <backup location>/backup/* .
Enter fullscreen mode Exit fullscreen mode

Now the most important part is to bind the volumes from our backup files. Got to file docker-compose-test-net.yaml

For orderer volumes replace

orderer.example.com:/var/hyperledger/production/orderer
Enter fullscreen mode Exit fullscreen mode

with

../orderer/:/var/hyperledger/production/orderer
Enter fullscreen mode Exit fullscreen mode

For peer1 volumes replace

peer0.org1.example.com:/var/hyperledger/production
Enter fullscreen mode Exit fullscreen mode

with

.../peer0.org1/:/var/hyperledger
Enter fullscreen mode Exit fullscreen mode

Of course, if you have more than one peer, you will bind volumes for all peers. In my case, I have two peers

For peer2 replace

peer0.org2.example.com:/var/hyperledger/production
Enter fullscreen mode Exit fullscreen mode

with

.../peer0.org2/:/var/hyperledger
Enter fullscreen mode Exit fullscreen mode

Now you are ready to start the fabric network.

./network.sh up
Enter fullscreen mode Exit fullscreen mode

Or If you are using a database.

./network.sh up -s couchdb
Enter fullscreen mode Exit fullscreen mode

Peers would take a couple of minutes to sync with the channel; then all chain code will be up and running with previous data. you can check them using peers log

docker logs peer0.org1.example.com -f
Enter fullscreen mode Exit fullscreen mode

To make sure everything is alright you cand check the last submitted block inside peer container.

peer channel getinfo -c <channel-Name>
Enter fullscreen mode Exit fullscreen mode

Thanks!

Join Coinmonks Telegram group and learn about crypto trading and investing

Also, Read

Get Best Software Deals Directly In Your Inbox


Top comments (0)