Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Samourai Dojo Copy Node Data
#### Copy over block data to your Dojo ####
## If you wanted to MOVE over the data instead of copying it, see --> https://gist.github.com/05nelsonm/5c3607a3ad7d138d908e8a3d985a0df0
## Written for use with Ubuntu Desktop 18.04 LTS & Dojo v1.0.0 ##
## On your machine running Dojo, open 2 terminals, we'll call them [terminal A] & [terminal Doc]
## In [terminal A] Check the size of your .bitcoin directory
$ df -hf ~/.bitcoin
## In [terminal A] Ensure you have enough hard drive space to copy over the content to the container.
$ df -h
## Under column `Filesystem` it should be something like /dev/sda2 , then read column `Avail` so see if you have space
## IN [terminal A] Start Dojo
$ cd /path/to/docker/my-dojo/ && sudo ./dojo.sh start
## In [terminal Doc] login to the bitcoind docker container as root
$ sudo docker exec -u root -it bitcoind /bin/bash
## In [terminal Doc] 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 copying the .bitcoin directory
## In [terminal Doc]
$ nano /home/bitcoin/.bitcoin/bitcoin.conf
## Add to bitcoin.conf
onlynet=onion
dnsseed=0
dns=0
## Save and exit
ctrl+x --> y --> return
## In [terminal A], restart the Dojo so changes to bitcoin.conf take effect
$ sudo ./dojo.sh stop
$ sudo ./dojo.sh start
## Pause the TOR container. This will stop bitcoind from downloading anything b/c it won't have an internet connection
## In [terminal A]
$ sudo docker container pause tor
## In [terminal Doc] Log back into the bitcoind container as root
$ sudo docker exec -u root -it bitcoind /bin/bash
## Clear out everything but `bitcoin.pid` and `bitcoin.conf` from the container's home/bitcoin/.bitcoin/ directory
## In [terminal Doc]
$ mv /home/bitcoin/.bitcoin/bitcoin.conf /home/bitcoin/
$ mv /home/bitcoin/.bitcoin/bitcoind.pid /home/bitcoin/
$ rm -rf /home/bitcoin/.bitcoin/*
## In [terminal A] Get the container ID for bitcoind container
$ sudo docker ps | grep bitcoind | cut -d " " -f 1
## Copy the contents of your current full node's .bitcoin directory to the bitcoind docker container
## In [terminal A], (where XXXXXXXXXXXX is the full container ID for bitcoind)
$ sudo docker cp /home/path/to/host_machine/.bitcoin/ XXXXXXXXXXXX:/home/bitcoin/.bitcoin/
## Go play with yourself for a bit while you wait...
## In [terminal Doc] When it's done... remove the bitcoin.conf & bitcoind.pid that you copied over,
## then move the Dojo's original bitcoin.conf and bitcoind.pid back
$ rm -rf /home/bitcoin/.bitcoin/bitcoin.conf
$ rm -rf /home/bitcoin/.bitcoin/bitcoind.pid
$ mv /home/bitcoin/bitcoin.conf /home/bitcoin/.bitcoin
$ mv /home/bitcoin/bitcoind.pid /home/bitcoin/.bitcoin
## In [terminal Doc] 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 {} \;
## In [terminal Doc] Double check ownership of everything is bitcoin:bitcoin by going into each directory and executing
$ ls -la
## In [terminal Doc] Reinstall the text editor (it gets uninstalled after Dojo restart)
$ apt-get update && apt-get install nano
## In [terminal Doc] 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
## In [termainl A] Restart the Dojo
$ sudo ./dojo.sh stop
$ sudo ./dojo.sh start
## In [terminal A] Check bitcoind progress
$ sudo ./dojo.sh logs bitcoind
@05nelsonm

This comment has been minimized.

Copy link
Owner Author

05nelsonm commented Jun 8, 2019

If your running Bitcoin Core on another machine, you can setup NFS between that machine and the one running Dojo.

On the machine currently running Bitcoin Core
sudo apt-get install nfs-kernel-server -y
sudo mkdir /export
sudo mkdir /export/bitcoin
sudo mount --bind ~/.bitcoin /export/bitcoin
sudo nano /etc/exports

  Add to /etc/exports
  /export/bitcoin *(rw,sync,no_root_squash,no_subtree_check)

sudo exportfs -ra
sudo service nfs-kernel-server restart

If you're using Uncomplicated Firewall (UFW) on the machine currently running Bitcoin Core, open port 2049

Now on your Dojo (where xxx.xxx.x.xxx is the IP address of the machine currently running Bitcoin Core)
sudo mkdir /mnt/bitcoin
sudo mount -o port=2049 xxx.xxx.x.xxx:/ /mnt/bitcoin
cd /mnt/bitcoin/export/

Cleanup after done copying files to bitcoind docker
On the Dojo
sudo umount /export/bitcoin

On the other machine that was running Bitcoin Core
sudo service nfs-kernel-server stop
sudo umount /export/bitcoin
sudo nano /etc/exports

  Remove from, or comment out of /etc/exports
  `#/export/bitcoin *(rw,sync,no_root_squash,no_subtree_check)`

sudo exportfs -ra
sudo exportfs -u
sudo exportfs -v # just to make sure nothing pops up...

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.