Forked from 05nelsonm/Move bitcoind data to Dojo bitcoind container
Created
December 29, 2020 05:04
-
-
Save kornpow/60419a148556d32755fef267c8228c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Move over block data to your Dojo #### | |
## If you wanted to copy over the data instead of moving it, see --> https://gist.github.com/05nelsonm/96ad8da7724de3a66f44d6c2d70b361c | |
## Written for Ubuntu Desktop 18.04 LTS & Dojo v1.0.0 ## | |
## Start Dojo | |
$ cd /path/to/docker/my-dojo/ && sudo ./dojo.sh start | |
## Login to the bitcoind docker container as root | |
$ sudo docker exec -u root -it bitcoind /bin/bash | |
## Update and install a text editor | |
$ apt-get update && apt-get install nano | |
## Stopping bitcoind via 'sudo ./dojo.sh bitcoin-cli stop' shuts the container down, so I found it easiest to | |
## just add the following to bitcoin.conf and then stop the tor container to cut internet so the bitcoind | |
## container won't be able to download anything while moving the .bitcoin directory | |
$ nano /home/bitcoin/.bitcoin/bitcoin.conf | |
## Add to bitcoin.conf | |
onlynet=onion | |
dnsseed=0 | |
dns=0 | |
## Save and exit | |
ctrl+x --> y --> return | |
## Make a new directory in the bitcoind container to mount a host directory to | |
$ mkdir /mnt/bitcoin_data | |
## Exit the bitcoind container | |
$ exit | |
## Stop Dojo | |
$ sudo ./dojo.sh stop | |
## Modify the docker-compose.yaml file to bind mount a host directory to a bitcoind container directory | |
$ nano docker-compose.yaml | |
## Be sure to enter the full path below to wherever your /.bitcoin/ directory is located (typically /home/your_username/.bitcoin/) | |
## Under the section for `bitcoind` --> `volumes:` add... | |
- /home/path/to/host_machine/.bitcoin:/mnt/bitcoin_data | |
#### Your bitcoind section should now look something like the following #### | |
bitcoind: | |
image: "samouraiwallet/dojo-bitcoind:1.0.0" | |
container_name: bitcoind | |
build: | |
context: ./bitcoin | |
env_file: | |
- ./.env | |
- ./conf/docker-bitcoind.conf | |
restart: on-failure | |
command: "/wait-for-it.sh tor:9050 --timeout=360 --strict -- /restart.sh" | |
expose: | |
- "28256" | |
- "9501" | |
- "9502" | |
volumes: | |
- /home/path/to/host_machine/.bitcoin:/mnt/bitcoin_data | |
- data-bitcoind:/home/bitcoin/.bitcoin | |
depends_on: | |
- db | |
- tor | |
networks: | |
dojonet: | |
ipv4_address: 172.28.1.5 | |
## Save and exit | |
ctrl+x --> y --> return | |
## Start Dojo | |
$ sudo ./dojo.sh start | |
## Pause the TOR container. This will stop bitcoind from downloading anything b/c it won't have an internet connection | |
$ sudo docker container pause tor | |
## Ensure bitcoind isn't doing anything by checking the bitcoind logs | |
$ sudo ./dojo.sh logs bitcoind | |
## You should see socks errors and unable to connect statements | |
## Login to bitcoind container as root | |
$ sudo docker exec -u root -it bitcoind /bin/bash | |
## Ensure that things mounted properly | |
$ cd /mnt/bitcoin_data/ | |
$ ls -la | |
## You should see the host machine's bitcoind files in there | |
## Clear out everything but `bitcoin.pid` and `bitcoin.conf` from the container's home/bitcoin/.bitcoin/ directory | |
$ mv /home/bitcoin/.bitcoin/bitcoin.conf /home/bitcoin/ | |
$ mv /home/bitcoin/.bitcoin/bitcoind.pid /home/bitcoin/ | |
$ rm -rf /home/bitcoin/.bitcoin/* | |
## Move over host machine .bitcoin files | |
$ mv /mnt/bitcoin_data/.bitcoin/ /home/bitcoin/.bitcoin/ | |
## Remove old `bitcoin.conf` file that you moved over from your host machine, and then move your Dojo's files back | |
$ rm -rf /home/bitcoin/.bitcoin/bitcoin.conf | |
$ mv /home/bitcoin/bitcoin.conf /home/bitcoin/.bitcoin/ | |
$ mv /home/bitcoin/bitcoind.pid /home/bitcoin/.bitcoin/ | |
## Change ownership of everything to bitcoin:bitcoin | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/blocks/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/blocks/index/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/chainstate/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/indexes/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/indexes/txindex/* | |
$ chown bitcoin:bitcoin /home/bitcoin/.bitcoin/wallets/* | |
##### If there are issues with changing ownership of the txindex/* files (Arguments being too long), try the following: | |
$ sudo find /home/bitcoin/.bitcoin/indexes/txindex/ -type f -exec chown bitcoin:bitcoin {} \; | |
## Double check ownership of everything is bitcoin:bitcoin by going into each directory and executing | |
$ ls -la | |
## Reinstall the text editor (it gets uninstalled after Dojo restart) | |
$ apt-get update && apt-get install nano | |
## Revert your bitcoin.conf back to allow for clearnet connections | |
$ nano /home/bitcoin/.bitcoin/bitcoin.conf | |
## Remove from bitcoin.conf | |
onlynet=onion | |
dnsseed=0 | |
dns=0 | |
## Save and exit | |
ctrl+x --> y --> return | |
## Exit the container | |
$ exit | |
## Restart the Dojo | |
$ sudo ./dojo.sh stop | |
$ sudo ./dojo.sh start | |
## Check bitcoind progress | |
$ sudo ./dojo.sh logs bitcoind |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment