Bitcoin Forum
May 20, 2022, 08:30:15 AM *
News: Latest Bitcoin Core release: 23.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Guide] C-Lightning backup guide  (Read 152 times)
n0nce
Sr. Member
****
Offline Offline

Activity: 280
Merit: 2234


Ubi concordia, ibi victoria!


View Profile WWW
February 03, 2022, 04:47:58 AM
Last edit: February 20, 2022, 11:36:06 AM by n0nce
Merited by BlackHatCoiner (5), EFS (4), ETFbitcoin (3), bill gator (1), PrimeNumber7 (1)
 #1

For completeness sake, since I already have a topic where I walk through my main node's setup, I am creating this separate guide for backing it up.
I generally follow the official guides, with a few tweaks here and there where I think makes sense. This one here, is based on https://lightning.readthedocs.io/BACKUP.html#backup-plugin-and-remote-nfs-mount.

It is worth noting that v0.10.3 will have a built-in mechanism for backing up your LN database locally or on a network share, however it has not yet been released and I'm not sure there even exists a release candidate right now.

That's why I'd recommend continuing to use the tried and trusted backup plugin written in Python.

It's worth noting depending on your hardware, it can be trivial to setup the system from the get-go to run on a RAID-0 array, which would mean a constantly up-to-date mirror of your boot drive, but this would be out of the scope of this little guide.

Part 1: hsm_secret backup.
The hsm_secret needs to be backed up once, e.g. on paper, best even multiple copies. Think of it as a seed word backup. It secures the on-chain balance, but we will need Part 2 to always have an up-to-date backup of our channels' states.

[1] Switch to unprivileged bitcoin user and extract the hsm_secret. By using this command, it will open in the text editor and not be saved to your history for better security. It is essential to now write down the hex data on a non-digital medium and afterwards closing vim without saving the file. Do so by opening vim's command prompt (colon), followed by q!, so the whole command will look like :q!↵.
Code:
su - bitcoin
cd ~/.lightning/bitcoin
xxd hsm_secret | vim -

Part 2: Automatic channel state backups

[1] Move to your home directory and clone the C-Lightning plugin repo.
Code:
cd
git clone https://github.com/lightningd/plugins.git

[2] Change into this new folder and install the required dependencies for the backup plugin.
Code:
cd plugins
pip install -r backup/requirements.txt

[3] Choose a location for your backup. It makes 0 sense to use a location on the same drive, so it either has to be an external drive (USB / LAN share) or a remote network share. Setting this up is again outside the scope of this guide. Let's assume the location is /mnt/share/lnbackup.

[4] Stop the node and go back into bitcoin user.
Code:
exit
sudo service lightningd stop
su - bitcoin

[5] Initial channel state backup
Code:
cd ~/plugins
backup/backup-cli init --lightning-dir /home/bitcoin/.lightning/bitcoin/ file:///mnt/share/lnbackup/backup.bkp
make sure to set the correct path for your (network) share and set a name that you like, such as backup.bkp.

You shall get a result such as:
Code:
Found an existing database at /home/bitcoin/.lightning/bitcoin/lightningd.sqlite3, initializing the backup with a snapshot
Successfully written initial snapshot to file:///mnt/share/lnbackup/backup.bkp
Initialized backup backend file:///mnt/share/lnbackup/backup.bkp, you can now start c-lightning

[6] Add plugin to lightningd.conf config file.
Code:
nano /home/bitcoin/.lightning/bitcoin/lightningd.conf

Simply add a new line with:
Code:
important-plugin=/home/bitcoin/plugins/backup/backup.py

[7] Now we can start up C-Lightning again!
Code:
exit
sudo service lightningd start

[8] If you get no errors starting up the service or anything, you're good! For good measure, you could send yourself some sats from a mobile wallet, restart the service with sudo service lightningd restart and see if it's all fine.

1653035415
Hero Member
*
Offline Offline

Posts: 1653035415

View Profile Personal Message (Offline)

Ignore
1653035415
Reply with quote  #2

1653035415
Report to moderator
1653035415
Hero Member
*
Offline Offline

Posts: 1653035415

View Profile Personal Message (Offline)

Ignore
1653035415
Reply with quote  #2

1653035415
Report to moderator
1653035415
Hero Member
*
Offline Offline

Posts: 1653035415

View Profile Personal Message (Offline)

Ignore
1653035415
Reply with quote  #2

1653035415
Report to moderator
Bitcoin Layer Two Wallet with CoinSwaps Privacy
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
xyris
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
May 06, 2022, 02:31:17 PM
 #2

Hi, thanks, this is really helpful. I'm a (non-technical) Raspiblitz user and I don't have enough know-how to do a c-lightning backup just with the available (too technical) documentation I could find online.

Unfortunately I stumbled over this command:
Code:
pip install -r backup/requirements.tx
where I got this error:
Code:
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

Indeed, there is no file "requirements.txt" anywhere, I checked in directories backup and plugins

What is going wrong here? Please help, thanks!
n0nce
Sr. Member
****
Offline Offline

Activity: 280
Merit: 2234


Ubi concordia, ibi victoria!


View Profile WWW
May 06, 2022, 05:27:28 PM
 #3

~
Oh, indeed, thanks for bringing this up! It seems the file has disappeared in the last two commits (after almost a year of silence): https://github.com/lightningd/plugins/commit/42f88ce24ab0469597bed3e90754a880ac9f956d

Now somehow, they switched to poetry instead of using Python's built-in pip. I generally prefer to stick with the popular, well-known and 'tried and tested' tools. You could certainly check-out the repo at an earlier point in time (before the two commits of last week) or try doing it with poetry.

I will update my guide as soon as possible, but I can't promise that it'll happen today.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!