From fc6d7fda90057a872da293112c84cfc88b8cdcc8 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Wed, 3 Aug 2022 10:53:11 -0400 Subject: [PATCH] BTCPAY Server migration improvements. --- deploy.sh | 17 +++++++++-------- deployment/btcpayserver/backup.sh | 2 +- deployment/btcpayserver/go.sh | 17 ++++++++++++----- .../remote_scripts/btcpay-backup.sh | 16 ++++++++++------ .../{run_setup.sh => stub_btcpay_setup.sh} | 3 +-- deployment/domain_init.sh | 3 +-- 6 files changed, 34 insertions(+), 24 deletions(-) rename deployment/btcpayserver/{run_setup.sh => stub_btcpay_setup.sh} (98%) diff --git a/deploy.sh b/deploy.sh index f88e577..43adf86 100755 --- a/deploy.sh +++ b/deploy.sh @@ -23,7 +23,7 @@ if ! lsb_release -d | grep -q "Ubuntu 22.04 LTS"; then exit 1 fi -MIGRATE_VPS=false +MIGRATE_BTCPAY=false DOMAIN_NAME= RESTORE_ARCHIVE= VPS_HOSTING_TARGET=lxd @@ -81,7 +81,7 @@ for i in "$@"; do shift ;; --migrate-btcpay) - MIGRATE_VPS=true + MIGRATE_BTCPAY=true RUN_CERT_RENEWAL=false shift ;; @@ -211,14 +211,15 @@ function run_domain { export RUN_CERT_RENEWAL="$RUN_CERT_RENEWAL" export BTC_CHAIN="$BTC_CHAIN" export UPDATE_BTCPAY="$UPDATE_BTCPAY" - export MIGRATE_VPS="$MIGRATE_VPS" + export MIGRATE_BTCPAY="$MIGRATE_BTCPAY" export RECONFIGURE_BTCPAY_SERVER="$RECONFIGURE_BTCPAY_SERVER" # iterate over all our server endpoints and provision them if needed. # www VPS_HOSTNAME= - # OPTINOAL umbrel - for VIRTUAL_MACHINE in www btcpayserver umbrel; do + + + for VIRTUAL_MACHINE in www btcpayserver; do FQDN= # shellcheck disable=SC1091 @@ -386,7 +387,7 @@ function run_domain { if [ "$MACHINE_EXISTS" = true ]; then # we delete the machine if the user has directed us to - if [ "$MIGRATE_VPS" = true ]; then + if [ "$MIGRATE_BTCPAY" = true ]; then # if the RESTORE_ARCHIVE is not set, then if [ -z "$RESTORE_ARCHIVE" ]; then @@ -422,13 +423,13 @@ function run_domain { RESTORE_BTCPAY="$RESTORE_BTCPAY" UPDATE_BTCPAY="$UPDATE_BTCPAY" RUN_RESTORE="$USER_RUN_RESTORE" RUN_BACKUP="$RUN_BACKUP" RUN_SERVICES=true ./deployment/domain_init.sh fi else - if [ "$MIGRATE_VPS" = true ]; then + if [ "$MIGRATE_BTCPAY" = true ]; then echo "INFO: User has indicated to delete the machine, but it doesn't exist. Going to create it anyway." fi # The machine does not exist. Let's bring it into existence, restoring from latest backup. echo "Machine does not exist. RUN_RESTORE=$USER_RUN_RESTORE RUN_BACKUP=false" - RESTORE_BTCPAY=false UPDATE_BTCPAY="$UPDATE_BTCPAY" RUN_RESTORE="$USER_RUN_RESTORE" RUN_BACKUP=false RUN_SERVICES=true ./deployment/domain_init.sh + RESTORE_BTCPAY="$RESTORE_BTCPAY" UPDATE_BTCPAY="$UPDATE_BTCPAY" RUN_RESTORE="$USER_RUN_RESTORE" RUN_BACKUP=false RUN_SERVICES=true ./deployment/domain_init.sh fi done diff --git a/deployment/btcpayserver/backup.sh b/deployment/btcpayserver/backup.sh index d13a161..b386007 100755 --- a/deployment/btcpayserver/backup.sh +++ b/deployment/btcpayserver/backup.sh @@ -7,7 +7,7 @@ cd "$(dirname "$0")" # the script executed here from the BTCPAY repo will automatically take services down # and bring them back up. -ssh "$FQDN" "cd $REMOTE_HOME/; sudo BTCPAY_BASE_DIRECTORY=$REMOTE_HOME bash -c $BTCPAY_SERVER_APPPATH/btcpay-down.sh" +ssh "$FQDN" "mkdir -p $REMOTE_HOME/backups; cd $REMOTE_HOME/; sudo BTCPAY_BASE_DIRECTORY=$REMOTE_HOME bash -c $BTCPAY_SERVER_APPPATH/btcpay-down.sh" # TODO enable encrypted archives # TODO switch to btcpay-backup.sh when on LXD fully. diff --git a/deployment/btcpayserver/go.sh b/deployment/btcpayserver/go.sh index 6769ff9..04c0782 100755 --- a/deployment/btcpayserver/go.sh +++ b/deployment/btcpayserver/go.sh @@ -24,11 +24,19 @@ elif [ "$RESTORE_BTCPAY" = true ]; then RUN_SERVICES=true OPEN_URL=true + # if this is a new VM from a migration procedure, then we can now run setup. + if [ "$MIGRATE_BTCPAY" = true ]; then + ./stub_btcpay_setup.sh + fi + elif [ "$RECONFIGURE_BTCPAY_SERVER" == true ]; then # the administrator may have indicated a reconfig; # if so, we re-run setup script. - ./run_setup.sh - exit + ./stub_btcpay_setup.sh + + RUN_BACKUP=false + RUN_SERVICES=true + OPEN_URL=true fi # if the script gets this far, then we grab a regular backup. @@ -37,7 +45,6 @@ if [ "$RUN_BACKUP" = true ]; then ./backup.sh "$UNIX_BACKUP_TIMESTAMP" fi - if [ "$RUN_SERVICES" = true ]; then # The default is to resume services, though admin may want to keep services off (eg., for a migration) # we bring the services back up by default. @@ -48,6 +55,6 @@ fi if [ "$OPEN_URL" = true ]; then if wait-for-it -t 5 "$FQDN:443"; then - xdg-open "https://$FQDN" + xdg-open "https://$FQDN" > /dev/null 2>&1 fi -fi \ No newline at end of file +fi diff --git a/deployment/btcpayserver/remote_scripts/btcpay-backup.sh b/deployment/btcpayserver/remote_scripts/btcpay-backup.sh index 24963ae..5ca43fd 100644 --- a/deployment/btcpayserver/remote_scripts/btcpay-backup.sh +++ b/deployment/btcpayserver/remote_scripts/btcpay-backup.sh @@ -67,13 +67,17 @@ echo "ℹ️ Archiving files in $(pwd)…" { tar \ --exclude="volumes/backup_datadir" \ - --exclude="volumes/generated_bitcoin_datadir/blocks" \ - --exclude="volumes/generated_bitcoin_datadir/chainstate" \ - --exclude="volumes/generated_bitcoin_datadir/debug.log" \ - --exclude="volumes/generated_litecoin_datadir/blocks" \ - --exclude="volumes/generated_litecoin_datadir/chainstate" \ - --exclude="volumes/generated_litecoin_datadir/debug.log" \ + --exclude="volumes/generated_bitcoin_datadir/_data/blocks" \ + --exclude="volumes/generated_bitcoin_datadir/_data/chainstate" \ + --exclude="volumes/generated_bitcoin_datadir/_data/debug.log" \ + --exclude="volumes/generated_bitcoin_datadir/_data/testnet3/blocks" \ + --exclude="volumes/generated_bitcoin_datadir/_data/testnet3/chainstate" \ + --exclude="volumes/generated_bitcoin_datadir/_data/testnet3/debug.log" \ + --exclude="volumes/generated_bitcoin_datadir/_data/regtest/blocks" \ + --exclude="volumes/generated_bitcoin_datadir/_data/regtest/chainstate" \ + --exclude="volumes/generated_bitcoin_datadir/_data/regtest/debug.log" \ --exclude="volumes/generated_postgres_datadir" \ + --exclude="volumes/generated_tor_relay_datadir" \ --exclude="volumes/generated_clightning_bitcoin_datadir/_data/lightning-rpc" \ --exclude="**/logs/*" \ -cvzf "$backup_path" "$dbdump_name" volumes/generated_* diff --git a/deployment/btcpayserver/run_setup.sh b/deployment/btcpayserver/stub_btcpay_setup.sh similarity index 98% rename from deployment/btcpayserver/run_setup.sh rename to deployment/btcpayserver/stub_btcpay_setup.sh index 2b66b41..36c3c9e 100755 --- a/deployment/btcpayserver/run_setup.sh +++ b/deployment/btcpayserver/stub_btcpay_setup.sh @@ -59,10 +59,9 @@ if [ "\$NBITCOIN_NETWORK" != regtest ]; then fi fi -# provision the btcpayserver +# run the setup script. . ./btcpay-setup.sh -i -sleep 15 EOL # send the setup script to the remote machine. diff --git a/deployment/domain_init.sh b/deployment/domain_init.sh index ab4eadd..d395965 100755 --- a/deployment/domain_init.sh +++ b/deployment/domain_init.sh @@ -36,8 +36,7 @@ function prepare_host { if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then echo "INFO: new machine detected. Provisioning BTCPay server scripts." - - ./btcpayserver/run_setup.sh + ./btcpayserver/stub_btcpay_setup.sh fi }