使用LVM进行灾难恢复

公司某台AWS服务器采用LVM管理卷,然后运维不知道的情况下错误的按照了AWS官方的扩展教程,把LVM搞坏了,征兆是物理卷无法识别,卷组和逻辑卷信息也丢失。
先试试pvscan扫描一下物理卷:

[root@ip-10-0-0-108 ~]# pvscan
  No matching physical volumes found

找不到任何物理卷,试试直接恢复卷组配置:

[root@ip-10-0-0-108 backup]# vgcfgrestore --file /etc/lvm/backup/vg vg
  Couldn't read volume group metadata.
  Restore failed.

cat看一下这个文件内容,里面给出了物理卷的UUID,然后试着在 /dev/disk/by-uuid/ 下找,根本没有这个物理卷。
那么试试重建物理卷吧,希望运维的操作没把物理卷文件系统的信息给破坏掉,

[root@ip-10-0-0-108 ~]# cd /etc/lvm/archive
[root@ip-10-0-0-108 archive]# pvcreate --uuid "o3fgcd-7VRd-1B70-CDRY-4Wye-0th8-Ea3FlI" --restorefile vg_00002-1761373269.vg /dev/xvdb
  Couldn't find device with uuid o3fgcd-7VRd-1B70-CDRY-4Wye-0th8-Ea3FlI.
  Physical volume "/dev/xvdb" successfully created

再试试pvscan,这下有结果了:

[root@ip-10-0-0-108 archive]# pvscan
  PV /dev/xvdb                      lvm2 [100.00 GiB]
  Total: 1 [100.00 GiB] / in use: 0 [0   ] / in no VG: 1 [100.00 GiB]

刚才重建物理卷的时候指定了卷组的配置信息,试试逻辑卷和卷组是否也跟着恢复过来了:

[root@ip-10-0-0-108 archive]# lvscan
  No volume groups found
[root@ip-10-0-0-108 archive]# vgscan
  Reading all physical volumes.  This may take a while...
  No volume groups found

唔,那看看物理卷的信息:

[root@ip-10-0-0-108 archive]# pvdisplay
  "/dev/xvdb" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/xvdb
  VG Name
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               o3fgcd-7VRd-1B70-CDRY-4Wye-0th8-Ea3FlI

再试试从配置信息里恢复卷组:

[root@ip-10-0-0-108 archive]# cd ../backup
[root@ip-10-0-0-108 backup]# vgcfgrestore vg
  Restored volume group vg

恢复成功了,再看看卷组和逻辑卷信息:

[root@ip-10-0-0-108 backup]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg" using metadata type lvm2
[root@ip-10-0-0-108 backup]# lvscan
  inactive          '/dev/vg/lv_va' [49.99 GiB] inherit

都对了,挂载上去看看:

[root@ip-10-0-0-108 backup]# mount /dev/vg/lv_va  /vol-meeting
mount: you must specify the filesystem type

看来mount无法识别出卷的文件系统,这是卷没有被激活引起的,先看看卷的属性:

[root@ip-10-0-0-108 backup]# lvs -a -o +devices
  LV    VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert Devices
  lv_va vg   -wi------ 49.99g                                              /dev/xvdb(0)
[root@ip-10-0-0-108 backup]# lvchange -ay /dev/vg/lv_va
[root@ip-10-0-0-108 backup]# lvs -a -o +devices
  LV    VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert Devices
  lv_va vg   -wi-a---- 49.99g                                              /dev/xvdb(0)

激活了,再来挂载,成功了,文件也都还在。
之后就进行了扩容操作,扩容操作网上一搜一大堆就不写了。


Last modified on 2014-11-10