Linux Learning-LVM Snapshot feature

Source: Internet
Author: User
Tags bz2

LVM Snapshot Features --we know that LVM can flexibly adjust the size of the file system by increasing or decreasing the number of PE, in addition, LVM has another important function, theLV disk snapshot , is through the function of the snapshot to record the file system information at this time, and later on the file system operation , we can use snapshots to restore the file system to its current state when the file system's data changes.

Directory

    • The snapshot principle of LV

    • Create a Snapshot

    • Recovery system with Snapshot

first, the principle of the LV Snapshot (snapshot)

The diagram on the left shows that LVM reserves a certain area on the VG as the snapshot area, the data is stored in the LV, and the snapshot area holds the LV metadata, so the size of the snapshot area does not need to be the same size as the original LV. When the snapshot is created, the snapshot area does not actually copy the data from the original LV, only the metadata in the entire original LV is recorded, so the point-in-time snapshot area is the same as the original LV shared file system data, that is, the data on both sides.

the graph on the right shows that when the data in the original LV changes, the data of the changed PE in the original LV is updated before the data is actually backed up to a PE in the snapshot area, before A->new A is backed up to a PE in the snapshot area. Then the LV in a is updated to new A, so that the snapshot area will save the LV in the data before the change of PE, and then we access the contents of the snapshot area is still the time to create snapshot at that point in the LV data, so we can use the snapshot area for backup and recovery.

It is important to note that because the snapshot area also has a capacity limit, the snapshot is immediately invalidated when the number of PE changes in the original LV exceeds the number of PE in the snapshot area.

When we create the snapshot area, we need to consider the future changes in the LV data to specify the size of the snapshot area, one solution is to immediately after the snapshot is created, the content in the snapshot area is backed up so that the snapshot area is not always considered invalid, because we have already backed up his data. Another simple and crude way is to create a snapshot area of the same size as the original LV, so that you don't have to worry about the amount of data changes.

Second, create a snapshot

Operation Flow:

The original LV is/dev/vg1/lv1, creating a snapshot of the LV for Lv1snap with a capacity of 100 PE

① View the number of available PE in VG1 information

② Creating a LV Snapshot

[Email protected] ~]# lvcreate-s-L 100-n lv1snap/dev/vg1/lv1 Logical volume "Lv1snap" created.

-S key option to create snapshot snap meaning

How many PE numbers are behind the-L and the snapshot

-N followed by the name of the snapshot created

-P R Because the snapshot is mostly read-only, the re-entry is read-only for the Modify permission bit (R)

Command finally remembers the original LV name of the snapshot created

③ viewing the newly created snapshot area

③ mount the snapshot of the original LV and LV  

[Email protected] ~]# mount/dev/vg1/lv1/mnt/lvm/[[email protected] ~]# mount/dev/vg1/lv1snap/mnt/snap/


Before I imported some data in/MNT/LVM, we found that the original LV and LV snapshots were mounted with the same capacity information

Third, the use of snapshot recovery system

when recovering a system with a snapshot, the amount of data to be recovered is not greater than the maximum range that the snapshot area can withstand

① Modifying the contents of the original LVM

[[email protected] ~]# dd If=/dev/zero of=/mnt/lvm/test bs=1m count=500500+0 Records in500+0 records out524288000 bytes (5 MB) copied, 5.31399 s, 98.7 MB/s

Usage of two directories changed


② compressing and backing up the data in the snapshot area

[[email protected] snap]# tar-jcv-f/backups/lvm.tar.bz2 * #-j Support bzip2 Extract file-C Create a new backup file-F Specify backup file Tmp[[email protected] sn ap]# Echo $?0

Unmount original LV reformat, then Mount DF to view


③ Data Recovery for the original LV

[[email protected] ~]# tar-jxv-f/backups/lvm.tar.bz2-c/mnt/lvm/#-c Extract to the specified directory

Original LV restored to the original 14%

I'm here for backup and restore in a packed and compressed manner, of course, with the CP command.


Linux Learning-LVM Snapshot feature

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.