Skip to content

Instantly share code, notes, and snippets.

@johnongit
Last active August 18, 2019 09:04
Show Gist options
  • Save johnongit/2b28b2b943775926d20adb0891639a7a to your computer and use it in GitHub Desktop.
Save johnongit/2b28b2b943775926d20adb0891639a7a to your computer and use it in GitHub Desktop.
#!/bin/bash
# lnd location (usually $HOME/.lnd on linux)
LND_DIR=""
# You backup directory
BACKUP_DIR=""
# Password used to unlock lnd wallet (base64 format)
# On unix system, run this command to convert your password to base64 > printf '%s' "MyPassword" | base64
LND_PASS_WALLET=""
# Don't modify this one
MACAROON_HEADER="Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 ${LND_DIR}/data/chain/bitcoin/mainnet/admin.macaroon)"
lncli --lnddir=$LND_DIR stop
# wait until lnd stop
while pgrep -x lnd > /dev/null; do
echo "LND has not yet stopped. Waiting 3 more seconds"
sleep 3
done
rsync --progress -aAXz -v $LND_DIR $BACKUP_DIR
echo "Backup done"
echo "start lnd"
screen -S lnd1 -d -m bash -c "lnd --lnddir=$LND_DIR"
sleep 2
screen -ls
echo "lnd started... unlock wallet"
sleep 1
echo $MACAROON_HEADER
curl --cacert $LND_DIR/tls.cert --header "$MACAROON_HEADER" https://localhost:8080/v1/unlockwallet -d '{ "wallet_password":'\"$LND_PASS_WALLET\"' }' -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment