Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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: /path/

while true; do
    inotifywait /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup
    cp /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup /backup/path/channel.backup

chmod +x /path/

Use systemd to run as service

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




sudo systemctl start backup-channels


journalctl -fu backup-channels

Run at boot

sudo systemctl enable backup-channels

Check that the backup is working

touch /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup

Look to see if the backup was updated

Copy link

darwin commented Apr 8, 2019

Shameless plug:

PRs welcome :-)

Copy link

I have jotted down a guide based on my experience of working with SCB.

Feedbacks are welcomed.

Copy link

bereska commented May 11, 2019

this is awesome. Trying to set it up on my raspiblitz where bitcoin and lnd were manually installed. The problem is I have 3 users: admin, bitcoin and root; and the channel.backup is in /home/bitcoin/.lnd/data/chain/bitcoin/mainnet, but I can only ssh to raspiblitz as admin. So I created in /home/bitcoin as root for the script to copy channel.backup to /home/admin/backup so as I could rsync it there from a remote machine. The question is how to create a systemd service for it to work correctly? Thank you

Copy link

bereska commented May 13, 2019

never mind, sorry for wasting your time if any, i figured it all out. My channel.back is being rsynced to two remotes. Thanks for guidance

Copy link

sangaman commented Dec 20, 2019

What are the pros/cons of using this approach vs lsyncd? Or is it basically the same?

Copy link

The benefit of this (the above) method is that it uses standard OS tools (cp file).
You could mount a backup disk (remote or cloud storage for example) and just copy the file to that mount point.
Easier to trust when you know exactly what's happening.

Copy link

This is great, thanks @alexbosworth.

Worth noting that people might want to add the script a call to just in case.

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