How to recover deleted Logical volume (LV) in LVM using vgcfgrestore

You have accidentally removed a logical volume lv01 from the Volume group vg01. Now you want to recover the LV without losing the data. Follow the steps given below to recover LV (lv01) under VG (vg01).

# lvremove vg01/lv01
Do you really want to remove active logical volume vg01/lv01? [y/n]: y
  Logical volume "lv01" successfully removed

Recovering remove LV

1. Verify the archive file under the directory /etc/lvm/archive when the logical volume was removed. In my case the file with latest timestamp under the /etc/lvm/archive directory will have the required information on the deleted volme lv01.

# cd /etc/lvm/archive/
# ls -lrt
total 16
-rw-------. 1 root root 1752 Oct 11 22:20 cl_00000-2084244320.vg
-rw-------. 1 root root 1111 Oct 13 20:05 vg01_00000-1050327195.vg
-rw-------. 1 root root 1112 Oct 13 20:06 vg01_00001-86976415.vg
-rw-------. 1 root root 1515 Oct 13 20:09 vg01_00002-1315455408.vg

2. Before running the actual restore you can do a dry run using the –test switch as shown below.

# vgcfgrestore vg01 --test -f /etc/lvm/archive/vg01_00002-1315455408.vg 
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Restored volume group vg01

3. If the above dry run is successful, do the actual restore.

# vgcfgrestore vg01  -f /etc/lvm/archive/vg01_00002-1315455408.vg 
  Restored volume group vg01

4. Verify if the deleted volume has been successfully restored or not using ‘lvscan’.

# lvscan
  inactive          '/dev/vg01/lv01' [10.00 GiB] inherit
  ACTIVE            '/dev/cl/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/cl/root' [17.00 GiB] inherit

5. As shown in the output the Logical volume lv01 is successfully restored from the metadata backup of VG. Activate the LV to access the data onto it.

# lvchange -a y /dev/vg01/lv01

6. Mount the logical volume and verify if the data is intact.

# mount /dev/mapper/vg01-lv01 /data
# ls /data
file1  file2  file3  lost+found
# df -hP /data
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01  9.8G   37M  9.2G   1% /data
Related Post