<p>As pointed out in similar questions backups are tricky with lightning. In the case of lightning each payment channel is a 2 of 2 multisig wallet. One of the keys is in your possession and it differs for each channel but in generally is derived from your master key.</p>

<p>The masterkey in c Lightning is 32 byte and stored in binary in <code>./lightning/hsm_secret</code> </p>

<p>Unluckily it is not sufficient to backup your masterkey. Every channel has a so called state and an old state of the channel will yield problems (potentially a forceful close of the channel partner and them being able to claim your funds.) </p>

<p>So here is what should happen :
If you turn off your node and make a backup of your lightning dir you will be able to restore that backup on this or a different machine and after turning on your lightning node everything should work as before. </p>

<p>If however you change channel state before restori g your backup your channel partner and you will most likely see a mismatch and fail the channel which means they publish their latest state. If you are lucky it is your partner and you can claim your outputs. If not it is your node and your partner will probably throw in their penalty tx to claim all coins of the channel due to the channel breach. </p>

<p>Generally under the hood after restart of a lightning node all peers are being connected again. If that does not work (because the other node might be offline) there will be inactive channels. </p>

CC BY-SA 4.0
2019-04-29T13:16:32.700Z
It's worth pointing out that state changes happen automatically, e.g., fee changes and HTLC forwarding, so it should never be considered safe to restore if the node had been running inbetween. Shutting down, migrating, the restarting is ok, put one must be absolutely sure the node hadn't been running in the interim.

With `option_dataloss_protection`, now enabled with all up to date implementations, no node should ever inadvertently cheat, but at that point you're at the mercy of the counterparty (see criticism of LNDs SCB scheme).
cdecker
CC BY-SA 4.0
2019-04-29T15:46:21.800Z
After restore i have now about 20 inactive channels. I can connect to almost every node (some nodes went offline) but this doesnt restore channel state to active even after 15 minutes. i have a bunch of inactive channels but what to do now? i cannot close these channels, i am getting "this channel is inactive". Both sides are online. as i understand there is some timeout which will be reached and then channel will auto-close? am i right?
baysx
CC BY-SA 4.0
2019-04-29T16:08:03.467Z
It seems that i got expensive lesson about backups :) channels now are closing, i see that onchain funds appear, but it looks that i loosed already about 15% of funds that was on channels. We'll see what happens next, i have still about 50% offchain on inactive channels. What keywords should be searched in logs to see was there claim for all funds on other side or not?
baysx
CC BY-SA 4.0
2019-05-02T11:05:40.417Z
Interesting fact, but almost all my funds appeared few days later after running dev-rescan-outputs (lasted quite long). Anyway, i think this is lucky case and you should not run 'old backup' version in online mode if you have chances to recover the last one node state. In my case i was doing exactly wrong way and ran 'last_state" then 'prev_state' then again 'last_stait'. On second step i had many messages in logfile about 'Recovering funds!' events, so you should not allow to happen this for best experience. anyway, i am happy that protocol itself is pretty fail-proof.
baysx
CC BY-SA 4.0
2019-05-02T13:38:55.390Z
Could be that your node detected problems, failed the channel with force closing newest state. In that case there was a timelock on your funds. Your lightning node keeps track of them and redeems them after the timelock this could be the reason why funds did not appear directly
Rene Pickhardt
CC BY-SA 4.0
2019-04-29T12:20:38.040Z
2019-04-29T12:20:38.040Z
Rene Pickhardt
<p>I have LN node running on c-lightning. I am performing ~/.lightning dir backups time-to-time.</p>

<p>Let's say after backup i open few new channels and withdraw rest of onchain funds to my electrum. Then i restore a backup.</p>

<p>What will happen to my node and its channels?</p>

<p>P.S. i have tried such scenario once. Onchain funds status after backup restore become 'spent'. i had to launch 'lightning-cli dev-rescan-outputs' to refresh onchain funds and get actual status. While my node lists channels in 'listfunds', i see that those channels become inactive. What is happening under the hood? what is the correct way of making and restoring node backups?</p>

<lightning-network><backup><core-lightning>
Question regarding LN node backups
baysx
# Question regarding LN node backups

(Asked by: username_0 on 2019-04-29)

I have LN node running on c-lightning. I am performing ~/.lightning dir backups time-to-time.

Let's say after backup i open few new channels and withdraw rest of onchain funds to my electrum. Then i restore a backup.

What will happen to my node and its channels?

P.S. i have tried such scenario once. Onchain funds status after backup restore become 'spent'. i had to launch 'lightning-cli dev-rescan-outputs' to refresh onchain funds and get actual status. While my node lists channels in 'listfunds', i see that those channels become inactive. What is happening under the hood? what is the correct way of making and restoring node backups?

**Tags:** lightning-network, backup, core-lightning


---

## 1 answers

### Answer by username_1 on 2019-04-29. Score: 2 | Accepted answer

As pointed out in similar questions backups are tricky with lightning. In the case of lightning each payment channel is a 2 of 2 multisig wallet. One of the keys is in your possession and it differs for each channel but in generally is derived from your master key.

The masterkey in c Lightning is 32 byte and stored in binary in `./lightning/hsm_secret`

Unluckily it is not sufficient to backup your masterkey. Every channel has a so called state and an old state of the channel will yield problems (potentially a forceful close of the channel partner and them being able to claim your funds.)

So here is what should happen :
If you turn off your node and make a backup of your lightning dir you will be able to restore that backup on this or a different machine and after turning on your lightning node everything should work as before.

If however you change channel state before restori g your backup your channel partner and you will most likely see a mismatch and fail the channel which means they publish their latest state. If you are lucky it is your partner and you can claim your outputs. If not it is your node and your partner will probably throw in their penalty tx to claim all coins of the channel due to the channel breach.

Generally under the hood after restart of a lightning node all peers are being connected again. If that does not work (because the other node might be offline) there will be inactive channels.

> **Comments:**
> **username_2**: It's worth pointing out that state changes happen automatically, e.g., fee changes and HTLC forwarding, so it should never be considered safe to restore if the node had been running inbetween. Shutting down, migrating, the restarting is ok, put one must be absolutely sure the node hadn't been running in the interim.  With `option_dataloss_protection`, now enabled with all up to date implementations, no node should ever inadvertently cheat, but at that point you're at the mercy of the counterparty (see criticism of LNDs SCB scheme).  
> **username_0**: After restore i have now about 20 inactive channels. I can connect to almost every node (some nodes went offline) but this doesnt restore channel state to active even after 15 minutes. i have a bunch of inactive channels but what to do now? i cannot close these channels, i am getting "this channel is inactive". Both sides are online. as i understand there is some timeout which will be reached and then channel will auto-close? am i right?  
> **username_0**: It seems that i got expensive lesson about backups :) channels now are closing, i see that onchain funds appear, but it looks that i loosed already about 15% of funds that was on channels. We'll see what happens next, i have still about 50% offchain on inactive channels. What keywords should be searched in logs to see was there claim for all funds on other side or not?  
> **username_0**: Interesting fact, but almost all my funds appeared few days later after running dev-rescan-outputs (lasted quite long). Anyway, i think this is lucky case and you should not run 'old backup' version in online mode if you have chances to recover the last one node state. In my case i was doing exactly wrong way and ran 'last_state" then 'prev_state' then again 'last_stait'. On second step i had many messages in logfile about 'Recovering funds!' events, so you should not allow to happen this for best experience. anyway, i am happy that protocol itself is pretty fail-proof.  
> **username_1**: Could be that your node detected problems, failed the channel with force closing newest state. In that case there was a timelock on your funds. Your lightning node keeps track of them and redeems them after the timelock this could be the reason why funds did not appear directly  

---

