Principles and experiment of RHEL6snapshot snapshots

Source: Internet
Author: User
LVM provides snapshot backup for lv, which is only valid for LVM. There are multiple implementation methods for snapshot. here we only talk about COW replication during writing, not cows. it is Copy-On-Write. when a snapshot is created, only the source data in the original volume is copied, this is not a thing...

LVM provides the snapshot backup function for lv, which is only valid for LVM. There are multiple implementation methods for snapshot. here we only talk about "COW replication during Writing". it's not a COW, it's "Copy-On-Write"
When a snapshot is created, only the source data in the original volume is copied, which is not physical data. Therefore, snapshot is created very quickly, when the data in the original volume is written, the backup volume starts to record which data has changed in the original volume, and then when the new data in the original volume overwrites the old data, copy the old data to the snapshot's reserved space to back up the data. This ensures the data consistency between all the data and the data before the backup volume is created.
For snapshot read operations, if the read data block is not modified, the read operation will be directly redirected to the original volume. if you want to read the modified block, read the blocks copied to snapshot. Therefore, when the original volume is damaged, the data backed up by snapshot can be restored.
Please refer to a 51CTO [Mr. asram] explanation:
[Image Separation: allows an image volume to be split for an instant, instead of being written into data. After splitting, all write IO operations performed by the primary volume are recorded in bitmap mode. Bitmap is a bitmap file. each bit in the file represents a block (sector, or a logical block composed of multiple sectors) on the volume. If this block is separated from the image, if the data is written, the program changes the bitmap file's corresponding bit from 0 to 1. After the backup is complete, you can restore the image relationship. in this case, the data on the master volume and the image volume are inconsistent and need to be synchronized again. The program searches for all 1 bits in bitmap, corresponding to the block on the volume, and then synchronizes the data on these blocks to the image volume to restore the real-time image relationship.
Changed block)
After a snapshot is created, the source and the snapshot share the same copy of physical data until the data is written, the old data or new data on the source is written to the new storage space. In order to record and track block changes and replication information, a bitmap is required to determine the location of the actually copied data and to determine whether the data is obtained from the source or target.
Concurrent)
It is very similar to changing blocks, but it always copies data physically. When an instant copy is executed, no data is copied. Instead, it creates a bitmap to record data replication and performs real physical data replication in the background.
When the data is written, the data is copied quickly after the snapshot time point. no physical data is copied, and only the metadata of the physical location of the original data is copied. Therefore, snapshots can be created quickly and instantly. Then, the snapshot copy tracks the data changes of the original volume (that is, the original volume write operation). once the original volume data block is written, the original volume data block is read and written to the snapshot volume, then overwrite the original volume with the new data block. In this way, the data on the snapshot volume is still before the write operation, which ensures the consistency of the backup data .]
 
Check the features of snapshot:
When COW is adopted, the snapshot size does not need to be as large as the original volume. How big is it set? First, it is set based on the change range of the original volume data. Second, it is determined based on the update frequency of the original volume data. Once the snapshot space record is full of the original volume block conversion information, this snapshot cannot be used. Of course, if your snapshot size is as big as or even as large as the original volume, the snapshot backup will never crash.
 
Let's get started!
1. create an lv partition and install a system (you don't need to install it. In fact, you only need to note that it is a data volume we want to back up)
---> First, check the free space of vg.
[Root @ shorttop21/] # vgs
VG # PV # LV # SN Attr VSize VFree
Vol0 2 4 1 wz -- n-55.22g 26.22g
---> There is still 26.22 GB. create a 3G lv to install the system. The lv name is syslv.
[Root @ shorttop21/] # lvcreate-L 3G-n syslv vol0
Logical volume "syslv" created
[Root @ shorttop21/] # lvdisplay/dev/vol0/syslv
--- Logical volume ---
LV Name/dev/vol0/syslv
VG Name vol0
Lvuuid xQXHqK-N3Oj-y9Z1-TBU6-hAsI-ek3V-PkmVmL
LV Write Access read/write
LV Status available
# Open 0
LV Size 3.00 GiB (lv Size 3G)
Current LE 96
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 6
---> OK, it is created successfully. next I will install a simple version of linux. I will not be able to try it myself.
[Note: This lv cannot be formatted if it is used as the installation system. it is used as the hard disk. who knows how to format the hard disk in the installation system? He will warn you of unrecognized hard disks ~]
.
.
.
 
II. create a snapshot
After the installation is complete, let's create a snapshot backup, which is similar to the lv creation method. just add the parameter-s.
[Root @ shorttop21/] # lvcreate-s-n snapsyslv-L 50 M/dev/vol0/syslv
Rounding up size to full physical extent 64.00 MiB
Logical volume "snapsyslv" created
[Root @ shorttop21/] # lvdisplay/dev/vol0/snapsyslv
--- Logical volume ---
LV Name/dev/vol0/snapsyslv
VG Name vol0
Lvuuid snoXql-gI1Q-TSsF-F3LN-SyRI-HInY-8cZM3r
LV Write Access read/write
LV snapshot status active destination for/dev/vol0/syslv
LV Status available
# Open 0
LV Size 3.00 GiB
Current LE 96
COW-table size 64.00 MiB (my PE is 32 M and only a multiple of 32 can be created)
COW-table LE 2
Allocated to snapshot 0.03% (usage: 0.03%)
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 7
---> OK, snapsyslv has been created, 64 M. check the details of snapsyslv:
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 swi-a-64.00 m syslv 0.07
---> What we need to care about is that the above usage rate is 0.07%. when it reaches 100%, it will be released, and snapshot will be broken, and it will be useless.
 
3. change the data of the original volume and view the changes of the backup volume.
1. log on to the system where syslv is located and create a file for testing.
Optional top64 login: root
Password:
[Root @ override top64 ~] # Dd if =/dev/zero of = testfile bs = 1 M count = 20
20 + 0 records in
20 + 0 records out
20971520 bytes (21 MB) copied, 0.0329396 s, 637 MB/s
---> All right, go to our host and check the snapshot changes. refresh the snapshot several times.
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 swi-a-64.00 m syslv 0.07
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 swi-a-64.00 m syslv 33.81
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 swi-a-64.00 m syslv 33.83
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 swi-a-64.00 m syslv 33.83
---> See? The usage is 33.83%, the snapshot size is 64 MB, and the original volume creates 20 MB of files. is the usage rate about 33%? Pai_^
2. create a snapshot of 50 MB, and add the previous 20 MB to check the snapshot changes.
[Root @ override top64 ~] # Dd if =/dev/zero of = testfile bs = 1 M count = 50
50 + 0 records in
50 + 0 records out
52428800 bytes (52 MB) copied, 0.132893 s, 395 MB/s
---> Refresh the snapshot and check the snapshot changes.
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 Swi-I-64.00 m syslv 100.00
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 Swi-I-64.00 m syslv 100.00
[Root @ shorttop21/] # lvs/dev/vol0/snapsyslv
Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
Snapsyslv vol0 Swi-I-64.00 m syslv 100.00
---> 100%. check the Snapshot status?
[Root @ shorttop21/] # lvdisplay/dev/vol0/snapsyslv
--- Logical volume ---
LV Name/dev/vol0/snapsyslv
VG Name vol0
Lvuuid snoXql-gI1Q-TSsF-F3LN-SyRI-HInY-8cZM3r
LV Write Access read/write
LV snapshot status INACTIVE destination for/dev/vol0/syslv (down)
LV Status available
# Open 0
LV Size 3.00 GiB
Current LE 96
COW-table size 64.00 MiB
COW-table LE 2
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 7
---> See, INACTIVE (not activated). Let's Activate it.
[Root @ shorttop21/] # lvchange-ay/dev/vol0/snapsyslv
Can't change snapshot logical volume "snapsyslv"
---> Can't. it cannot be activated, and snapshots cannot be used. remove it.
[Root @ shorttop21/] # lvremove/dev/vol0/snapsyslv
Do you really want to remove active logical volume snapsyslv? [Y/n]: y
Logical volume "snapsyslv" successfully removed
---> OK. the snapshot has been removed. now you can continue to create the snapshot. ^_^

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.