目標是 sap 的 database restore 流程自動化,不過能半自動化應該就不錯了
因為 script 要寫偵測和應對機制很麻煩 (特別是 batch file)
sapdev01: source sap database
sapdev02: target sap database
還原有一些大前提:
hostname 不同 (如果 hostname 相同事情就單純了,VM帶走就好)
SID 相同
使用 netapp storage (snapdrive)
- sapdev02
- 停止 sap 服務
- 設定服務啟動類型為停用
- 避免服務自動啟用,造成資料庫在還原後損毀
- sapdev01
- 用 sdcli 中斷netapp lun: dev_db_bak
- sapdev02
- 用 sdcli 連線netapp lun: dev_db_bak
- 用 sqlcmd 將 dev 資料庫離線
- 用 sqlcmd 刪除 dev 資料庫
- 執行 d:\rmDev.bat
- 用 sqlcmd 還原資料庫
測試的 command 如下
#sql command line: sqlcmd#backup
sqlcmd -e -s sapdev02 -q "BACKUP DATABASE master TO DISK='D:\backup_master.bak'"
#drop
sqlcmd -e -s sapdev02 -q "drop database DEV"
#cmd: remove all dir and recreate
d:\rmDev.bat
#restore
sqlcmd -e -s sapdev02 -Q "RESTORE DATABASE [DEV] FROM DISK = N'F:\MP_DB_BAK' WITH FILE = 3, MOVE N'DEVDATA1' TO N'D:\DEVDATA1\DEV.mdf', MOVE N'DEVDATA2' TO N'D:\DEVDATA2\DEV_1.ndf', MOVE N'DEVDATA3' TO N'D:\DEVDATA3\DEV_2.ndf', MOVE N'DEVDATA4' TO N'D:\DEVDATA4\DEV_3.ndf', MOVE N'DEVDATA5' TO N'D:\DEVDATA5\DEV_4.ndf', MOVE N'DEVDATA6' TO N'D:\DEVDATA6\DEV_5.ndf', MOVE N'DEVDATA7' TO N'D:\DEVDATA7\DEV_6.ndf', MOVE N'DEVDATA8' TO N'D:\DEVDATA8\DEV_7.ndf', MOVE N'DEVLOG1' TO N'E:\DEVLOG1\DEV_8.ldf', NOUNLOAD, STATS = 10"
#powershell
Set-service SAPDAA_97 -StartupType Disabled
Set-service SAPDEV_00 -StartupType Disabled
Set-service SAPHostControl -StartupType Disabled
Set-service SAPHostExec -StartupType Disabled
Stop-service SAPDAA_97
Stop-service SAPDEV_00
Stop-service SAPHostControl
#Stop-service SAPHostExec
Set-service SAPDAA_97 -StartupType Manual
Set-service SAPDEV_00 -StartupType Manual
Set-service SAPHostControl -StartupType Manual
Set-service SAPHostExec -StartupType Automatic
Start-service SAPDAA_97
Start-service SAPDEV_00
Start-service SAPHostControl
#Start-service SAPHostExec
#snapdrive command line: sdcli#list iscsi initiator
sdcli iscsi_initiator list -s
Target name: iqn.1992-08.com.netapp:sn.142252455
#list igroup
sdcli igroup list -f netapp1
Node Name: SAPDEV02
Initiators Group Name: viaRPC.iqn.1991-05.com.microsoft:sapdev02.domain.local
Initiators Group Type: ISCSI
os-type:Windows
Initiators:
iqn.1991-05.com.microsoft:sapdev02.domain.local
#disconnect disk
sdcli disk disconnect -d f
#connect disk
sdcli disk connect -p netapp1:/vol/sap_dev_bak/dev_db_bak -d f -dtype dedicated -I sapdev01 iqn.1991-05.com.microsoft:sapdev01
sdcli disk connect -p netapp1:/vol/sap_dev_bak/dev_db_bak -d f -dtype dedicated -I sapdev02 iqn.1991-05.com.microsoft:sapdev02.domain.local
若 connect disk 出現這個錯誤訊息Unable to connect to the LUNError: The specified initiator iqn.1991-05.com.microsoft:sapdev02.domain.local is not connected to the target storage system 192.168.0.4.
使用 windows 內建的 iscsi 啟動器,把所有已連接的 iscsi target 中斷連接並移除,指定目標入口(netapp storage IP and PORT),再重新 connect disk 即可
沒有留言:
張貼留言