實驗環(huán)境
實驗選擇HPE 3PAR作為storage server, 通過Fiber Channel 連接 ESXi hosts, 3個ESXi 組成cluster, 被vCenter管理. 實驗環(huán)境沒有啟用vSAN, 集群的datastore以local disks 和 SAN storage構(gòu)成.
如果VM需要添加disk, 我們會在3PAR上創(chuàng)建volume, 依次export到3臺ESXi主機, 這個volume以RDM(Raw Disk Mapping)的形式直接與VM相連, 作為VM的一塊local disk.
因此我們這里創(chuàng)建了一臺VM, 并為他添加額外一塊disk作為數(shù)據(jù)盤, 至此虛擬機上有2塊硬盤,一塊是安裝了OS的系統(tǒng)disk, 另外一塊是用于存儲數(shù)據(jù)的虛擬磁盤,來自于3PAR.
VM: 30.80.133.18
DISK1: OS disk 100G
DISK2: Data disk 154G(RDM from 3PAR)
備份Backup
對數(shù)據(jù)盤(Disk2)進行pvcreate操作, 創(chuàng)建相應(yīng)的PV, 顯示如下
cqaljnh0sh:~ # pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/360002ac00000000047002ba00001aab6 datav lvm2 a-- 153.98g 4.00m
基于上一步創(chuàng)建的PV, 創(chuàng)建VG "datav", 顯示如下
cqaljnh0sh:~ # vgs
VG #PV #LV #SN Attr VSize VFree
datav 1 1 0 wz--n- 153.98g 4.00m
創(chuàng)建LV "lvol0", 格式化后mount到目錄/sap/data, 顯示如下
cqaljnh0sh:~ # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvol0 datav -wi-ao---- 153.98g
cqaljnh0sh:~ # mount -l | grep lvol0
/dev/mapper/datav-lvol0 on /sap/data type ext4 (rw,relatime,stripe=4096)
添加數(shù)據(jù)到/sap/data目錄, 并創(chuàng)建文件作為標記
cqaljnh0sh:~ # ll /sap/data/
total 40
-rw------- 1 root root 18937 Dec 8 04:18 agent-installer-221201.log
drwx------ 2 root root 16384 Dec 5 08:40 lost+found
-rw-r--r-- 1 root root 35 Dec 5 09:50 test.log
cqaljnh0sh:~ # cat /sap/data/test.log
this is test file for base volume.
在3PAR端, 為這個volume創(chuàng)建snapshot, 并且export snapshot給3個ESXi hosts. 至此先不要為VM添加這個RDM.
PLNN13PAR8-SAP cli% showvv N1TRLNTh98Yu94T7hZRdPgMQPavJ.SP
-Rsvd(MiB)- -(MiB)-
Id Name Prov Compr Dedup Type CopyOf BsId Rd -Detailed_State- Snp Usr VSize
44664 N1TRLNTh98Yu94T7hZRdPgMQPavJ.SP snp NA NA vcopy N1TRLNTh98Yu94T7hZRdPgMQPavJ 11168 RW normal -- -- 157696
---------------------------------------------------------------------------------------------------------------------------------------
1 total 0 0 157696
現(xiàn)在模擬誤操作破壞了/sap/data目錄數(shù)據(jù), 刪掉其中一個文件, 更改另一個文件內(nèi)容.
cqaljnh0sh:~ # rm -f /sap/data/agent-installer-221201.log
cqaljnh0sh:~ # vi /sap/data/test.log
cqaljnh0sh:~ # ll /sap/data/
total 20
drwx------ 2 root root 16384 Dec 5 08:40 lost+found
-rw-r--r-- 1 root root 49 Dec 8 04:38 test.log
cqaljnh0sh:~ # cat /sap/data/test.log
this is test file, change content after snapshot
恢復(fù)部分文件Restore
由于上個步驟模擬了文件損壞的場景, 我們現(xiàn)在需要恢復(fù)損壞的文件, 而不是恢復(fù)整塊磁盤數(shù)據(jù). 如果需要整個volume的恢復(fù), 可以直接3PAR promote snapshot to base volume就可以了.
以防萬一, 操作之前建議備份好現(xiàn)有LVM structure, 需要的時候通過vgcfgrestore命令恢復(fù)LVM structure.
我們這里有開機和關(guān)機兩種辦法來添加snapshot RDM disk給VM,
cqaljnh0sh:~ # vgcfgbackup -f restore.sp datav
-
HOT 開機添加
unmount LV "lvol1" 和文件目錄, de-active 我們所要操作的VG "datav",
cqaljnh0sh:~ # umount /sap/data/
cqaljnh0sh:~ # vgchange -a n datav
0 logical volume(s) in volume group "datav" now active
給VM添加snapshot的RDM disk, 然后remove 原來"Hard Disk2". VM reconfigure 結(jié)束后, active VG "datav", 并mount "lvol1"到/sap/data目錄
cqaljnh0sh:~ # vgchange -ay datav
1 logical volume(s) in volume group "datav" now active
cqaljnh0sh:~ # mount /dev/datav/lvol0 /sap/data/
-
Cold 關(guān)機添加
Shutdown VM, 給VM添加snapshot的RDM disk, 然后remove 原來"Hard Disk2". VM reconfigure 結(jié)束后, startup VM, 檢查PV/VG/LV狀態(tài)
cqaljnh0sh:~ # pvscan
PV /dev/sda3 VG vg00 lvm2 [98.80 GiB / 5.80 GiB free]
PV /dev/mapper/360002ac0000000004700ae780001aab6 VG datav lvm2 [153.98 GiB / 4.00 MiB free]
Total: 2 [252.79 GiB] / in use: 2 [252.79 GiB] / in no VG: 0 [0 ]
cqaljnh0sh:~ # vgscan | grep datav
Found volume group "datav" using metadata type lvm2
cqaljnh0sh:~ # lvscan | grep lvol0
ACTIVE '/dev/datav/lvol0' [153.98 GiB] inherit
我們可以看到, 所有的PV/VG/LV都是正常的, 不需要任何多余的配置.
保存data, 恢復(fù)損壞文件
接下來我們檢查恢復(fù)后的數(shù)據(jù)
cqaljnh0sh:~ # ll /sap/data/
total 44
drwxr-xr-x 6 root root 4096 Dec 2 07:34 acf
drwx------ 2 root root 16384 Dec 2 07:29 lost+found
-rw------- 1 root root 18937 Dec 2 07:33 agent-installer-221201.log
-rw-r--r-- 1 root root 53 Dec 5 07:38 test.log
cqaljnh0sh:~ # cat /sap/data/test.log
this is test file for base volume.
我們可以看到刪除掉的文件恢復(fù)回來, 修改過的文件也回到原來. 保存恢復(fù)過的data到安全的地方, 為以后覆蓋損壞的data做好準備.
保存好數(shù)據(jù)后, 我們采取以上同樣的辦法掛回原來的數(shù)據(jù)volume, 最后Copy 恢復(fù)的數(shù)據(jù)到損壞的目錄.