如何使用 vgcfgrestore 在 LVM 中恢复已删除的逻辑卷 (LV)

我们不小心从卷组 vg01 中删除了逻辑卷 lv01.
现在我们想在不丢失数据的情况下恢复 LV。
按照下面给出的步骤在 VG (vg01) 下恢复 LV (lv01)。

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

恢复删除LV

  1. 验证删除逻辑卷时目录/etc/lvm/archive 下的归档文件。
    在我的情况下,/etc/lvm/archive 目录下具有最新时间戳的文件将包含有关已删除 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
  1. 在运行实际恢复之前,我们可以使用 -test 开关进行试运行,如下所示。
# 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
  1. 如果上述试运行成功,则进行实际恢复。
# vgcfgrestore vg01  -f /etc/lvm/archive/vg01_00002-1315455408.vg 
  Restored volume group vg01
  1. 使用“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
  1. 如输出所示,逻辑卷 lv01 从 VG 的元数据备份中成功恢复。
    激活 LV 以访问其上的数据。
# lvchange -a y /dev/vg01/lv01
  1. 挂载逻辑卷,验证数据是否完整。
# 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
日期:2020-09-17 00:13:46 来源:oir作者:oir