Skip to content

Instantly share code, notes, and snippets.

@skwp
Created October 26, 2018 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skwp/87a7a046c49cf97fcfee5b9c252585e2 to your computer and use it in GitHub Desktop.
Save skwp/87a7a046c49cf97fcfee5b9c252585e2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
network=$1
filename=$2
if [[ -z "$network" ]]; then
echo "Usage: ./restore-chainstate network [filename]"
echo "Restores chainstate. Example: ./restore-chainstate test1 2018-05-07/bitcoin.tgz"
echo "If filename is omitted, will restore to whatever was in /tmp/bitcoin.tgz, typically what we booted with"
fi
stop_command="btcstop"
start_command="btcstart"
wait_command="while ps aux | grep bitcoind | grep -v grep; do sleep 0.5; done"
restore_command="btcrestore $filename"
echo "Stopping all nodes..."
$DIR/run-cmd $network 'client' "$stop_command"
$DIR/run-cmd $network 'miner' "$stop_command"
echo "Waiting for all nodes to shut down..."
$DIR/run-cmd $network client "$wait_command"
echo "Clients shut down"
$DIR/run-cmd $network miner "$wait_command"
echo "Miners shut down"
echo "Restoring..."
$DIR/run-cmd $network miner "$restore_command"
$DIR/run-cmd $network client "$restore_command"
echo "Starting miners..."
$DIR/run-cmd $network miner "$start_command"
echo "Starting clients..."
$DIR/run-cmd $network client "$start_command"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment