Skip to content

Instantly share code, notes, and snippets.

@janvojt
Last active May 23, 2021 13:06
Show Gist options
  • Save janvojt/98685978cb1b7a79e8ef8648934ab684 to your computer and use it in GitHub Desktop.
Save janvojt/98685978cb1b7a79e8ef8648934ab684 to your computer and use it in GitHub Desktop.
#!/bin/bash
CONF="$HOME/.lnd-backup.conf"
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Create configuration file at '${CONF}' with the below variables:"
echo
echo "LND_PATH path to lnd configuration directory, can be absolute or relative to current working directory"
echo "REMOTE_PATH ssh-compatible specification to the directory where backup will be uploaded via scp"
echo "TMP_DIR temporary directory for caching encrypted files, will be created if it does not exist, e.g.: /tmp/backup-lnd"
echo "PASSPHRASE symmetric encryption passphrase"
exit
fi
if [[ ! -f "${CONF}" ]]; then
echo "Could not find configuration file at '${CONF}'."
exit
fi
source "${CONF}"
while true; do
inotifywait "${LND_PATH}/data/chain/bitcoin/mainnet/channel.backup"
TODAY=$(date +%Y-%m-%d)
mkdir -p "${TMP_DIR}"
echo "${PASSPHRASE}" | gpg --batch --yes --passphrase-fd 0 \
--output "${TMP_DIR}/${TODAY}_channel.backup.enc" \
--symmetric --cipher-algo AES256 \
"${LND_PATH}/data/chain/bitcoin/mainnet/channel.backup"
scp "${TMP_DIR}/${TODAY}_channel.backup.enc" "${REMOTE_PATH}"
rm -rf "${TMP_DIR}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment