Update (08/22/2022): Just a heads up, this guide got an update for Core Lightning v0.11.2. They switched from using a backup plugin to some new built-in backup feature.
So, to keep things thorough, I’ve decided to create this separate guide just for backing up since I already have a main node setup topic. I pretty much adhere to the official guides but throw in a few adjustments where I think it could be clearer. This guide takes inspiration from the info found at https://lightning.readthedocs.io/BACKUP.html#sqlite3-wallet-main-backup-and-remote-nfs-mount.
Depending on what hardware you're using, you might find it super easy to set everything up from the start with a RAID-0 array. That’d give you a real-time mirror of your boot drive, but that’s a bit beyond what I’m focusing on here.
Part 1: Backing up your hsm_secret.
Be sure to back up your hsm_secret at least once; it’s like saving your seed words. This keeps your on-chain balance safe, but moving on to Part 2 is crucial for keeping your channel states up to date.
[1] First off, switch to an unprivileged bitcoin user and grab the hsm_secret. Use this command to open it in a text editor without saving it in your history for more security. It’s super important to write down the hex data on something physical, then close vim without saving. You can do this by accessing vim’s command prompt (just type a colon), followed by q!, making the full command :q!↵.
Part 2: Setting up automatic channel state backups
[1] Pick a backup location. Seriously, it makes zero sense to save this on the same drive, so find an external one.
C-Lightning Backup Instructions
18 replies 55 views
5il3ntstakeMember
Posts: 1 · Reputation: 92
#2Dec 14, 2023, 02:52 AM
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:
where I got this error:
Indeed, there is no file "requirements.txt" anywhere, I checked in directories backup and plugins
What is going wrong here? Please help, thanks!
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.
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#4Dec 16, 2023, 11:36 AM
This guide must be outdated. Once I run the backup-cli command, I get:
It is! I will add a red note to the original post, right now and update the guide as soon as possible. Sorry for the inconvenience!
Actually, within the backup plugin's README file, it tells you to just use poetry install. And to then invoke ./backup-cli using poetry run ./backup-cli ....
But I remember that I did minimal modification to my original install / workflow which is described here, to get it working again. It could be as simple as: pip install tqdm after Step 2. @BlackHatCoiner, this is worth trying..
I will check my history file once I find the time and have SSH access to my node (the two are not always synchronous.. ).
Thanks for the correction, i didn't notice they put README.md file on their directory. Even so, i still find wording on main README.md file means you can install dependency for all plugin using pip
I'd advice to install exact version of tqdm (pip install tqdm==4.62.3) on poerty.lock file to avoid possible package conflict.
Hey everybody! Guide fixed. At last. Replaced the backup plugin entirely in favor of the new built-in backup feature; this way we skip all this poetry packet manager stuff and the whole setup process is much cleaner and simpler to do.
I did spin up a whole new VM in which I installed Core Lightning as per my own install guide as well as following the steps I described here for backing up, so it should work, but if anyone's got any issues don't hesitate to ask.
oracle2011Member
Posts: 4 · Reputation: 92
#9Dec 21, 2023, 04:33 AM
Question:
1. Is restoring the lightning node from the same device or even an entirely different device going to cause my existing channels to close forcibly?
2. How to restore a c-lightning node? Do i simply remove the hsm_secret file and that is called a restore?
Thanks guys.
No, that's the idea of the backups. While your old / broken node is offline, the channel will just be offline. The counterparty could force-close, if they don't believe you're going to come back online, though.
If they don't, all the channels should be back just as they were before.
As the guide says:
Yes; first of all make sure you don't have a lot of funds on it.
Then, shut the node down and delete everything. You can even wipe the machine.
Or spin up a fresh Virtual Machine, or use a different device - you get the idea. The 'real' node must be offline for good, though.
Then restore your backup as explained in the guide and check that your channels are still there.
Now you know you have a good backup.
Again: it's not just about hsm_secret, if you don't have the channel state database, the channels are gone.
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#12Dec 21, 2023, 01:51 PM
From lightning.readthedocs.io:
To backup both off-chain and on-chain you need both the hsm_secret and the lightningd.sqlite3.
I'd advice Jason Brendon to test recovering a Lightning node (on-chain & off-chain funds) with fake money first (tBTC). That way, you don't need to be afraid of losing anything. That's why testnet exists. If you don't have tBTC, acquire here: https://bitcointalk.org/index.php?topic=5359454.msg57912622#msg57912622
oracle2011Member
Posts: 4 · Reputation: 92
#13Dec 21, 2023, 01:57 PM
Well, thanks, buddy. yes tBtTC, I see veterans do experiments with testnet all the time. Me haven't tried anything like that. because i am afraid of ending up messing things up....
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#14Dec 21, 2023, 04:31 PM
No problem. Just ask some in that faucet-thread.
oracle2011Member
Posts: 4 · Reputation: 92
#15Dec 21, 2023, 10:11 PM
hi op,
one question that often stays on top of my mind is that:
is the sq file constantly writing like every minute or second?
let's say I have just 5 channels open to the others. and let's say in the next 2 days, I am not receiving nor sending anything. So, the channel status stays the same, right?
my question is that: if i take the old sq file (2 days ago) and th hsm secret, will i be able to restore the node and not be punished for being caught cheating? (the sq file is 2 days old.)
need people with a confirmed answer. Thanks a lot!
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#16Dec 23, 2023, 02:46 AM
The lightningd.sqlite3 file is updated whenever there is a change in the state of the channel (such as if you send a payment, receive a payment, or route a payment). However, if you're trying to backup your wallet, this way is not recommended by the developers. It is nowhere stated that copying the database file elsewhere is safe. The backup page describes that if you want to backup your wallet, use either the --wallet parameter properly, or the backup plugin.
Not entirely correct. Even if you are not sending / receiving, someone else may use your node to route their payment, thus changing your channel states.
The recommended backup methods all update the backup automatically whenever a channel state happens.
Your manual method would not work, if you only update backups whenever you make payments. You'd have to keep track of every payment going through your node, at which point you're simply coding the backup plugin all over again.
oracle2011Member
Posts: 4 · Reputation: 92
#18Dec 23, 2023, 12:30 PM
great. thank you two for the explanation.
One other question, considering that i don't have many channels open. Is there an intensive writing to the disk? the reason i am asking is i am considering buying a tf card or a usb. If it requires constant and high density writing, i need to buy a good tf card. If not, i will just buy a cheaper one..
This seems interesting. I would try to use it for my next project. Is this guide still up to date?
Related topics
- My experience running a Lightning Network node 19
- Proposal for Simplified Lightning Channel Closures 6
- Radar.Chat secure messaging app with Bitcoin lightning payments 10
- Using the lightning network for anonymous crypto 19
- Ways to monitor lightning network payments 8
- Setting up Zeus with Lightning Terminal for Family Wallets 6