2021-2022-1 20211304 《資訊保安專業導論》第十二週學習總結
阿新 • • 發佈:2021-12-11
1、邏輯卷管理器快照
1、快照是特殊的邏輯卷,它是在生成快照時存在的邏輯卷的準確拷貝
2、對於需要備份或者複製的現有資料臨時拷貝以及其它操作來說,快照是最合適的選擇
3、建立的前提,快照和邏輯卷在同一個卷組中, 在生成快照時會分配給它一定的空間,快照中的資料是邏輯卷的原始資料,一旦邏輯卷中的資料發生變動,立即會被複制至快照中,當邏輯卷的快照還原後,快照的生命週期結束;建立快照的卷大小小於等於原始邏輯卷,也可以使用lvextend擴充套件快照
4、快照就是將當時的系統資訊記錄下來,就好像照相一般,若將來有任何資料改動了,則原始資料會被移動到快照區,沒有改動的區域則由快照區和檔案系統共享
5、由於快照區與原本的LV共用很多PE的區塊,因此快照與被快照的LV必須在同一個VG中.系統恢復的時候的檔案數量不能高於快照區的實際容量
2、為現有邏輯卷建立照
1、現有的邏輯卷 [root@centos_8 ~]# lvdisplay --- Logical volume --- LV Path /dev/vg1/xzcdc LV Name xzcdc VG Name vg1 LV UUID 8FTXa6-PWyC-RN9Q-3kXu-cEmf-oxfT-kwk9yk LV Write Access read/write LV Creation host, time centos_8, 2021-12-15 19:26:40 +0800 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 2、建立快照 [root@centos_8 ~]# lvcreate -L +3G -s -n data-snapshot -p /dev/vg1/xzcdc [root@centos_8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert data-snapshot vg1 sri-a-s--- 3.00g xzcdc 0.00 xzcdc vg1 owi-a-s--- 10.00g [root@centos_8 ~]# lvdisplay --- Logical volume --- LV Path /dev/vg1/xzcdc LV Name xzcdc VG Name vg1 LV UUID 8FTXa6-PWyC-RN9Q-3kXu-cEmf-oxfT-kwk9yk LV Write Access read/write LV Creation host, time centos_8, 2021-12-15 19:26:40 +0800 LV snapshot status source of data-snapshot [active] LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/vg1/data-snapshot LV Name data-snapshot VG Name vg1 LV UUID 9RZuZq-7tDr-LDVx-1QA7-jdd1-33De-yk2eP1 LV Write Access read only LV Creation host, time centos_8, 2021-12-15 19:30:51 +0800 LV snapshot status active destination for xzcdc LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 COW-table size 3.00 GiB COW-table LE 768 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:3 3、掛載快照 [root@centos_8 ~]# mkdir -p /mnt/snap [root@centos_8 ~]# mount -o ro /dev/vg1/data-snapshot /mnt/snap
3、LVM xfs快照
1、完成邏輯卷 [root@centos_8 ~]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created. [root@centos_8 ~]# vgcreate vg0 /dev/sdc Volume group "vg0" successfully created [root@centos_8 ~]# lvcreate -n mysql -L +19G vg0 Logical volume "mysql" created. 2、建立xfs快照 [root@centos_8 ~]# lvcreate -n mysql-back -s -L 10M /dev/vg0/mysql Rounding up size to full physical extent 12.00 MiB Logical volume "mysql-back" created. --- Logical volume --- LV Path /dev/vg0/mysql-back LV Name mysql-back VG Name vg0 LV UUID uR9wV8-ylWj-Qpvm-ne8L-U9Tv-yDia-xo5bbk LV Write Access read/write LV Creation host, time centos_8, 2021-12-15 19:44:36 +0800 LV snapshot status active destination for mysql LV Status available # open 0 LV Size 19.00 GiB Current LE 4864 COW-table size 12.00 MiB COW-table LE 3 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:7 3、格式化為xfs檔案系統 [root@centos_8 ~]# mkfs.xfs /dev/vg0/mysql meta-data=/dev/vg0/mysql isize=512 agcount=4, agsize=1245184 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=4980736, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@centos_8 ~]# mkfs.xfs /dev/vg0/mysql-back meta-data=/dev/vg0/mysql-back isize=512 agcount=4, agsize=1245184 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=4980736, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 4、在xfs檔案系統中,建立快照的時候,要有讀寫許可權,不然會掛載不了的 [root@centos_8 ~]# mkdir -pv /mnt/{mysql,snap} [root@centos_8 ~]# mount -o nouuid /dev/vg0/mysql-back /mnt/snap/ [root@centos_8 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 20961280 3636392 17324888 18% / devtmpfs 805608 0 805608 0% /dev tmpfs 821536 0 821536 0% /dev/shm tmpfs 821536 10476 811060 2% /run tmpfs 821536 0 821536 0% /sys/fs/cgroup /dev/sda3 5232640 32948 5199692 1% /data /dev/sda1 15718400 158004 15560396 2% /boot tmpfs 164308 12 164296 1% /run/user/42 tmpfs 164308 0 164308 0% /run/user/0 /dev/mapper/vg0-mysql--back 19912704 32944 19879760 1% /mnt/snap /dev/mapper/vg0-mysql 19912704 32944 19879760 1% /mnt/mysql 4、檢視資料是否同步 5、恢復快照 [root@centos_8 ~]# umount /mnt/sanp/ [root@centos_8 ~]# umount /mnt/mysql/ [root@centos_8 ~]# lvconvert --merge /dev/vg0/mysql-back 6、刪除快照 umount /mnt/mysql-back lvremove /dev/vg0/mysql-back