1. 程式人生 > 其它 >記錄一次生產環境LVM中誤操作刪除VG卷組恢復過程

記錄一次生產環境LVM中誤操作刪除VG卷組恢復過程

場景描述:ORacle伺服器中的資料盤容量已滿,需要將其資料目錄遷移到1.8T的SATA盤中,當時午睡醒來有些迷糊,誤將oracle資料目錄解除安裝並將其所在的磁碟刪除VG卷組以及格式化磁碟;
將oracle資料目錄遷移到新做好檔案系統的盤中,發現數據空空,資料丟失;當時在這之前這臺機器中並未對oracle資料庫進行資料備份;在解決資料恢復問題之後,將誤操作和資料恢復過程重新演繹並展現如下以供學習參考:

誤操作過程:

[root@test01 ~]# umount /data01/

[root@test01 ~]# lvremove /dev/vgsata_01_J/lv_01 
Do you really want to remove active logical volume vgsata_01_J
/lv_01? [y/n]: y Logical volume "lv_01" successfully removed [root@test01 ~]# vgremove /dev/vgsata_01_J Volume group "vgsata_01_J" successfully removed [root@test01 ~]# pvremove /dev/sdb Labels on physical volume "/dev/sdb" successfully wiped. [root@test01 ~]# mkfs.xfs /dev/sdb meta-data=/dev/sdb isize=512
agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming
=version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@test01 ~]# mount /dev/vgsata_02_J/lv_01 /data02/ [root@test01 ~]# ls (此處發現目錄為空,這時已經意識到問題的嚴重性) 在/etc/lvm/存放著LVM的配置、歸檔、備份等資訊,當我們在操作vgcreate、vgreduce、vgremove、lvcreate、lvreduce、lvremove等命令時均會生成新的歸檔資訊;因此在/etc/lvm/archive/中發現曾經丟失的vg卷組。

資料恢復過程:

[root@test01 /etc/lvm/archive]# vgcfgrestore -f /etc/lvm/archive/vgsata_01_J_00000-1917780534.vg vgsata_01_J
  Couldn't find device with uuid zSvIeb-Hpsb-U0Fy-XGjS-Od3N-BQ19-dUkM3n.
  Cannot restore Volume Group vgsata_01_J with 1 PVs marked as missing.
  Restore failed.
這裡發現無法找到uuid為“uuid zSvIeb-Hpsb-U0Fy-XGjS-Od3N-BQ19-dUkM3n” 的pv卷組。
[root@test01 /etc/lvm/archive]# vim /etc/lvm/archive/vgsata_01_J_00000-1917780534.vg vgsata_01_J
這裡通過檢視卷組檔案驗證了缺少pv卷組。

這時直接強制建立pv,看看能不能成功,看接下來的一步
[root@test01 ~]# pvcreate /dev/sdb --uuid zSvIeb-Hpsb-U0Fy-XGjS-Od3N-BQ19-dUkM3n --restorefile /etc/lvm/archive/vgsata_01_J_00000-1917780534.vg
  Couldn't find device with uuid zSvIeb-Hpsb-U0Fy-XGjS-Od3N-BQ19-dUkM3n.
  Physical volume "/dev/sdb" successfully created.
  
此處已經建立成功
再次嘗試之前的恢復操作
[root@test01 /etc/lvm/archive]# vgcfgrestore -f /etc/lvm/archive/vgsata_01_J_00000-1917780534.vg vgsata_01_J
  Restored volume group vgsata_01_J
  
此時發現vgsata_01_J卷組已經找回
[root@test01 /etc/lvm/archive]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               vgsata_02_J
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               0
  Allocated PE          2559
  PV UUID               5WjGm3-d9fM-O7Bv-kp0z-vM8Q-ds2w-aUwEke
   
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vgsata_01_J
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               2559
  Allocated PE          0
  PV UUID               zSvIeb-Hpsb-U0Fy-XGjS-Od3N-BQ19-dUkM3n
 
然而並未出現 vgsata_01_J
[root@test01 /etc/lvm/archive]# ls /dev/vg
vga_arbiter  vgsata_02_J/ 

[root@test01 /etc/lvm/archive]# vgscan
  Reading volume groups from cache.
  Found volume group "vgsata_02_J" using metadata type lvm2
  Found volume group "vgsata_01_J" using metadata type lvm2
 
 儘管卷組已經恢復,但是需要將卷組啟用才可以使用;以下是卷組啟用過程中的嘗試:
[root@test1 /etc/lvm/archive]# vgchange -ay vgsata_01_J
  0 logical volume(s) in volume group "vgsata_01_J" now active
  
[root@test1 /etc/lvm/archive]# vgcfgrestore -f /etc/lvm/archive/vgsata_01_J_00000-1398704631.vg vgsata_01_J
  Restored volume group vgsata_01_J
  
[root@test01 /etc/lvm/archive]# vgchange -ay vgsata_01_J
  0 logical volume(s) in volume group "vgsata_01_J" now active
  
[root@test01 /etc/lvm/archive]# vgcfgrestore -f /etc/lvm/archive/vgsata_01_J_00001-82901740.vg vgsata_01_J
  Restored volume group vgsata_01_J
  
[root@test01 /etc/lvm/archive]# vgchange -ay vgsata_01_J
  0 logical volume(s) in volume group "vgsata_01_J" now active
  
當操作完vgsata_01_J_00002-1786117572.vg時,發現卷組已經被激活了。
[root@test01 /etc/lvm/archive]# vgcfgrestore -f /etc/lvm/archive/vgsata_01_J_00002-1786117572.vg vgsata_01_J
  Restored volume group vgsata_01_J
  
[root@test01 /etc/lvm/archive]# vgchange -ay vgsata_01_J
  1 logical volume(s) in volume group "vgsata_01_J" now active


[root@test01 /etc/lvm/archive]# ls /dev/vg
vga_arbiter  vgsata_01_J/ vgsata_02_J/ 


掛載

# mount /dev/vgsata_01_J/lv_01 /data01/
mount: wrong fs type, bad option, bad superblock on /dev/vgsata_01_J/lv_01,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

掛載失敗,應該是檔案系統有故障,所以修復一下
修復之前先備份元資料
xfs_metadump -f /dev/vgsata_01_J/lv_01 /dev/vgsata_03_J

修復操作:
xfs_repair /dev/vgsata_01_J/lv_01

如果上條語句修復不成功,執行下一條
xfs_repair -L /dev/vgsata_01_J/lv_01(清空日誌,會丟失檔案)
說明:-L是修復xfs檔案系統的最後手段,慎重選擇,它會清空日誌,會丟失使用者資料和檔案。

重新檢查檔案系統
xfs_repair /dev/vgsata_01_J/lv_01
掛載
mount /dev/vgsata_01_J/lv_01 /data01/

恢復服務,檢查資料健全。

總結:

總結:
在對VG做變更時,切記先用vgcfgbackup備份好VG的資訊,避免意外。
[root@test01 ~]# vgcfgbackup -f /etc/lvm/backup/ vgsata_01_J

 怎麼說呢,這篇文章是在這次誤操作事故發生後近一年才寫出來的,當時的Oracle裡存的資料是很極其重要(GAJD),可想而知這次誤操作給當時的我裡留下了多大的陰影。
 我更多希望的是大家在工作中時刻牢記資料安全很重要,大腦不清醒狀態下不要去動資料;更多的是希望大家不要搜到這邊文章,因為一旦發生既是煎熬。
 感謝當時主管從公司第一時間趕過來幫我一起解決了問題,而沒有責備我什麼。