LVM Snapshots of Logical Volume on Rhel 7/Centos 7/Oracle 7 Linux are space productive pointing time duplicates of lvm volumes.
It works just with lvm and expend the space just when changes are made to the source intelligent volume to depiction volume.
If source volume has a
huge changes made to sum of 500MB the same changes will be made to the snapshot
volume.
Incase the preview comes up short on capacity, we can utilize lvextend to develop.
On the off chance that we have incidentally erased any record in the wake of making a Snapshot we don't need to stress in light of the fact that the preview have the first document which we have erased.
On the off chance that we have incidentally erased any record in the wake of making a Snapshot we don't need to stress in light of the fact that the preview have the first document which we have erased.
To remove the snapshot we can use lvremove command.
Step 1: Create LVM Snapshot
First, check for free
space in volume group to create a new snapshot.For that we are using using
following vgs command.
# vgs
VG #PV #LV #SN Attr
VSize VFree
VolGroup 1 2 0
wz--n- 7.51g 0
testvg 2 1 0
wz--n- 3.99g 1.99g
# lvs
LV
VG
Attr LSize Pool Origin Data% Move Log Cpy%Sync
Convert
lv_root VolGroup -wi-ao----
6.71g
lv_swap VolGroup -wi-ao---- 816.00m
testlv testvg -wi-ao---- 2.00g
You see, there is 1.99GB
of free space left in above vgs output. So, let’s create a snapshot for one of
my volume named testlv.
For an example we are
going to create only 1GB snapshot volume using following commands.
# lvcreate -L 1GB -s -n testlv_snap
/dev/testvg/testlv
Logical volume "testlv_snap"
created
Where
1GB= Size of snapshot
Iam creating here.
-s= Creates snapshot.
-n= Creates name for the
snapshot.
testlv_snap= New
snapshots name.
/dev/testvg/testlv= Volume
which we are going to create a snapshot.
# lvs
LV
VG Attr
LSize
Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup
-wi-ao---- 6.71g
lv_swap VolGroup
-wi-ao---- 816.00m
testlv
testvg
owi-aos--- 2.00g
You see above, a
snapshot was created successfully.
# df -Th /dev/mapper/testvg-testlv
Filesystem
Type Size
Used Avail Use% Mounted on
/dev/mapper/testvg-testlv
ext4 2.0G 67M 1.9G 4% /testlvm
Let’s add some new files
into testlv.
Now check the volume
using the follwing command.
#lvs
LV VG Attr
LSize
Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup
-wi-ao---- 6.71g
lv_swap VolGroup
-wi-ao---- 816.00m
testlv
testvg
owi-aos--- 2.00g
testlv_snap testvg
swi-a-s--- 1.00g testlv 0.13
You see, 0.13% of
snapshot volume was used now.
If we copy more than 1GB
of files in testlV you will get error message appear On the screen
Input/output error, it means out of space in snapshot.
Step 2: Extend Snapshot in LVM
First we check available
PE using vgdisplay command
# vgdisplay
--- Volume group ---
VG Name
testvg
System ID
Format
lvm2
Metadata Areas
2
Metadata Sequence No 4
VG Access
read/write
VG Status resizable
MAX LV
0
Cur LV
2
Open LV
1
Max PV
0
Cur PV
2
Act PV
2
VG Size
3.99 GiB
PE Size
4.00 MiB
Total PE
1022
Alloc PE / Size
768 / 3.00 GiB
Free PE / Size
254 / 1016.00 MiB
VG UUID
mz7AN3-jsR0-rnsQ-XpvM-2W0N-M8q8-pki2kB
# lvextend -l +254 /dev/testvg/testlv_snap
Extending logical volume testlv_snap to 1.99
GiB
Logical volume testlv_snap successfully
resized
Now verify the size using the below command.
# lvdisplay /dev/testvg/testlv_snap
--- Logical volume ---
LV Path
/dev/testvg/testlv_snap
LV Name
testlv_snap
VG Name
testvg
LV UUID
eVvo1m-OZhv-PfP2-caja-r67k-W2o6-PD9Fcm
LV Write Access
read/write
LV Creation host, time localhost.localdomain,
2018-06-16 08:17:05 +0530
LV snapshot status
active destination for testlv
LV Status
available
# open
0
LV Size
2.00
GiB
Current LE
512
COW-table size
1.99 GiB
COW-table LE
510
Allocated to snapshot 0.07%
Snapshot chunk size
4.00 KiB
Segments
1
Allocation
inherit
Read ahead sectors
auto
- currently set to
256
Block device
253:3
# lvs
LV
VG Attr
LSize
Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup
-wi-ao---- 6.71g
lv_swap VolGroup
-wi-ao---- 816.00m
testlv
testvg
owi-aos--- 2.00g
testlv_snap testvg
swi-a-s--- 1.99g testlv 0.07
Step 3: Restoring
Snapshot or Merging
To restore the snapshot,
we need to un-mount the file system first.
# unmount /testlvm
Just check for the mount
point whether its unmounted or not.
# df -h
Here our mount has been
unmounted, so we can continue to restore the snapshot. To restore the snap
using command lvconvert.
# lvconvert --merge /dev/testvg/testlv_snap
Merging of volume testlv_snap started.
testlv: Merged: 100.0%
Merge of snapshot into logical volume
testlv has finished.
Logical volume "testlv_snap"
successfully removed
After the merge is finished, snapshot volume will be expelled naturally. Now we can check partition space using the below command.
# df -Th
If this article is helpful to know about LVM Snapshots on Rhel 7/Centos 7/Oracle 7 Linux and restore the snapshot please share and subscribe this article.
0 comments:
Post a Comment