bcoin-org / bcoin

Javascript bitcoin library for node.js and browsers
https://bcoin.io
Other
3.01k stars 811 forks source link

backing up spvchain #386

Closed yayitswei closed 6 years ago

yayitswei commented 6 years ago

Hi, thanks for making bcoin.

For backing up the wallet db, we have the backup route. Is there a similar method to back up the spvchain db?

bucko13 commented 6 years ago

All databases and other node info are located in the path set in the node configs which defaults to [HOME_DIR]/.bcoin/[BITCOIN_NETWORK].

yayitswei commented 6 years ago

Is it safe to copy the spv file directly while bcoin is running?

When we used lmdb we would use the mdb_copyutility to back up both the wallet and spvchain, but since lmdb is being deprecated I'm looking for a similar functionality with leveldb.

bucko13 commented 6 years ago

To be honest, I'm not sure. @nodar-chkuaselidze an ideas?

nodech commented 6 years ago

Copying Chain file while bcoin is running is not guaranteed to succeed. Most likely you will end up with db corruption. Leveldb can't/shouldn't be accessed by multiple processes at the same time. (Even though its safe to access it from the same process) https://github.com/google/leveldb/blob/master/doc/index.md#concurrency

@BluSyn Have you dealt with this ?

bucko13 commented 6 years ago

Hey @yayitswei, sorry for the delay. The best way to deal with backups and avoid downtime is to have redundant nodes setup. From what I understand, leveldb apparently does a lot of compression and optimizations in the background which is why it's unsafe to run other processes concurrently. Since the blockchain is essentially one giant distributed backup, the trade-off to get the ability to do those concurrent backups wasn't really worth it.