Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save echennells/9b6845a9e11d79a46a830bae52cc079f to your computer and use it in GitHub Desktop.
Save echennells/9b6845a9e11d79a46a830bae52cc079f to your computer and use it in GitHub Desktop.
Backup channel.backup file using systemd and inotify

LND backup script for channel.backup using inotify

Install inotify

sudo apt install inotify-tools

Create script to watch for changes and copy on change

Create a script file at the path of your choice: sudo nano /usr/local/bin/copy-channel-backup-on-change.sh

#!/bin/bash
while true; do
    inotifywait /home/ubuntu/.lnd/data/chain/bitcoin/mainnet/channel.backup
    cp /home/ubuntu/.lnd/data/chain/bitcoin/mainnet/channel.backup /mnt/bitcoin/channel.backup
done

chmod +x /usr/local/bin/copy-channel-backup-on-change.sh

Use systemd to run as service

Create file: sudo nano /etc/systemd/system/backup-channels.service

[Service]
ExecStart=/usr/local/bin/copy-channel-backup-on-change.sh
Restart=always
RestartSec=1
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=backup-channels
User=ubuntu
Group=ubuntu

[Install]
WantedBy=multi-user.target

Start

sudo systemctl start backup-channels

Monitor

journalctl -fu backup-channels

Run at boot

sudo systemctl enable backup-channels

Check that the backup is working

touch /home/ubuntu/.lnd/data/chain/bitcoin/mainnet/channel.backup

Look to see if the backup was updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment