从 Hyperledger Fabric v2.0 恢复备份

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/

我按照这 2 个教程来备份和恢复我的区块链,我做了所有相同的事情,除了:

备份:

1:

cp –r crypto-config/ backup/

我自己的组织文件夹:

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

然后:

./network down for restore on next steps

2:

我需要 sudo cp 而不是 cp,因为否则无法复制 .key 文件,之后,我 运行 chown 也将我的配置文件设置为所有者

恢复备份:

1:

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

通过 sudo cp 更改它...并分 2 个步骤进行(与创建备份相同)

2:

./byfn.sh up

我没有那个脚本,但是教程说:

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.

所以我用

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

像往常一样,它让我出错:

输出:

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"

编辑 1:

正如你所说,我认为我做的很好,然后,我可以用./network up开始网络,并正确地做

输出:

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

那么,我应该可以调用 orderer,不是吗?

但是当我尝试时:

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":[]}'

输出:

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

然后排序节点下线

感谢支持

有什么想法吗?

编辑 2:

更多信息:

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

我的点餐机在我起来后 1 分钟就挂了

根据你的描述,在tourial中,fabric版本是v1.4.X,而你现在使用的fabric是v2.x.x,所以在v1.4.x中测试脚本是 byfn.sh 而在 v2.x.x 中测试脚本是 network.sh,这两个脚本是不同的。

如果你想备份一个结构网络并恢复,你只需要备份加密配置(v2.x.x中的组织),从docker容器的/var/hyperledger/fabric获取的分类账数据,并启动你的orderer和peer容器,你不需要创建通道或加入通道,你可以查询和调用chaincode。

我已经回答了另一个关于恢复fabric网络的问题,你可以参考一下

----------------新答案---------------------------- --

如果你在终端执行你的peer chaincode invoke命令,你应该添加这个环境,你可以调用成功。

## 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/Admin@org1.example.com/msp

#peer address,
export CORE_PEER_ADDRESS=localhost:7051