LVM Snapshot Backup and recovery

Source: Internet
Author: User

Brief introduction

Recent work on data backup uses two tools, one DD, and the other a snapshot of LVM (snapshot). Because the data is large, the direct use of DD is very time-consuming, and LVM snapshots can be easily done in a few seconds, and can achieve real-time results, but the cost of using LVM snapshots is to exchange space for time.
Let's start by understanding the following principles:
The snapshot is implemented by "Copy on Write" in LVM, that is, when a snapshot is created, only the metadata (meta-data) of the data in the original volume is copied, and when created, there is no physical copy of the data. So the creation of snapshot is almost real-time, and when a write operation is performed on the original volume, snapshot tracks the change of the original volume block, which is copied to the snapshot reserved space before the changed data on the original volume.

Note: When you take the cow implementation, the size of the snapshot does not need to be as large as the original volume, and its size requires only two aspects: from Shapshot creation to the time of release, estimate how much the block changes, and how often the data is updated. Once the snapshot's space is full of information about the original volume-block transformation, the snapshot is immediately released and unusable, causing the snapshot to become invalid. So, it's important to be sure to do what you need to do in the snapshot life cycle.

Instance requirements

The LVM creation process is not detailed here, and here is my existing LVM, where Lv_image is the logical volume we need to back up.

[[email protected] ~]# lvs  lv            VG            Attr        lsize   pool origin data%  move log cpy% sync convert  lv_image     vg_image       -wi-ao----   8.00t                                                                                                                                          logvol00     vg_test -wi-ao----    7.81g                                                 LogVol01      vg_test -wi-ao---- 101.70g   1234512345
Realize

Premise: The VG where the LVM snapshot resides must be the same as the backup source (that is, lv_image), so we need to confirm the remaining space of the vg_image, if it is not enough to be extended.

1. Confirm Vg_image Space

[[email protected] ~]# vgs  vg              #PV   #LV   #SN  Attr   VSize   VFree     vg_image        2   1   0  wz--n-   8.29t 4.00m  vg_test          1   2   0 wz--n- 109.51g       0 12341234 

From the above see Vg_image of the remaining space (Vfree) is 4m, obviously not enough space.

2.VG Space Expansion

Here, you may have a question "How much space does the VG need to expand?" "The above mentioned cow principle, the greater the snapshot, the more we do in the snapshot cycle, but we have limited space, so we generally use the snapshot space is about 10% of the original volume ."

Now we have a 2T size backup disk/DEV/SDF1 to use.

[[email protected] ~]# vgextend vg_image /dev/sdf1  volume group  "Vg_image"  successfully extended[[email protected] ~]# pvs  PV          VG             fmt  attr psize   pfree    /dev/sda2  vg_ test       lvm2 a--  109.51g       0   /dev/sdc1  vg_image      lvm2 a--     8.00t   4.00m  /dev/sdf1  vg_image       lvm2 a--    2.00t   2.00t[[email protected]  ~]# vgs  VG             #PV   #LV   #SN  attr   vsize   vfree    vg_image         2   1   0 wz--n-   2.00t    2.00t  vg_picture118   1   2   0 wz--n-  109.51g      0 12345678910111234567891011

3. Create a Snapshot

[[email protected] ~]# lvcreate-l 300gb-s-N lv_image_snap/dev/vg_image/lv_image 11

which
-L 300G Indicates this snapshot size is created
-S means snapshot creation
-N Lv_image_snap indicates that the new snapshot is named Lv_image_snap
/dev/vg_image/lv_image a logical volume to create a snapshot

[[email protected] ~]# lvs  lv            VG            Attr        lsize   pool origin data%  move log cpy% sync convert  lv_image     vg_image       -wi-ao----   8.00t                                                                                             &nBSP; LV_IMAGE_SNAP VG_IMAGE     -SWI-A---- 300.00G   LV _image  0                                            logvol00     vg_test - Wi-ao----   7.81g                                                 LogVol01      vg_test -wi-ao---- 101.70g   123456123456

At this point, our snapshot has been created, just to mount it.
Mount/dev/vg_image/lv_image_snap/mnt
In addition, the data in the "data%" section increases as the data of the source logical volume grows, and the snapshot becomes unusable after 100% and needs to be expanded. before you create a snapshot, it is a good idea to mount the source logical volume as read-only.

4. Deleting a logical Volume
Lvremove/dev/vg_image/lv_image_snap
Vgreduce VG_IMAGE/DEV/SDF1
Pvremove/dev/sdf1

Snapshot restore

This is based on the above backup:

#确保/data has enough space dd If=/dev/vg_image/lv_image_snap OF=/DATA/RECOVER.IMGDD if=/data/recover.img of=/dev/vg_new/lv_ newrm/data/recover.imglvremove/dev/vg_image/lv_image_snap1234512345

Note: Although the snapshot is small, the space backed up by snapshot must be large enough because its data is as large as the source LVM data.

Summarize

With the use of LVM snapshots we can easily backup data, due to the relationship between snapshot and source LVM, snapshot can only be used temporarily, can not be separated from the source LVM, so that the data is foolproof, We can perform DD backups or other backup operations on a snapshot basis, so that neither the raw data nor the backup needs will be affected.


This article is from the "Shunsheng" blog, make sure to keep this source http://shunsheng.blog.51cto.com/11516694/1768755

LVM Snapshot Backup and recovery

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.