Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lnd-channels-backup-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# run as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root."
echo "Use the command 'sudo su -' and try again"
exit 1
fi

# generate LND backup ssh key
if [ -f /root/.ssh/lnd_backup ]; then
echo "Key exists"
else
echo "Generating SSH key"
ssh-keygen -o -a 100 -t ed25519 -f /root/.ssh/lnd_backup -N ''
fi

# check and install rsync and inotify
echo "Checking rsync and inotify..."
for pkgs in rsync inotify-tools; do
if [ $(dpkg -s $pkgs 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
echo "$pkgs is already installed "
else
apt -yy install $pkgs
echo "Successfully installed $pkgs "
fi
done

# check and install rclone
echo "Checking rclone..."
if command -v rclone 2>/dev/null -eq 1; then
echo "rclone is already installed"
else
curl https://rclone.org/install.sh | bash
echo "Successfully installed rclone"
fi
23 changes: 23 additions & 0 deletions lnd-channels-backup-systemd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

sudo su -

echo "Adding backup-channels.service to systemd"
echo "
[Service]
ExecStart=/root/btcpayserver/lnd-channels-remote-backup-on-change.sh
Restart=always
RestartSec=1
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=backup-channels
User=root
Group=root

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/backup-channels.service

systemctl daemon-reload
systemctl start backup-channels
systemctl enable backup-channels
echo "OK"
23 changes: 23 additions & 0 deletions lnd-channels-remote-backup-on-change.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This script is inspired by Alex Bosworth's idea to automate static channels backup (SCB) on local disk
# https://gist.github.com/alexbosworth/2c5e185aedbdac45a03655b709e255a3
# However one more step is required to instantly backup the latest SCB on a remote server (off-site) in case of LND server crash.
# This script will copy SCB to remote server(s) and/or cloud storage(s) of your choice.


lnd_channel_backup="/var/lib/docker/volumes/generated_lnd_bitcoin_datadir/_data/data/chain/bitcoin/mainnet/channel.backup"
key="/root/.ssh/lnd_backup"

# You need provide your remote server credentials and rclone remote name below after copying btcserver ssh key to remote servers
# and/or configuring rclone accordingly.
# You can add as many remote servers and clouds as you want by adding extra variables and modifying the script

remote_server1="YOUR_REMOTE_SERVER_USER_NAME@YOUR_REMOTE_SERVER_IP:~/btcpayserver/"
cloud1="YOUR_RCLONE_REMOTE:btcpayserver/"

while true; do
/usr/bin/inotifywait -r -e modify,attrib,close_write,move,create,delete ${lnd_channel_backup}
/usr/bin/rsync -az -e "ssh -i ${key}" ${lnd_channel_backup} ${remote_server1}
/usr/bin/rclone sync ${lnd_channel_backup} ${cloud1} --config /root/.config/rclone/rclone.conf
done