Skip to content

Instantly share code, notes, and snippets.

Embed
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/copy-channel-backup-on-change.sh

#!/bin/bash
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
done

chmod +x /path/copy-channel-backup-on-change.sh

Use systemd to run as service

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

[Service]
ExecStart=/path/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 /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup

Look to see if the backup was updated

@darwin
Copy link

darwin commented Apr 8, 2019

Shameless plug: https://github.com/darwin/lnd-auto-backup

PRs welcome :-)

@rahil471
Copy link

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

https://medium.com/@rahil471/enable-channel-backups-and-fund-recovery-on-lnd-lightning-network-3f27be42eb43

Feedbacks are welcomed.

@bereska
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 copy-channel-backup-on-change.sh 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

@bereska
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

@sangaman
Copy link

sangaman commented Dec 20, 2019

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

@triplea-dev
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.

@OliverOffing
Copy link

This is great, thanks @alexbosworth.

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

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