Skip to content

Commit d310861

Browse files
bereskabereska
authored andcommitted
lnd-channels-remote-backup-on-change
Date: Thu Feb 20 23:16:14 2020 +0300 Committer: bereska <bereska@MacBook-Air-DG-4007.local> Changes to be committed: new file: lnd-channels-backup-dependencies.sh
1 parent c223abe commit d310861

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# run as root
4+
if [ "$(id -u)" != "0" ]; then
5+
echo "This script must be run as root."
6+
echo "Use the command 'sudo su -' and try again"
7+
exit 1
8+
fi
9+
10+
# generate LND backup ssh key
11+
if [ -f /root/.ssh/lnd_backup ]; then
12+
echo "Key exists"
13+
else
14+
echo "Generating SSH key"
15+
ssh-keygen -o -a 100 -t ed25519 -f /root/.ssh/lnd_backup -N ''
16+
fi
17+
18+
# check and install rsync and inotify
19+
echo "Checking rsync and inotify..."
20+
for pkgs in rsync inotify-tools; do
21+
if [ $(dpkg -s $pkgs 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
22+
echo "$pkgs is already installed "
23+
else
24+
apt -yy install $pkgs
25+
echo "Successfully installed $pkgs "
26+
fi
27+
done
28+
29+
# check and install rclone
30+
echo "Checking rclone..."
31+
if command -v rclone 2>/dev/null -eq 1; then
32+
echo "rclone is already installed"
33+
else
34+
curl https://rclone.org/install.sh | bash
35+
echo "Successfully installed rclone"
36+
fi

lnd-channels-backup-systemd.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
sudo su -
4+
5+
echo "Adding backup-channels.service to systemd"
6+
echo "
7+
[Service]
8+
ExecStart=/root/btcpayserver/lnd-channels-remote-backup-on-change.sh
9+
Restart=always
10+
RestartSec=1
11+
StandardOutput=syslog
12+
StandardError=syslog
13+
SyslogIdentifier=backup-channels
14+
User=root
15+
Group=root
16+
17+
[Install]
18+
WantedBy=multi-user.target" > /etc/systemd/system/backup-channels.service
19+
20+
systemctl daemon-reload
21+
systemctl start backup-channels
22+
systemctl enable backup-channels
23+
echo "OK"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# This script is inspired by Alex Bosworth's idea to automate static channels backup (SCB) on local disk
4+
# https://gist.github.com/alexbosworth/2c5e185aedbdac45a03655b709e255a3
5+
# However one more step is required to instantly backup the latest SCB on a remote server (off-site) in case of LND server crash.
6+
# This script will copy SCB to remote server(s) and/or cloud storage(s) of your choice.
7+
8+
9+
lnd_channel_backup="/var/lib/docker/volumes/generated_lnd_bitcoin_datadir/_data/data/chain/bitcoin/mainnet/channel.backup"
10+
key="/root/.ssh/lnd_backup"
11+
12+
# You need provide your remote server credentials and rclone remote name below after copying btcserver ssh key to remote servers
13+
# and/or configuring rclone accordingly.
14+
# You can add as many remote servers and clouds as you want by adding extra variables and modifying the script
15+
16+
remote_server1="YOUR_REMOTE_SERVER_USER_NAME@YOUR_REMOTE_SERVER_IP:~/btcpayserver/"
17+
cloud1="YOUR_RCLONE_REMOTE:btcpayserver/"
18+
19+
while true; do
20+
/usr/bin/inotifywait -r -e modify,attrib,close_write,move,create,delete ${lnd_channel_backup}
21+
/usr/bin/rsync -az -e "ssh -i ${key}" ${lnd_channel_backup} ${remote_server1}
22+
/usr/bin/rclone sync ${lnd_channel_backup} ${cloud1} --config /root/.config/rclone/rclone.conf
23+
done

0 commit comments

Comments
 (0)