Linux logical volume snapshots and the use of SSM

Source: Internet
Author: User
Tags uuid

Linux logical volume snapshots and the use of SSM


Theoretical part:


Logical Volume Management (LVM) provides a snapshot of any logical volume in order to get a partitioned backup in a consistent state. Because during the backup process, The application may access a partitioned file or database. Some files may be backed up in one state, and later files may be backed up after an update, resulting in incomplete backups

In specific detail, a snapshot is a reference tag or pointer to data stored in a storage device

Operation section:


First, create a logical volume/dev/vg00/lv00 with a space of 504M

lvdisplay /dev/vg00/lv00 
  --- Logical volume ---  LV Path                 /dev/vg00/lv00  LV Name                 lv00  VG  name                vg00   LV UUID                 1ZUmzM-krIb-ag0Y-58oQ-IEfp-CRu4-JrzlB1  LV Write Access         read/write  LV Creation host, time CentOS-1,  2017-01-09 19:25:41 +0800  lv status               available  # open                  1  lv size                 504.00 MiB  Current LE              126  Segments                1  Allocation              inherit  read ahead sectors      auto  - currently set to      8192  block device           253:2

To reflect the results, we're going to copy some data into this logical volume into the/data.

cp/boot/*/data/

Next we begin to take a logical volume snapshot of/dev/vg00/lv00

Lvcreate--size 500M--snapshot--name lvsp00/dev/vg00/lv00logical Volume "lvsp00" created.

Use Lvscan to see

Lvscan active '/dev/centos/swap ' [8.00 Gib] inherit active '/dev/centos/root ' [41.51 GiB] Inherit Active Original '/dev/vg00/lv00 ' [504.00 MIB] inherit active Snapshot '/dev/vg00/lvsp00 ' [500.00 MiB] Inherit

Now you can see that/dev/vg00/lv00 is the original logical volume, and the last/dev/vg00/lvsp00 is the snapshot

Execute lvdisplay or LVS command to view logical information

lvdisplay /dev/vg00/lvsp00   --- Logical volume ---  lv path                 /dev/vg00/ lvsp00  lv name                 lvsp00  VG Name                 vg00  LV UUID                 pkwnxm-7z1a-lntk-qtmd-t3xz-e5de-l33opy  lv  write access        read/write  lv creation  host, time centos-1, 2017-01-09 19:34:38 +0800  lv snapshot  status     active destination for lv00  lv status               available  # open                  0  LV Size                 504.00 mib   current le             126   COW-table size         500.00 MiB   COW-table LE           125   allocated to snapshot  0.00%  snapshot chunk size     4.00 KiB  Segments                1  Allocation              inherit  read ahead sectors     auto  - currently set to      8192  Block device            253:5
lvs  lv     vg     attr        lsize   pool origin data%  meta%  move log  cpy%sync convert  root   centos -wi-ao----  41.51g                                                         swap    centos -wi-ao----   8.00g                                                   &nbSp;     lv00   vg00   owi-aos--- 504.00m                                                         lvsp00  vg00   swi-a-s--- 500.00m      lv00    0.00

Here you can see that the logical snapshot has been created successfully <--note that snapshots are not required to be formatted and mounted--


Now let's simulate the removal of data from a logical volume

rm-rf/data/*

Now that there are no files in the logical volume/data directory, there are two ways to recover the deleted data.

Method One:

To dismount the original logical volume mount:

umount/dev/vg00/lv00

The logical volume snapshot is then mounted to the/data directory for normal access to the

mount/dev/vg00/lvsp00/data/

Method Two:

Re-write the contents of the snapshot back to the original LVM via Lvconvert

First dismount the logical volume from the Mount

umount/dev/vg00/lv00

Then execute lvconvert to merge the snapshot's data into the original logical volume

Lvconvert--merge/dev/vg00/lvsp00

Finally mount the original logical volume

mount/dev/vg00/lv00/data/


Logical volume Management Using SSM (System Storage Manager)

Install SSM:

can be installed with RPM or Yum

Yum-y Install System-storage-manager

You can use the SSM list to check the LVM volume information on the hard disk after installation

Ssm list---------------------------------------------------------------device           Free       Used       Total  Pool    Mount  Point---------------------------------------------------------------/dev/sda                            50.00 gb          partitioned/dev/ sda1                         500.00 MB           /boot      /dev/sda2    0.00 KB    49.51 gb   49.51 gb  centos             /dev/sdb    99.50  GB  504.00 MB  100.00 GB  vg00                /dev/sdc   100.00 GB     0.00 KB  100.00 GB  vg00                /dev/sdd                          100.00  GB                      /dev/sde                          100.00 GB                 --------Omit some of the content-------- 

Create an LVM volume (/DEV/MYPOOL/LV01) from the SSM below

First, create a mount point to mount

Mount/test

Then execute the next command to create a storage pool named Mypool and create a 500M size LVM volume named Lv01 in the storage pool, format the volume using the XFS file system, and mount it to/mnt/test

SSM create-s 500m-n lv01--fstype xfs-p mypool/dev/sdd/test

Use Lvscan to view creation results

lvscan   active              '/dev/centos/swap '  [8.00 GiB] inherit  ACTIVE              '/dev/centos/root '  [41.51 gib]  inherit  ACTIVE             '/dev/ Vg00/lv00 '  [504.00 MiB] inherit  ACTIVE              '/dev/mypool/lv01 '  [500.00 mib] inherit 
 df -ThFilesystem               type      size  used avail use% mounted on/ dev/mapper/centos-root xfs        42g  3.5g    39G   9% /devtmpfs                 devtmpfs  3.8G     0  3.8G    0% /devtmpfs                    tmpfs     3.9g  144k  3.9g    1% /dev/shmtmpfs                    tmpfs     3.9G  9.0M   3.9g   1% /runtmpfs                    tmpfs     3.9G     0  3.9G    0% /sys/fs/cgroup/dev/sda1                xfs       497m  159m  339m   32% /boottmpfs                    tmpfs     781M   20K   781m   1% /run/user/0/dev/mapper/vg00-lv00   xfs        501M  150M  352M  30% /data/dev/sr0                 iso9660   4.1g   4.1g     0 100% /mnt/dev/mapper/mypool-lv01 xfs        497m   26m  472m   6% /test

Add a new hard drive to the LVM pool

SSM Add-p MYPOL/DEV/SDD

Extend the LVM volume to increase the/DEV/MYPOOL/LV01 volume by 300M

SSM Resize-s +300M/DEV/MYPOOL/LV01

Note: This only increases the LVM volume by 300M on the original basis, but the file system size (Fs size) has not changed and is still the original size, so we will use the following command to enlarge the existing XFS file system

Xfs_growfs/dev/mypool/lv01


To create a snapshot of an LVM volume

To reflect the results of the experiment, we copied some files into the/test.

cp-rf/boot/*/test/

Then we use SSM to create a snapshot for/dev/mypool/lv01.

SSM SNAPSHOT/DEV/MYPOOL/LV01

View some of the created snapshots

SSM List Snapshots-----------------------------------------------------------------------------Snapshot Origin Pool Volume size size Type----------------------------------------------------------------------- ------/dev/mypool/snap20170109t203221 lv01 mypool 160.00 MB 16.38 KB linear-------------------------------------- ---------------------------------------

Each subsequent data change in the original LVM can be manually executed by the SSM snapshot to generate a snapshot


Simulate data loss in LVM, recover files using snapshots

rm-rf/test/*

Method One:

Unmount the original logical volume first:

Umount/dev/mypool/lv01

Then mount the logical volume snapshot

mount/dev/mypool/snap20170109t203221/test/

Method Two:

Re-write the contents of the snapshot back to the original LVM via Lvconvert

Same as above, first unload the original logical volume

Umount/dev/mypool/lv01

Then execute the following command to merge the snapshot data into the original logical volume

Lvconvert--merge/dev/mypool/snap20170109t203221

Finally mount the original logical volume

Mount/dev/mypool/lv01/test


This article is from the "Dark Cloud Technology" blog, please be sure to keep this source http://wuyunkeji.blog.51cto.com/12028005/1890566

Linux logical volume snapshots and the use of SSM

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.