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

This comment has been minimized.

Copy link

darwin commented Apr 8, 2019

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

PRs welcome :-)

@rahil471

This comment has been minimized.

Copy link

rahil471 commented Apr 25, 2019

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

This comment has been minimized.

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

This comment has been minimized.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.