使用伺服務端 Groovy 指令碼複製環境

您可以在伺服器端 Groovy 指令碼中包含 EPM Automate 命令,用於複製環境以因應災難復原。這允許在不涉及任何內部部署的情況下設定災難復原。

如果密碼包含特殊字元,請參閱處理特殊字元。此外,為了配合您的環境,可自行替換這些參數:

Table 4-1 要變更的參數

參數 描述
password 負責在來源環境中執行複製操作的服務管理員,其使用的密碼。
targetpassword 負責在目標環境中執行複製操作的服務管理員,其使用的密碼。
username 服務管理員在來源環境中的使用者 ID。
targetusername 服務管理員在目標環境中的使用者 ID。此使用者還必須被指派至目標環境中的識別網域管理員角色。
email_id 您計劃將關於複製程序的資訊傳送至哪一個電子郵件地址。

進行密碼加密時會用到的指令碼

EpmAutomate automate = getEpmAutomate()

//Encrypt the password of a Service Administrator in the source environment
EpmAutomateStatus encryptstatus1 = automate.execute('encrypt', 'password','encryptionKey','sourcePassword.epw')
if(encryptstatus1.getStatus() != 0)  throwVetoException(encryptstatus1.getOutput())
println(encryptstatus1.getOutput())

//Encrypt the password of a Service Administrator in the target environment
//This user must also have the Identity Domain Administrator 
//role in the target environment

EpmAutomateStatus encryptstatus2= automate.execute('encrypt', 'targetpassword',
'encryptionKey', 'targetPassword.epw')
if(encryptstatus2.getStatus() != 0) throwVetoException(encryptstatus2.getOutput())
println(encryptstatus2.getOutput())

複製環境時會用到的指令碼

這個指令碼會使用透過上述指令碼建立的加密密碼檔案。

EpmAutomate automate = getEpmAutomate()

//Log into the target environment
EpmAutomateStatus loginstatus = automate.execute('login', 'username','targetPassword.epw' , 'targeturl')
if(loginstatus.getStatus() != 0) throwVetoException(loginstatus.getOutput())
println(loginstatus.getOutput())

//Recreate the target environment
EpmAutomateStatus recreatestatus = automate.execute('recreate' , '-f' )
if(recreatestatus.getStatus() != 0) throwVetoException(recreatestatus.getOutput())
println(recreatestatus.getOutput())

//Copy Artifact Snapshot from the source environment 
//to the target environment
EpmAutomateStatus copystatus = automate.execute('copysnapshotfrominstance',
'Artifact Snapshot', 'sourceusername', 'sourcePassword.epw','source url')
if(copystatus.getStatus() != 0) throwVetoException(copystatus.getOutput())
println(copystatus.getOutput())

//import Artifact Snapshot into the target environment
EpmAutomateStatus importstatus = automate.execute('importsnapshot', 'Artifact Snapshot')
println(importstatus.getOutput())

//Send an email to a designated user with the status of the 
//snapshot import process
EpmAutomateStatus emailstatus = automate.execute('sendmail', 'email_id' ,'Status of DR' , 'BODY='+ importstatus.getOutput())
println(emailstatus.getOutput())

//Sign out of the target environment
EpmAutomateStatus logoutstatus = automate.execute('logout')
println(logoutstatus.getOutput())