Automate the Cloning of Environments

Use the script in this section to automate the cloning of environments.

Create a batch (.bat) or shell (.sh) file containing script similar to the following to clone an environment. The following sample scripts handle these activities:

  • Sign in to the source environment.
  • Use Artifact Snapshot (the snapshot created during the last daily maintenance of the source environment) or another snapshot available in the source environment to convert the target environment as a clone of the source.
  • Optionally, create users and their predefined and application role assignments matching those in the source environment.
  • Optionally, change the daily maintenance start time to match that of the source environment.
  • Sign out.

For detailed information on cloning process, see "Cloning EPM Cloud Environments " in Administering Migration for Oracle Enterprise Performance Management Cloud.

See Automating Script Execution for information on scheduling the script using Windows Task Scheduler.

Windows

  1. Create a batch (.BAT) file named cloneEnvironment.bat containing the following script and save it in a convenient location, for example, C:\automate_scripts.
    @echo off
    set paramRequiredMessage=Syntax: cloneEnvironment.bat "SOURCE USERNAME" "SOURCE PASSWORD FILE" "SOURCE URL" "TARGET USERNAME" "TARGET PASSWORD FILE" "TARGET URL"
    
    set usersandpredefinedroles="false"
    set snapshotname="Artifact Snapshot"
    set dailymaintenancestarttime="true"
    set dirpath=%~dp0
    cd %dirpath:~0,-1%
    
    if "%~1" == "" (
      echo Source User Name is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~2" == "" (
      echo Source Password File is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~3" == "" (
      echo Source URL is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~4" == "" (
      echo Target User Name is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~5" == "" (
      echo Target Password File is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~6" == "" (
      echo Target URL is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    
    PowerShell.exe -File cloneEnvironment.ps1 %~1 %~2 %~3 %~4 %~5 %~6 %usersandpredefinedroles% %snapshotname% %dailymaintenancestarttime%
    
  2. Modify cloneEnvironment.bat to set the values for these parameters:

    Table 3-5 Parameters to set in cloneEnvironment.bat

    Parameter Description
    usersandpredefinedroles Set the value of this parameter to true to clone users and their predefined and application role assignments.

    To clone users and role assignments, the user running the script must have the Service Administrator role and the Identity Domain Administrator in the target environment.

    snapshotname Name of the snapshot in the source environment that should be used for cloning.
    dailymaintenancestarttime Set the value of this parameter to true to change the daily maintenance start time of the cloned environment to that of the source environment. Set this value to false to retain the current daily maintenance start time of the cloned environment.
  3. Create a PowerShell script named cloneEnvironment.ps1 containing the following script and save it in the directory where you saved cloneEnvironment.bat, for example, C:\automate_scripts.
    # Clone Environment script
    
    $source_username=$args[0]
    $source_password=$args[1]
    $source_url=$args[2]
    $target_username=$args[3]
    $target_password=$args[4]
    $target_url=$args[5]
    $usersandpredefinedroles=$args[6]
    $snapshotname=$args[7]
    $dailymaintenancestarttime=$args[8]
    
    epmautomate.bat login "${source_username}" "${source_password}" "${source_url}"
    epmautomate.bat cloneEnvironment "${target_username}" "${target_password}" "${target_url}" UsersAndPreDefinedRoles="${usersandpredefinedroles}" SnapshotName="${snapshotname}" DailyMaintenanceStartTime="${dailymaintenancestarttime}"
    epmautomate.bat logout
  4. Run cloneEnvironment.bat using this command:
    cloneEnvironment.bat "SOURCE USERNAME" "SOURCE PASSWORD FILE" "SOURCE URL" "TARGET USERNAME" "TARGET PASSWORD FILE" "TARGET URL"
    
    For example:
    cloneEnvironment.bat jdoe@example.com C:\mySecuredir\example_pwd.epw https://source_example.oraclecloud.com jdoe@example.com C:\mySecuredir\example_pwd2.epw https://target_example.oraclecloud.com.

Linux

  1. Create a shell script named cloneEnvironment.sh containing the following script and save it in a convenient location.
    #!/bin/bash
    
    # Update the following parameters
    # -------------------------------
    epmautomatescript=/home/user1/epmautomate/bin/epmautomate.sh
    javahome=/home/user1/jdk1.8.0_191/
    usersandpredefinedroles="false"
    snapshotname="Artifact Snapshot"
    dailymaintenancestarttime="true"
    # -------------------------------
    
    source_username="$1"
    source_password="$2"
    source_url="$3"
    target_username="$4"
    target_password="$5"
    target_url="$6"
    
    export JAVA_HOME=${javahome}
    
    if [ "$#" -ne 6 ]; then
        echo "Usage: ./cloneEnvironment.sh <SOURCE USERNAME> <SOURCE PASSWORD FILE> <SOURCE URL> <TARGET USERNAME> <TARGET PASSWORD FILE> <TARGET URL>"
        exit 1
    fi
    
    ${epmautomatescript} login "${source_username}" "${source_password}" "${source_url}" 
    ${epmautomatescript} cloneEnvironment "${target_username}" "${target_password}" "${target_url}" UsersAndPreDefinedRoles="${usersandpredefinedroles}" SnapshotName="${snapshotname}" DailyMaintenanceStartTime="${dailymaintenancestarttime}"
    ${epmautomatescript} logout
  2. Modify cloneEnvironment.sh to set the values for these parameters:

    Table 3-6 Parameters to set in cloneEnvironment.sh

    Parameter Description
    epmautomatescript The absolute path of EPM Automate executable (epmautomate.sh).
    javahome JAVA_HOME location.
    usersandpredefinedroles Set the value of this parameter to true to clone users and their predefined and application role assignments.

    To clone users and role assignments, the user running the script must have the Service Administrator role and the Identity Domain Administrator in the target environment.

    snapshotname Name of the snapshot in the source environment that should be used for cloning.
    dailymaintenancestarttime Set the value of this parameter to true to change the daily maintenance start time of the cloned environment to that of the source environment. Set this value to false to retain the current daily maintenance start time of the cloned environment.
  3. Run cloneEnvironment.sh.
    ./cloneEnvironment.sh "SOURCE USERNAME" "SOURCE PASSWORD FILE" "SOURCE URL" "TARGET USERNAME" "TARGET PASSWORD FILE" "TARGET URL"
    
    For example:
    ./cloneEnvironment.sh jdoe@example.com ./home/secure/example_pwd.epw https://source_example.oraclecloud.com jdoe@example.com ./home/secure/example_pwd.epw2 https://target_example.oraclecloud.com.