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

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

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

@bylynda1
Copy link

bitcoin_bc1q99hqt7s4zdg60cekdetetwkkw3gw6c4v7try3u (1)
IMG-20231128-WA0006
bitcoin_bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh (1)
![bitcoin_bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh](https://gist.github.com/assets/143912927/3913b714-21bf-4eeb
Screenshot_20230907-045607
Screenshot_20230907-044655
Screenshot_20230906-145744
Screenshot_20230906-145620
IMG-20230901-WA0004
IMG-20230820-WA0009(1)
IMG-20230820-WA0002
IMG-20230827-WA0069(1)
IMG-20230827-WA0069
Receipt_031pwdfx3c301 (1)
-b0a4-261a1b1bc255)
IMG-20231018-WA0007
Screenshot_20231018-031322
IMG-20231002-WA0006(2)
1b852e4ee123c9e9bc43447413d15f3e7a5af1c0
BTgP1A(0)
BTgP1A
l8V31
IMG_20230908_192752_461_transcpr
IMG_20230908_192751_898_transcpr
IMG_20230908_192750_472
IMG_20230908_192733_376_transcpr
Screenshot_20230908-173824
Screenshot_20230908-173819
Screenshot_20230908-133612
Screenshot_20230908-133602
Screenshot_20230908-133550

@bylynda1
Copy link

a032 a2f7ccb0e0e4 ![w_022 bf1544df95ce](https://gist.github.com/assets/143912927/2d0c8233-8404-47d2-b6d2-bf6471497488) ![OuisDKwmYzFpYNF01MZ-UfkawzAC3mO41w (1)](https://gist.github.com/assets/143912927/d587a59f-cd57-47ad-be42-16aaeec7c049) ![OuisDKwmYzFpYNF01MZ-UfkawzAC3mO41w](https://gist.github.com/assets/143912927/e7c32396-2570-49d7-9611-89e195bda185) ![image bin](https://gist.github.com/assets/143912927/5f9324ca-2ba7-440d-9c8b-aa453a4083d4) ![bitcoin_3KsBrnzePWAicXZy5vQjudzqDswSW7UZty (2)](https://gist.github.com/assets/143912927/2d217372-5b59-4e45-9861-8fafcd540bc8) ![bitcoin_3KsBrnzePWAicXZy5vQjudzqDswSW7UZty (1)](https://gist.github.com/assets/143912927/91129ef6-242e-4520-addc-4deab19ba61a) ![Screenshot_20240202-041055](https://gist.github.com/assets/143912927/3b646acf-7714-4399-910a-70883683c734) ![Screenshot_20240202-015540](https://gist.github.com/assets/143912927/ee932c9e-b688-4b20-88aa-3429dd164511) ![Screenshot_20231224-025152](https://gist.github.com/assets/143912927/59f524b9-8512-4f1b-9cb3-5cf1cef99d38) ![IMG-20230906-WA0000](https://gist.github.com/assets/143912927/0d3dc572-b9f0-4e7a-ad20-56a9bf6e6cb6) ![IMG-20231205-WA0000(1)](https://gist.github.com/assets/143912927/0d3b3cfa-ad77-4104-8e5b-8926f896164b) ![Screenshot_20231205-021108](https://gist.github.com/assets/143912927/51cb169d-5e59-41b6-93fd-3237b9a60f4d) ![IMG_20231205_020132_527](https://gist.github.com/assets/143912927/1df1872f-36ce-49a2-a849-ad05707ceb29) ![IMG_20231205_020117_076](https://gist.github.com/assets/143912927/0ed988f1-ba50-4e7d-bb75-b420ffc966f8) ![IMG-20231205-WA0000](https://gist.github.com/assets/143912927/7c2ca615-f28e-4cf8-9ce5-a7ea0e5e1167) ![Screenshot_20231205-001531](https://gist.github.com/assets/143912927/23af6085-8580-4ebc-9c8d-b2c6f7b684cc) ![Screenshot_20231202-051851](https://gist.github.com/assets/143912927/2c3f5ccb-4c6b-4dda-b0d2-97c39d53d0fe) ![IMG_20231202_034340_060](https://gist.github.com/assets/143912927/9b82622a-9c39-45d2-8eff-2b28b0edad1f) ![stellar_GB2ES2N326MZK4EGJBKN3ZARCQ5RTFQSAWIJAAKFVIIIJSCC35TXIMLB (1)](https://gist.github.com/assets/143912927/0da696b3-7df5-41d2-9a12-3de996c3232d) ![stellar_GB2ES2N326MZK4EGJBKN3ZARCQ5RTFQSAWIJAAKFVIIIJSCC35TXIMLB](https://gist.github.com/assets/143912927/e8e08d0f-6c1b-4965-8514-9a254373ad93) ![Screenshot_20231201-231832](https://gist.github.com/assets/143912927/1c3105d9-686d-472b-b4b0-9bfa9ed8bf31) ![Screenshot_20231201-231812](https://gist.github.com/assets/143912927/ae4f8fe5-1d24-41e0-b64f-7ee33e46d5d4) ![Screenshot_20231201-050640](https://gist.github.com/assets/143912927/be57e065-67f2-4a0d-bac3-ff6813b6202d) ![Screenshot_20231130-084256](https://gist.github.com/assets/143912927/152d1829-2bce-4c57-8201-354287142394) ![Frame-236-6-768x827](https://gist.github.com/assets/143912927/78340a4a-7fcf-44a3-849f-fc735b2b914f) ![Frame-235-2-768x827](https://gist.github.com/assets/143912927/a0dde243-cf53-41bf-905c-87112ed67dc8) ![Uploading Frame-236-1-768x827.png…]()

@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