使用服务器端 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())