Luis Bote
Luis Bote

Reputation: 169

Restore Back up From Hyperledger Fabric v2.0

https://www.devprovider.com/how-to-take-backup-from-hyperledger-fabric/

https://www.devprovider.com/how-to-restore-hyperledger-fabric-from-backup/

I follow this 2 tutorials for back up and restore my Blockchain,I did everything the same except:

Make back up:

1:

cp –r crypto-config/ backup/

On my own its organizations folder:

test-network/organizations$ ls
ccp-generate.sh  ccp-template.json  ccp-template.yaml  cryptogen  fabric-ca  ordererOrganizations  peerOrganizations

And then:

./network down for restore on next steps

2:

I need to sudo cp instead of cp, cause else cant copy .key files, after that, i run chown too for set my profile as owner

Restore Back up:

1:

cd backup/ && cp -r * ../ && cd ../

Change it by sudo cp ... and do it on 2 steps(its same that creating back up)

2:

./byfn.sh up

I havent that script, but tutorial said:

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.

So i use

 ./network.sh up createChannel -c mychannel -ca for create my channel

as i always did, it get me errors:

output:

Creating channel 'mychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb 
Generating channel create transaction 'mychannel.tx'
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
2021-03-30 09:53:34.546 CEST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-03-30 09:53:34.560 CEST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/luis/Escritorio/Bchain/asset-Prueba/test-network/configtx/configtx.yaml
2021-03-30 09:53:34.560 CEST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2021-03-30 09:53:34.562 CEST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
Creating channel mychannel
Using organization 1
+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
+ peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/luis/Escritorio/Bchain/asset-Prueba/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:7050: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:7050: connect: connection refused"

edit 1:

As you said i think im doing all well, then, i can start network with ./network up, and do it correctly

output:

./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.2.1
DOCKER_IMAGE_VERSION=2.2.1
/home/luis/Escritorio/Bchain/asset-Prueba/test-network/../bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
/home/luis/Escritorio/Bchain/asset-Prueba/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2021-03-31 08:50:54.035 CEST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2021-03-31 08:50:54.047 CEST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/luis/Escritorio/Bchain/asset-Prueba/test-network/configtx/configtx.yaml
2021-03-31 08:50:54.048 CEST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-03-31 08:50:54.049 CEST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating orderer.example.com    ... done
Creating peer0.org2.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli                    ... done
CONTAINER ID   IMAGE                               COMMAND                   CREATED         STATUS                  PORTS                              NAMES
a4ad5fed6957   hyperledger/fabric-ccenv:2.2        "/bin/sh -c '\nset -e…"   1 second ago    Created                                                    epic_lichterman
64d6650eb7f1   hyperledger/fabric-ccenv:2.2        "/bin/sh -c '\nset -e…"   1 second ago    Created                                                    kind_chaplygin
c9fe6c8f20f4   hyperledger/fabric-tools:latest     "/bin/bash"               1 second ago    Up Less than a second                                      cli
1f20728228a3   hyperledger/fabric-peer:latest      "peer node start"         3 seconds ago   Up Less than a second   0.0.0.0:7051->7051/tcp             peer0.org1.example.com
7732b7cd55d7   hyperledger/fabric-orderer:latest   "orderer"                 3 seconds ago   Up Less than a second   0.0.0.0:7050->7050/tcp             orderer.example.com
4a2c0207f3d2   hyperledger/fabric-peer:latest      "peer node start"         3 seconds ago   Up Less than a second   7051/tcp, 0.0.0.0:9051->9051/tcp   peer0.org2.example.com

Then, i should can invoke orderer,not?

But when i try:

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"getAllAssets","Args":[]}'

output:

Error: error endorsing invoke: rpc error: code = Unknown desc = error validating proposal: access denied: channel [mychannel] creator org [Org1MSP] - proposal response: <nil>

Then orderer go down

Thanks for support

any ideas?

edit 2:

more info:

docker ps -a
...
32ba6c3ff55d   hyperledger/fabric-orderer:latest                                                                                                                                        "orderer"                About a minute ago   Exited (2) 28 seconds ago                                      orderer.example.com

My orderer go down 1 min after i get up it

Upvotes: 0

Views: 872

Answers (1)

Li Xian
Li Xian

Reputation: 411

according to your describe,in the tourial ,fabric version is v1.4.X,and the fabric you now use is v2.x.x,so in v1.4.x the test script is byfn.sh and in v2.x.x the test script is network.sh,these two scripts are different.

if you want to backup a fabric network and restore,you need just backup crypto-config(organizations in v2.x.x),ledger data which obtain from /var/hyperledger/fabric of docker container,and start your orderer and peer container ,you need not create channel or join channel ,you can query and invoke chaincode.

I have answer another question about restore fabric network,you can reference it In Hyperledger Fabric, is there a way to reuse the data of previous network?

--------------new answer-------------------------------

if you exec you peer chaincode invoke command in terminal,you should add this env,and you can invoke success.

## ebable tls
export CORE_PEER_TLS_ENABLED=true

#MSP ID
export CORE_PEER_LOCALMSPID="Org1MSP"

#ca.crt of peer0.org1.example.com , you should change it to absolute path
export CORE_PEER_TLS_ROOTCERT_FILE=crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

#msp of peer0.org1.example.com,you should change it to absolute path
export CORE_PEER_MSPCONFIGPATH=crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp

#peer address,
export CORE_PEER_ADDRESS=localhost:7051

Upvotes: 1

Related Questions