This is a channel backup script for LND node (prepared to be installed as a systemd service).
The script uses inotifywait
to monitor for file changes and triggers a new time-stamped backup when needed.
The backup script can do anything. As an example, we provide optional backup to Amazon S3 or via rsync.
Or you can specify your own custom script.
See lightningnetwork/lnd#2313 for details.
apt install inotify-tools
git clone --depth=1 https://github.com/darwin/lnd-auto-backup.git
cd lnd-auto-backup
- create a
.envrc
with content:
# for S3 backup (optional)
# also don't forget to `apt install awscli`
# note: S3 secrets can be configured via `aws configure`
export LNDAB_S3_BUCKET=your_bucket_name
# for rsync backup (optional)
# note: ssh access keys must be configured on the machine
export LNDAB_RSYNC_TARGET=user@server:/remote/path/to/backup/dir
# for custom backup (optional)
export LNDAB_CUSTOM_BACKUP_SCRIPT=path/to/your/script.sh
# these are optional:
#
# export LND_HOME=/root/.lnd # if differs from $HOME/.lnd
# export LND_NETWORK=mainnet
# export LND_CHAIN=bitcoin
# export LNDAB_CHANNEL_BACKUP_PATH=/custom/path/to/channel.backup
# export LNDAB_VERBOSE=1
# export LNDAB_S3_BACKUP_SCRIPT=./backup-via-s3.sh
# export LNDAB_RSYNC_BACKUP_SCRIPT=./backup-via-rsync.sh
- modify
LNDAB_HOME
in./service/lnd-auto-backup.service
to point to the right directory, also review other service settings ./service/install.sh
./service/start.sh
- start it!./service/status.sh
- just to check the status./service/enable.sh
- if it looks good, enable service launching after system restart
Note: The service runs under the root privileges by default. You can change it by setting User/Group in .service
config file.
You should perform aws configure
under the same user. Or make sure $HOME/.aws
folder is at expected place with correct permissions.
- set env vars, or source
.envrc
or better usedirenv
./monitor.sh
touch /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup
./service/logs.sh
./service/status.sh
./service/stop.sh
./service/disable.sh
cd lnd-auto-backup
git pull
./service/restart.sh
# you may be prompted to do `systemctl daemon-reload` if needed, then you need to restart it again
Tested on Ubuntu 19.04 server. My lnd node runs in a docker container and I use this service to monitor changes of
channel.backup
file mapped to host machine via a docker volume.