Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Last active March 29, 2024 01:33
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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

@bylynda1
Copy link

Frame-235-1-768x827
Frame-237-768x827
Frame-235-768x827
IMG-20231127-WA0002(2)
IMG-20231129-WA0000
bitcoin_bc1q99hqt7s4zdg60cekdetetwkkw3gw6c4v7try3u (1)
IMG-20231128-WA0006
IMG-20230820-WA0009(3)
IMG-20230820-WA0009(2)
Screenshot_20231128-031008
chrome_qrcode_1701059125000 (1)
chrome_qrcode_1701059125000
bnb_0x55d398326f99059ff775485246999027b3197955~3
bnb_0x55d398326f99059ff775485246999027b3197955~2
Screenshot_20231124-042553
Screenshot_20231123-180118
IMG-20231120-WA0000
IMG_20231118_021406_003
IMG_20231115_224746_297
IMG_20231115_224402_033
IMG_20231115_224400_435
bitcoin_3KsBrnzePWAicXZy5vQjudzqDswSW7UZty
IMG_20231114_185629_036
Screenshot_20231103-044524
Screenshot_20231103-013612
bitcoin_1GVt7MRgh8FrUjGT3pX8pFfBaevyyGJbHV (1)
bitcoin_1GVt7MRgh8FrUjGT3pX8pFfBaevyyGJbHV
IMG_20231103_011413_502_transcpr
IMG_20231103_011405_308_transcpr
IMG_20231103_011204_709_transcpr
IMG_20231103_011203_409_transcpr
IMG_20231103_011159_773_transcpr
IMG-20231101-WA0001
Screenshot_20231030-183813
Screenshot_20231027-225148
Screenshot_20231019-193739
bitcoin_bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh (1)
Screenshot_20231018-154132
Screenshot_20231018-154015
Screenshot_20231018-052506
Screenshot_20231018-031322

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