diff --git a/contrib/save-utxo-set-in-bitcoind.sh b/contrib/save-utxo-set-in-bitcoind.sh index 7f4dde5..6ebfd73 100755 --- a/contrib/save-utxo-set-in-bitcoind.sh +++ b/contrib/save-utxo-set-in-bitcoind.sh @@ -13,16 +13,16 @@ echo "Waiting bitcoind to stop..." $BITCOIN_CLI stop wait $BITCOIND_PID -NETWORK_DIRECTORY=$NETWORK -if [[ $NETWORK == "mainnet" ]]; then +NETWORK_DIRECTORY=$NBITCOIN_NETWORK +if [[ $NBITCOIN_NETWORK == "mainnet" ]]; then NETWORK_DIRECTORY="." fi -if [[ $NETWORK == "testnet" ]]; then +if [[ $NBITCOIN_NETWORK == "testnet" ]]; then NETWORK_DIRECTORY="testnet3" fi cd /data -TAR_NAME="utxo-snapshot-bitcoin-$NETWORK-$PRUNED_HEIGHT.tar" +TAR_NAME="utxo-snapshot-bitcoin-$NBITCOIN_NETWORK-$PRUNED_HEIGHT.tar" echo "Creating $TAR_NAME..." tar -cf "$TAR_NAME" "$NETWORK_DIRECTORY/blocks/" tar -rf "$TAR_NAME" "$NETWORK_DIRECTORY/chainstate/" diff --git a/contrib/save-utxo-set.sh b/contrib/save-utxo-set.sh index aeee683..b713c94 100755 --- a/contrib/save-utxo-set.sh +++ b/contrib/save-utxo-set.sh @@ -2,44 +2,49 @@ # This script shows the steps to create an archive of the current UTXO Set -exit 1 # This script is not meant to run automatically - - -## ARGS# -NETWORK="mainnet" -export AZURE_STORAGE_CONTAINER="public" -export AZURE_STORAGE_CONNECTION_STRING="" -####### +: "${AZURE_STORAGE_CONTAINER:=public}" # IN THE HOST ############################################################# # Stop btcpay btcpay-down.sh +for i in /var/lib/docker/volumes/generated_bitcoin_datadir/_data/utxo-snapshot-*; do + echo "Deleting $i" + rm $i +done + +rm /var/lib/docker/volumes/generated_bitcoin_datadir/_data/utxo-snapshot-* # Run only bitcoind and connect to it SCRIPT="$(cat save-utxo-set-in-bitcoind.sh)" cd "`dirname $BTCPAY_ENV_FILE`" -docker-compose -f $BTCPAY_DOCKER_COMPOSE run -e "NETWORK=$NETWORK" bitcoind bash -c "$SCRIPT" +docker-compose -f $BTCPAY_DOCKER_COMPOSE run -e "NBITCOIN_NETWORK=$NBITCOIN_NETWORK" bitcoind bash -c "$SCRIPT" btcpay-up.sh +echo "Calculating the hash of the tar file..." TAR_FILE="$(echo /var/lib/docker/volumes/generated_bitcoin_datadir/_data/utxo-snapshot-*)" TAR_FILE_HASH="$(sha256sum "$TAR_FILE" | cut -d " " -f 1)" -echo "SHA256: $TAR_FILE_HASH" -echo "Uploading to azure..." -# Install az from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest - -BLOB_NAME="$(basename -- $TAR_FILE)" -az storage container create --name "$AZURE_STORAGE_CONTAINER" --public-access "blob" -az storage blob upload -f "$TAR_FILE" \ - -c "$AZURE_STORAGE_CONTAINER" \ - -n "$BLOB_NAME" \ - --content-type "application/x-tar" - -az storage blob metadata update --container-name "$AZURE_STORAGE_CONTAINER" --name "$BLOB_NAME" --metadata "sha256=$TAR_FILE_HASH" - -# Print the sha256sum. Downloaders will need to verify this -STORAGE_URL="$(az storage blob url --container-name "$AZURE_STORAGE_CONTAINER" --name "$BLOB_NAME" --protocol "http")" -echo "You can now download the UTXO on $STORAGE_URL" -echo "Please, after download, verify the sha256 with:" -echo "echo "$TAR_FILE_HASH $BLOB_NAME" | sha256sum -c -" -rm "$TAR_FILE" \ No newline at end of file + +if [[ "$AZURE_STORAGE_CONNECTION_STRING" ]]; then + echo "Uploading to azure..." + # Install az from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest + + BLOB_NAME="$(basename -- $TAR_FILE)" + az storage container create --name "$AZURE_STORAGE_CONTAINER" --public-access "blob" + az storage blob upload -f "$TAR_FILE" \ + -c "$AZURE_STORAGE_CONTAINER" \ + -n "$BLOB_NAME" \ + --content-type "application/x-tar" + + az storage blob metadata update --container-name "$AZURE_STORAGE_CONTAINER" --name "$BLOB_NAME" --metadata "sha256=$TAR_FILE_HASH" + + # Print the sha256sum. Downloaders will need to verify this + STORAGE_URL="$(az storage blob url --container-name "$AZURE_STORAGE_CONTAINER" --name "$BLOB_NAME" --protocol "http")" + echo "You can now download the UTXO on $STORAGE_URL" + echo "Please, after download, verify the sha256 with:" + echo "echo "$TAR_FILE_HASH $BLOB_NAME" | sha256sum -c -" + rm "$TAR_FILE" +else + echo "SHA256: $TAR_FILE_HASH" + echo "File at: $TAR_FILE" +fi