LVM PART 1 data restore after accidental removal of logical volume

 Data Restore after  accidental  remove/delete of logical volume                     
Preparing  testing enviroment :

After creating partition use below command

partx        /dev/sda
pvcreate     /dev/sda4   /dev/sda5
vgcreate  VG1    /dev/sda4 /dev/sda5
vgs                                                              #display vg's
lvcreate  -L  4G -n  lv001   VG1
lvscan         or           lvdisplay


mke2fs -t  ext4  -j  
/dev/volgroup001/lv001
Add more space to logical volume (here lv001 is increased from 4gb to 6gb)
lvresize -L 6GB /dev/volgroup001/lv001                     
After resizing
 resize2fs   /dev/volgroup001/lv001

Accidental removal of logical volume

#lvremove    /dev/volgroup001/lv001     
#ll /etc/lvm/archive   ##contains the arhive of lvm data
[root@demo1 ~]# ll /etc/lvm/archive/
total 44
-rw-------. 1 root root 1761 Oct  8 15:46 vg_demo1_00000-1563239603.vg
-rw-------. 1 root root 1135 Oct 20 18:34 volgroup001_00000-1225438891.vg
-rw-------. 1 root root 1135 Oct 20 18:36 volgroup001_00001-1361506140.vg
-rw-------. 1 root root 1731 Oct 21 19:56 volgroup001_00002-1489665094.vg
-rw-------. 1 root root 1731 Oct 22 18:46 volgroup001_00003-1149849750.vg
-rw-------. 1 root root 1733 Oct 23 10:46 volgroup001_00004-1224808495.vg
-rw-------. 1 root root 1741 Oct 23 10:46 volgroup001_00005-843600971.vg
-rw-------. 1 root root 1733 Oct 23 10:56 volgroup001_00006-965431690.vg
-rw-------. 1 root root 1734 Oct 23 13:24 volgroup001_00007-1544816747.vg
-rw-------. 1 root root 1130 Oct 23 13:29 volgroup001_00008-1538079247.vg
-rw-------. 1 root root 1552 Oct 23 18:02 volgroup001_00009-1668760531.vg

#vgcfgrestore --list  volgroup001                              

  File:        /etc/lvm/archive/volgroup001_00008-1538079247.vg
  VG name:        volgroup001
  Description:    Created *before* executing 'lvcreate -L 4G -n lv001 volgroup001'
  Backup Time:    Thu Oct 23 13:29:51 2014

  
  File:        /etc/lvm/archive/volgroup001_00009-1668760531.vg
  VG name:        volgroup001
  Description:    Created *before* executing 'lvresize -L 6GB /dev/volgroup001/lv001'
  Backup Time:    Thu Oct 23 18:02:56 2014

  
  File:        /etc/lvm/backup/volgroup001
  VG name:        volgroup001
  Description:    Created *after* executing 'lvresize -L 6GB /dev/volgroup001/lv001'
  Backup Time:    Thu Oct 23 18:02:56 2014

#######
read the description and backuptime and select the file eg. /etc/lvm/archive/volgroup001_00009-
1668760531.vg    
#######

######   NOW RESTORRING   ######

#vgcfgrestore   -f    /etc/lvm/archive/volgroup001_00009-1668760531.vg     volgroup001
#lvscan
#lvchange -ay /dev/volgroup001/lv001         ##lvchange= change attribute ,  -ay = activateall -yes
#lvscan




vgcfgrestore -f   /etc/lvm/backup/volgroup001


now mount the lvm again

=================================================================

parted
select /dev/sdb

or   parted /dev/sdb
mklabel msdos
mkpart primary 1  10GB                                #1MB to 10GB = approx. 10 GB partition is created

print  or p ##view partition table

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   21.5GB  20.9GB  primary               lvm



set   <partition-number>  lvm on
quit

partx /dev/sdb

pvcreate  /dev/sdb5 /dev/sdb6 /dev/sdb7

or

pvcreate /dev/sdb[567]

##extend volume group with name volgroup 001

vgextend  volgroup001 /dev/sdb5 /dev/sdb6 /dev/sdb7  

To expand rest of space in VG enter similar command like below:-

lvextend -l +100%FREE /dev/myvg/testlvm

No comments:

Post a Comment