Snapshot principle of LVM (Logical Volume Manager) based

First, why no matter how logical volumes for backup, the snapshot will be completed in a few seconds?

Snapshots taken in the moment, the system will record the state of the logical volume that point in time, data, etc., then take a snapshot of the equivalent of a piece of paper. as the picture shows

After the snapshot done, over time, the source volume where things will change. The data would be rewritten, 2 A, B, as shown:

At this time, data in the source volume lv change will be transferred to the snapshot volume inside. When you revert to the snapshot, and the snapshot source volume will be merged, there are no changes in the source volume data + snapshot volume, it is restored to its original state.

 

Second, note:

1, when the data inside the source volume change is too large, (the source volume after 2G, 200M only snapshot volume) snapshot volume is not installed in the snapshot volume is not set too small space, capped by a volume group (VG) the size of the decision.

2, when the source volume is broken ring system, it can not restore the snapshot. (Data not equal to destroy completely revised)

 

Third, the operation

1. Create a snapshot volume (EXT4)
[root @ server0 ~] # lvcreate -L 128M -n -s lv2-SNAP / dev / vg1 / lv2
or so to see it, create LV, name lv2-snap, snapshot based on lv2, size 128M
the lvcreate -n LV2 -s-SNAP / dev / the VG1 / LV2 -L 128M

2 query snapshot volume size.
[server0 the root @ ~] # LVS
the LV VG of the Attr Pool LSize the Move the Log% Origin the Data Sync% Cpy the Convert
LV1 the VG1 -Wi-AO ---- 768.00m
LV2 OWI the VG1-AOS --- 512.00m
LV2 SNAP-swi- the VG1 aos --- 128.00m lv2 5.92

3 to mount the snapshot volume, copying the data. It can be used as a reply data use.
[server0 the root @ ~] # mkdir / mnt / SNAP-LV2
[server0 the root @ ~] -o RO # Mount / dev / the VG1 / SNAP-LV2 / mnt / SNAP-LV2 / (RO read only)

4 Mount View case two volumes.
[server0 the root @ ~] # DF -Th
the Filesystem Size Used Avail the Use the Type% Mounted ON
/ dev / Mapper / LV2 ext4 the VG1-488M 32M. 7% 429 m / mnt / LV2
/ dev / Mapper / the VG1-LV2 - SNAP ext4 488M 32M 429M 7% / mnt / lv2 -snap

5 View two volumes relationship
[server0 the root @ ~] # the lvscan
the ACTIVE '/ dev / the VG1 / LV1' [768.00 MiB] the inherit
the ACTIVE Original '/ dev / the VG1 / LV2' [512.00 MiB] the inherit
the ACTIVE the Snapshot '/ dev / the VG1 / SNAP-LV2 '[128.00 MiB] the inherit

. 6 to view the contents of the file. It is used according to the situation.
[the root @ server0 ~] # LS / mnt / LV2
etc Lost + found
[the root @ server0 ~] # LS / mnt / LV2-SNAP /
etc Lost + found

. 7 observe the Snapshot
[the root @ server0 ~] # LVS
the LV VG of the Attr LSize Origin% the Move the Log the Data Pool Cpy% Sync Convert For
LV1 vg1 -wi-AO ---- 768.00m
lv2 vg1 OWI-the AOS --- 512.00m
lv2-SWI-SNAP vg1 the AOS --- 128.00m lv2 30.56

8 XFS file system: does not recognize uuid, we need to add a separate -o nouuid be ignored.
[root @ server0 ~] # mount -o nouuid, ro / dev / vg1 / lv1-snap / mnt / lv1-snap /

Mount the snapshot, to make use of ro ​​manner, will not destroy data in the snapshot volume

Guess you like

Origin www.cnblogs.com/zjz20/p/11242653.html