Each replica of a Longhorn volume contains the full data for the volume.
If the whole Kubernetes cluster or Longhorn system goes offline, the following steps can be used to retrieve the data of the volume.
Check the path found in step 1 to see if it contains the data.
The data will be stored in the
/replicas
directory, for example:# ls /var/lib/longhorn/replicas/
pvc-06b4a8a8-b51d-42c6-a8cc-d8c8d6bc65bc-d890efb2
The directory naming pattern is:
So in the example above, there are two volumes stored here, which are
pvc-06b4a8a8-b51d-42c6-a8cc-d8c8d6bc65bc
and .The volume name matches the Kubernetes PV name.
-
# lsof pvc-06b4a8a8-b51d-42c6-a8cc-d8c8d6bc65bc-d890efb2/
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
The above result shows that the data directory is still being used, so don’t proceed to the next step. If it’s not being used,
lsof
command should return empty result. Check the volume size of the volume you want to restore using the following command inside the directory:
From the result above, you can see the volume size is (1 GiB). Note the size.
To export the content of the volume, use the following command to create a single replica Longhorn volume container:
docker run -v /dev:/host/dev -v /proc:/host/proc -v <data_path>:/volume --privileged longhornio/longhorn-engine:v1.3.0 launch-simple-longhorn <volume_name> <volume_size>
For example, based on the information above, the command should be:
Result: Now you should have a block device created on /dev/longhorn/<volume_name>
for this device, such as /dev/longhorn/pvc-06b4a8a8-b51d-42c6-a8cc-d8c8d6bc65bc
for the example above. Now you can mount the block device to get the access to the data.
After you are done accessing the volume content, use to stop the container. The block device should disappear from the /dev/longhorn/
directory after the container is stopped.