LVM 逻辑卷管理器-快照区复原系统

LVM 逻辑卷管理器-快照区复原系统

复原的数据量不能够高于快照区所能负载的实际容量。由于原始数据会被搬移到快照区,如果你的快照区不够大,原始资料变动的实际数据量比快照大,那么快照区就容纳不了,这时快照就会失效。

(1)将原本的/dev/vg_1/lv_1内容做些改动,增减一些目录。

[root@centos6 ~]# df -h /mnt/lvm/
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg_1-lv_1   15G  351M   14G   3% /mnt/lvm
[root@centos6 ~]# ll /mnt/lvm/
total 36
dr-xr-xr-x.  5 root root  4096 Sep  8  2015 boot
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
[root@centos6 ~]# rm -r /mnt/lvm/boot
[root@centos6 ~]# cp -a /etc/fstab /mnt/lvm/
[root@centos6 ~]# ll /mnt/lvm/
total 36
-rw-r--r--.  1 root root   805 Sep  8  2015 fstab
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
[root@centos6 ~]# lvdisplay /dev/vg_1/snaps 
  --- Logical volume ---
  LV Path                /dev/vg_1/snaps
  LV Name                snaps
  VG Name                vg_1
  LV UUID                cCr9ap-TPbg-hLgy-JqXV-Ev9d-H4VK-042QOo
  LV Write Access        read/write
  LV Creation host, time centos6.5, 2016-09-10 03:41:00 +0800
  LV snapshot status     active destination for lv_1
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             960
  COW-table size         1.56 GiB
  COW-table LE           100
  Allocated to snapshot  0.02%   #快照区已经被使用了0.02%,因为原始的文件系统异动过;
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

(2)利用快照区将原本的文件系统备份

[root@centos6 ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/sda3                16G  1.5G   14G  11% /
tmpfs                   112M     0  112M   0% /dev/shm
/dev/sda1               194M   29M  155M  16% /boot
/dev/mapper/vg_1-lv_1    15G  328M   14G   3% /mnt/lvm
/dev/mapper/vg_1-snaps   15G  351M   14G   3% /mnt/snapshot
#两者确定不一样了,开始将快照区内容复制出来;
[root@centos6 snapshot]# mkdir -p /backups
[root@centos6 snapshot]# cd /mnt/snapshot/
[root@centos6 snapshot]# tar -jcvf /backups/lvm.tar.gz *   #将文件打包备份
[root@centos6 snapshot]# ll /backups/
total 74028
-rw-r--r--. 1 root root 75792390 Sep 10 03:50 lvm.tar.gz

(3)将snaps卸载并移除,因为里面的内容已经备份起来了

[root@centos6 ~]# umount /mnt/snapshot/
[root@centos6 ~]# lvremove /dev/vg_1/snaps 
Do you really want to remove active logical volume snaps? [y/n]: y
  Logical volume "snaps" successfully removed
[root@centos6 ~]# umount /mnt/lvm/
[root@centos6 ~]# mkfs -t ext4 /dev/vg_1/lv_1
[root@centos6 ~]# mount /dev/vg_1/lv_1 /mnt/lvm/
[root@centos6 ~]# tar -jxf /backups/lvm.tar.gz -C /mnt/lvm
[root@centos6 ~]# ll /mnt/lvm/
total 36
dr-xr-xr-x.  5 root root  4096 Sep  8  2015 boot
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
#成功还原,与最初的内容相同。

6.1、利用快照区进行各项练习与测试的任务,再以原系统还原快照

将原本的/dev/vg_1/lv_1当作备份数据,然后将/dev/vg_1/snaps当作实际运行中的数据 ,任何测试的操作都在snaps这个快照区中进行,当测试完毕后要将测试的数据删除时,只要将快照区删除即可。复制一个/dev/vg_1/lv_1系统,再制作另外一个快照区即可。

(1)新建一个大一些的快照区,将/dev/sdb5的PE全部给快照区;

[root@centos6 ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg_1
  System ID             
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  40
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               20.00 GiB
  PE Size               16.00 MiB
  Total PE              1280
  Alloc PE / Size       960 / 15.00 GiB
  Free  PE / Size       320 / 5.00 GiB   #查看还剩余320个PE
  VG UUID               NpO8m2-s4rx-WOIA-SbCt-yqQV-MU1w-wru4cS
[root@centos6 ~]# lvcreate -s -l 320 -n snaps /dev/vg_1/lv_1   #创建快照
  Logical volume "snaps" created
[root@centos6 ~]# lvdisplay /dev/vg_1/snaps 
  --- Logical volume ---
  LV Path                /dev/vg_1/snaps
  LV Name                snaps
  VG Name                vg_1
  LV UUID                w6hXrI-qnwQ-DOKc-vTCr-kbXG-p1ni-HQt2MH
  LV Write Access        read/write
  LV Creation host, time centos6.5, 2016-09-10 06:31:51 +0800
  LV snapshot status     active destination for lv_1
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             960
  COW-table size         5.00 GiB
  COW-table LE           320
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

(2)隐藏/dev/vg_1/lv_1,挂载/dev/vg_1/snaps

[root@centos6 ~]# umount /mnt/lvm/
[root@centos6 ~]# mount /dev/vg_1/snaps /mnt/snapshot/
[root@centos6 ~]# df -h /mnt/snapshot/
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/vg_1-snaps   15G  351M   14G   3% /mnt/snapshot

(3)在/dev/vg_1/snaps挂载的目录/mnt/snapshot中开始增加或删除文件

[root@centos6 ~]# ll /mnt/snapshot/
total 36
dr-xr-xr-x.  5 root root  4096 Sep  8  2015 boot
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
[root@centos6 ~]# rm -rf /mnt/snapshot/boot /mnt/snapshot/lib
[root@centos6 ~]# cp -a /etc /mnt/snapshot/
[root@centos6 ~]# ll /mnt/snapshot/
total 32
drwxr-xr-x. 79 root root  4096 Sep 10 06:32 etc
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
#与原本数据有差异了
[root@centos6 ~]# mount /dev/vg_1/lv_1 /mnt/lvm   #挂载/dev/vg_1/lv_1
[root@centos6 ~]# ll /mnt/lvm/
total 36
dr-xr-xr-x.  5 root root  4096 Sep  8  2015 boot
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
#无论在快照区怎么增加或删除数据,原本的数据完好如初

(4)还原原本数据,回到原文件系统相同的信息

[root@centos6 ~]# umount /mnt/snapshot/    #卸载/dev/vg_1/snaps快照区
[root@centos6 ~]# lvremove /dev/vg_1/snaps    #移除/dev/vg_1/snaps快照区
Do you really want to remove active logical volume snaps? [y/n]: y
  Logical volume "snaps" successfully removed
[root@centos6 ~]# lvcreate -s -l 320 -n snaps /dev/vg_1/lv_1   #创建新的快照区
  Logical volume "snaps" created
[root@centos6 ~]# mount /dev/vg_1/snaps /mnt/snapshot/   #挂载快照区
[root@centos6 ~]# ll /mnt/snapshot/
total 36
dr-xr-xr-x.  5 root root  4096 Sep  8  2015 boot
dr-xr-xr-x. 10 root root  4096 Sep  8  2015 lib
drwx------.  2 root root 16384 Sep  9 19:05 lost+found
dr-xr-xr-x.  2 root root 12288 Sep  9 04:35 sbin
#快照区的数据就这样还原了
#上面的步骤有些繁琐,快照区的文件损毁了,直接删除再新建一个就可以了。

7、LVM命令汇总与LVM的关闭

7.1 LVM命令汇总

任务 PV阶段 VG阶段 LV阶段
查找(ssan) pvscan vgscan lvscan
新建(create) pvcreate vgcreate lvcreate
显示(display) pvdisplay vgdisplay lvdispaly
增加(extend) vgextend lvextend(lvresize)
减少(reduce) vgreduce lvreduce(lvresize)
删除(remove) pvremove vgremove lvremove
改变容量(resize) lvresize
改变属性(attribute) pvchange vgchange lvchange

7.2 LVM的关闭

(1)关闭LVM的步骤:

  1. 卸载系统上面的LVM文件系统(包括快照与所有的LV);

  2. 使用lvremove删除LV;

  3. 使用vgchage -an VGNAME 让VGNAME这个VG不具有Active的标志;

  4. 使用vgremove删除VG;

  5. 使用pvremove删除PV;

  6. 最后,使用fdisk将分区systemID修改回来。

(2)操作步骤:

[root@centos6 ~]# umount /mnt/lvm/
[root@centos6 ~]# umount /mnt/snapshot/
[root@centos6 ~]# lvremove /dev/vg_1/snaps 
Do you really want to remove active logical volume snaps? [y/n]: y
  Logical volume "snaps" successfully removed
[root@centos6 ~]# lvremove /dev/vg_1/lv_1 
Do you really want to remove active logical volume lv_1? [y/n]: y
  Logical volume "lv_1" successfully removed
[root@centos6 ~]# vgchange -a n vg_1
  0 logical volume(s) in volume group "vg_1" now active
[root@centos6 ~]# vgremove vg_1
  Volume group "vg_1" successfully removed
[root@centos6 ~]# pvremove /dev/sdb{1,2,3,5}
  Labels on physical volume "/dev/sdb1" successfully wiped
  Labels on physical volume "/dev/sdb2" successfully wiped
  Labels on physical volume "/dev/sdb3" successfully wiped
  Labels on physical volume "/dev/sdb5" successfully wiped
[root@centos6 ~]# pvscan
  No matching physical volumes found
[root@centos6 ~]# fdisk /dev/sdb  
#将磁盘的ID改为83就好,操作过程省略。

原创文章,作者:zhuckee,如若转载,请注明出处:http://www.178linux.com/47594

(0)
上一篇 2016-09-18 20:01
下一篇 2016-09-19 10:24

相关推荐

  • N22-第二周作业

    Linux上的文件管理类命令有哪些,其常用使用方法及其相关示例演示。 文件管理类命令有:cp,mv,rm cp:复制文件或者目录   单源复制:cp [OPTION]… [-T] SOURCE DEST        多源复制:cp [OPTION]… SOURCE… DI…

    Linux干货 2016-09-19
  • Linux基础知识点(一)

    此篇博客只是记录第一周未掌握或不熟悉的知识点,用来加深印象。

    2018-03-13
  • 第三周-作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。     ~]# who | cut -d" " -f1 | uniq 2、取出最后登录到当前系统的用户的相关信息。     ~]# who |  t…

    Linux干货 2016-12-14
  • 集中管理利器-puppet快速入门-下

    Puppet配置 1.    文件管理 file 文件服务器写法: /etc/puppet/ fileserver.conf 定义 [files] path /tmp/files  ## puppet数据存放目录 =è后面远程备份实战会用到 allow *.example.com 实战1: 备份master机…

    Linux干货 2015-05-07
  • OpenSSL 及创建私有CA

    OpenSSL 及创建私有CA OpenSSL OpenSSL,是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。这个包广泛被应用在互联网的网页服务器上。 接下来对openssl基本命令进行介绍openssl 非常强大其子命令很多,这里只是对完成某些操作进行部分解释openssl 的基本格式为openss…

    2017-09-11
  • CentOS程序安装的3种方式{ 源码包安装 | rpm包安装 | yum安装;}

    CentOS程序安装的3种方式{ 源码包安装 | rpm包安装 | yum安装;} CentOS软件安装主要由3种方式,第一种是源码包安装,需要从网站下载并解压之后通过手动编译的方式安装,过程相对比较复杂;第二种是rpm包安装,通过rmp这个包管理器实现程序的安装、升级、卸载等操作,rpm包管理器是RPM Package Manager的简称,功能非常强大,…

    Linux干货 2016-08-24