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.www58058.com/47594

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

相關推薦

  • iptables的使用

    iptables         firewall:隔離工具;Packets Filter Firewall;工作于主機或網絡的邊緣,對經由的報文根據預先定義的規則(匹配條件)進行檢測,對于能夠被規則匹配到的報文實行某預定義的處理機制的一條組件; 硬件防火墻:在硬件級別實現部分顧慮功能;另…

    Linux干貨 2016-10-29
  • Linux基礎之權限管理(含SUID\SGID\STICKY和ACL)

    概述     Linux系統是一個多人多任務的操作系統,系統上同時可能有很多人登錄,每個人都會利用系統上的各類資源完成一定的操作。那么如何合理的規范這些用戶的行為,保證資源的合理分配,則就需要用到權限管理的相關內容了。權限管理是Linux系統上最基礎,也是最重要的一部分內容,本章就簡要說明下權限管理的相關內容。內容主要…

    Linux干貨 2016-08-04
  • Linux系統啟動流程簡圖

    CentOS 系統啟動流程: POST 加電自檢   外部硬件是否都能存在和是否能正常工作ROM:COMS 芯片上的BIOS 基本輸入輸出 BOOT Sequence:   引導加載次序,也就磁盤上的MBR,bootloader 按次序查找各引導設備,第一人有引導程序的設備即為本次啟動用到的設備。 bootloaderr:引導加載器,程序…

    2017-05-13
  • 馬哥教育網絡班19期+第九周課程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin),分別這兩類用戶的個數,通過字符串比較來實現。 #!/bin/bash for user_shell in `awk -F: '{print $7}'&nbsp…

    Linux干貨 2016-07-01
  • Find命令以及解壓與壓縮文件的相關指令

    1,find   實時查找,通過遍歷指定路徑完成文件的查找 查找路徑:指定具體目標路徑,默認為當前目錄 查找條件:指定的查找標準,可以文件名,大小,類型,權限等標準進行,默認為找出指定路徑下的所有文件 處理動作:對符合條件的文件做操作,默認輸出至屏幕 find -maxdepth level  最大搜索目錄深度 -mindept…

    2017-08-12
  • CentOS 系統啟動流程

    CentOS 系統啟動流程 一、Linux系統的組成部分:內核+根文件系統 1.內核: 進程管理:進程之間的通信為:IPC(Inter Process Communication)機制,有消息隊列、semerphor、shm、socket(跨主機之間的通信) 內存管理; 網絡管理; 文件系統; 驅動程序; 安全功能; 2.運行中的系統環境可分為兩層:內核空間…

    Linux干貨 2016-09-13
欧美性久久久久