Restore volume group and logical volume

If you deleted volume group and logical volume by accident then you can follow the following procedure

lets suppose you have volume group called datavg and logical volume called backuplv and u deleted both datavg and backup lv. So to recover both you need to first run the following command

[root@puppetmaster ~]# ll /etc/lvm/archive/
total 48
-rw-------. 1 root root 3338 Apr 4 02:14 appvg_00000-271467848.vg
-rw------- 1 root root 899 Sep 21 12:25 datavg_00000-1498075142.vg
-rw------- 1 root root 907 Sep 21 12:25 datavg_00001-1837039560.vg
-rw------- 1 root root 1334 Sep 21 12:27 datavg_00002-179127577.vg
-rw------- 1 root root 889 Sep 21 12:27 datavg_00003-1722395327.vg
-rw------- 1 root root 899 Sep 21 12:33 datavg_00004-416396364.vg
-rw------- 1 root root 889 Sep 21 12:40 datavg_00005-1593003829.vg
-rw------- 1 root root 1308 Sep 21 12:44 datavg_00006-471401798.vg

here it shows i have information about appvg and datavg volume group

Since we want to recover datavg lets do

[root@puppetmaster ~]#  vgcfgrestore --list datavg

  File:         /etc/lvm/archive/datavg_00000-1498075142.vg
  VG name:      datavg
  Description:  Created *before* executing 'vgcreate datavg /dev/sdb1'
  Backup Time:  Mon Sep 21 12:25:01 2015


  File:         /etc/lvm/archive/datavg_00001-1837039560.vg
  VG name:      datavg
  Description:  Created *before* executing 'lvcreate -L 1G -n backuplv datavg'
  Backup Time:  Mon Sep 21 12:25:21 2015


  File:         /etc/lvm/archive/datavg_00002-179127577.vg
  VG name:      datavg
  Description:  Created *before* executing 'lvremove /dev/datavg/backuplv'
  Backup Time:  Mon Sep 21 12:27:03 2015


  File:         /etc/lvm/archive/datavg_00003-1722395327.vg
  VG name:      datavg
  Description:  Created *before* executing 'vgremove datavg'
  Backup Time:  Mon Sep 21 12:27:20 2015

now i need the file that has information  before removed volume group which is

 /etc/lvm/archive/datavg_00003-1722395327.vg

lets restore datavg from the point it was removed

vgcfgrestore -f /etc/lvm/archive/datavg_00003-1722395327.vg datavg

lets also restore logical volume from the point it was removed

vgcfgrestore -f /etc/lvm/archive/datavg_00002-179127577.vg datavg
[root@puppetmaster ~]# vgchange -a y datavg
 1 logical volume(s) in volume group "datavg" now active

[root@puppetmaster ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  appvg    1   6   0 wz--n- 67.75g 41.75g
  datavg   1   1   0 wz--n-  5.01g  4.01g
[root@puppetmaster ~]# lvs
  LV         VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homelv     appvg  -wi-ao---- 4.00g
  optlv      appvg  -wi-ao---- 4.00g
  tmplv      appvg  -wi-ao---- 4.00g
  usrlocallv appvg  -wi-ao---- 4.00g
  usrlv      appvg  -wi-ao---- 6.00g
  varlv      appvg  -wi-ao---- 4.00g
  backuplv   datavg -wi-a----- 1.00g

now mount the backuplv to its mount point

[root@puppetmaster ~]# mount /dev/datavg/backuplv /backup
[root@puppetmaster ~]# ls -l /backup/
total 20
-rw-r--r-- 1 root root   292 Sep 21 12:26 file.txt
drwx------ 2 root root 16384 Sep 21 12:25 lost+found

done

[Note:   If you have removed physical volume as well then]

before restoring volume group restore physical volume by

[root@puppetmaster ~]# cat /etc/lvm/archive/datavg_00003-1722395327.vg
# Generated by LVM2 version 2.02.111(2)-RHEL6 (2014-09-01): Mon Sep 21 12:27:20 2015

contents = "Text Format Volume Group"
version = 1

description = "Created *before* executing 'vgremove datavg'"

creation_host = "puppetmaster.lab" # Linux puppetmaster.lab 2.6.32-504.12.2.el6.x86_64 #1 SMP Wed Mar 11 22:03:14 UTC 2015 x86_64
creation_time = 1442856440 # Mon Sep 21 12:27:20 2015

datavg {
 id = "kHdMKi-A1q6-bLyV-lskx-9i4S-znUg-NVVgAo"
 seqno = 3
 format = "lvm2" # informational
 status = ["RESIZEABLE", "READ", "WRITE"]
 flags = []
 extent_size = 8192 # 4 Megabytes
 max_lv = 0
 max_pv = 0
 metadata_copies = 0

 physical_volumes {

 pv0 {
 id = "UT57Ru-M43y-Lr1x-g7wZ-USu6-fRG3-EJqfdN"
 device = "/dev/sdb1" # Hint only

 status = ["ALLOCATABLE"]
 flags = []
 dev_size = 10506447 # 5.00986 Gigabytes
 pe_start = 2048
 pe_count = 1282 # 5.00781 Gigabytes
 }
 }

}

create a physical volume usind physical volume id above

pvcreate --uuid "UT57Ru-M43y-Lr1x-g7wZ-USu6-fRG3-EJqfdN" --restorefile /etc/lvm/archive/datavg_00003-1722395327.vg

now after this check by pvs and if the physical volume is created follow with the procedure of restoring volume group

 

 

 

 

 

 

 

 

Leave a Reply