How To Take a Backup For Your Hyperledger Fabric Network
Tags: blockchain, blockchaintechnology, hyperledger, hyperledgerfabric
Published: 2021-01-19 08:34:25

---
title: How To Take a Backup For Your Hyperledger Fabric Network
published: true
date: 2021-01-16 10:09:05 UTC
tags: blockchain,blockchaintechnology,hyperledger,hyperledgerfabric
canonical_url: https://medium.com/coinmonks/how-to-take-a-backup-for-your-hyperledger-fabric-network-d42f1a4eb6d0
---

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.

![](https://cdn-images-1.medium.com/max/768/0*eBk_GvqDBF_-4zI2.png)

### 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
```

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/ .
```

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/ .
```

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 {} \;
```

Use the secure copy command to download the backup directory.

```
scp -i ../<FILE>.pem -r ubuntu@<ipAddress>:<location>/backup/ .
```

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/*
```

Copy your backup content to your hyperledger fabric network directory.

```
cd <network-location>/
sudo cp -Ra <backup location>/backup/* .
```

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
```

with

```
../orderer/:/var/hyperledger/production/orderer
```

For peer1 volumes replace

```
peer0.org1.example.com:/var/hyperledger/production
```

with

```
.../peer0.org1/:/var/hyperledger
```

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
```

with

```
.../peer0.org2/:/var/hyperledger
```

Now you are ready to start the fabric network.

```
./network.sh up
```

Or If you are using a database.

```
./network.sh up -s couchdb
```

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
```

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

```
peer channel getinfo -c <channel-Name>
```

Thanks!

> Join Coinmonks [Telegram group](https://t.me/joinchat/EPmjKpNYwRMsBI4p) and learn about crypto trading and investing

#### Also, Read

- [Learn Ethereum and Web3 development](http://blog.coincodecap.com/go/learn)
- The Best [Crypto Trading Bot](https://medium.com/coinmonks/crypto-trading-bot-c2ffce8acb2a)
- What are the [best books to learn about Bitcoin](https://medium.com/coinmonks/what-are-the-best-books-to-learn-bitcoin-409aeb9aff4b)?

> [Get Best Software Deals Directly In Your Inbox](https://medium.com/coinmonks/newsletters/coinmonks)

[![](https://cdn-images-1.medium.com/max/584/1*BoDnKUyK8p4hitHAJZ5Pdw.png)](https://medium.com/coinmonks/newsletters/coinmonks)

* * *