Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Last active March 29, 2024 01:33
Show Gist options
  • Save alexbosworth/2c5e185aedbdac45a03655b709e255a3 to your computer and use it in GitHub Desktop.
Save alexbosworth/2c5e185aedbdac45a03655b709e255a3 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: /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

@btckai
Copy link

btckai commented Jun 12, 2023

Hi. I am trying to get a copy of my scb. i am running umbrel on linux ubuntu 20.04. everything works as you described. But:

inotify is making a backup every minute of my channel.backup file - even when there is no change in file. i dont know how to handle this.

@S0wbear83
Copy link

Hi. I am trying to get a copy of my scb. i am running umbrel on linux ubuntu 20.04. everything works as you described. But:

inotify is making a backup every minute of my channel.backup file - even when there is no change in file. i dont know how to handle this.

you can change it like this to wait for modifications or attribute changes:
inotifywait -e modify,attrib /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup

@btckai
Copy link

btckai commented Jun 17, 2023

Hi. I am trying to get a copy of my scb. i am running umbrel on linux ubuntu 20.04. everything works as you described. But:
inotify is making a backup every minute of my channel.backup file - even when there is no change in file. i dont know how to handle this.

you can change it like this to wait for modifications or attribute changes: inotifywait -e modify,attrib /path/to/.lnd/data/chain/bitcoin/mainnet/channel.backup

I changed it to:

event=$(inotifywait --format '%e' /home/umbrel/umbrel/xxxxx) || exit
[ "$event" = "MODIFY" ] && cp /home/umbrel/umbrel/xxxxxxx home/umbrel/umbrel/backup/xxxxx
done

will try your command too. thank you for that. awesome work!

@Hermit-Tango
Copy link

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

Hey I have a few questions, do you mind answering them if you got the time?? I just set up my Raspiblitz node too!

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