Important: You should only follow the steps in this document if you’ve lost all
nodes of your LiteFS cluster. Otherwise, you can
restore from a LiteFS Cloud backup.
Start your app up with only the primary node
It’s simpler to recover a single node, rather than several nodes, so to start out with, it’s best to remove all replica nodes and run just a primary node. If your app hasn’t already restarted before you got here, just restart it with only the primary node and move on to the next step! If your app has already restarted with multiple nodes running, you should temporarily remove all of the replicas. If you’re running your app on the Fly Platform, you can see the machines running your app with:replica:
fly status after you’re done, to confirm you only have the primary running.
Find the correct cluster id
When your app restarted, LiteFS generated a new cluster id, which is different than the cluster id stored in LiteFS Cloud. This is a safety measure: we don’t want to accidentally overwrite data in a cluster if you inadvertently set the wrong LiteFS Cloud token for the app. You’ll see some error messages in the LiteFS logs, similar to this:LFSC25AD000F32ED02A9 in
our example. Copy this value to use later.
Update the cluster id
Now that you have the correct cluster id, you can connect to your primary node and update the cluster id file. If your app is deployed on the Fly Platform, you can connect with:clusterid file:
Resolve consul key error
If you’re running on the Fly Platform (or you’re using Consul for lease management elsewhere), you may see the following errors in your logs:- change the Consul key value that LiteFS uses. This is easy, but leaves extra Consul keys set.
- remove the “wrong” key from Consul. This is more difficult but cleaner.
Easy option: change the Consul key
You can simply update thelease.consul.key value in the litefs.yml file. The old one will
still exist in Consul, but LiteFS won’t care. For example, you can just add -v2 to the end
of the Consul key value:
Cleaner option: remove the wrong key from Consul
First, you’ll need to addconsul in your image. Connect to your primary node via ssh, and
install it there. Here’s how to install it:
FLY_CONSUL_URL:
https://:{TOKEN}@{HOST}/{PREFIX}. You’ll need each of these values
separately. You’ll also need the value of lease.consul.key from your litefs.yml file.
Then use the Consul CLI to delete the key with:
Add your replicas back
Once your primary node is connected to LiteFS Cloud again and your data has been recovered, you should go ahead and scale back up. If you’re using the Fly Platform, that probably looks something like this (replacingord
with the region you’d like to run your new replica in):