プライマリ環境での日次メンテナンス完了後の、プライマリ環境からスタンバイ環境への毎日のクローニング

スタンバイ環境をプライマリ環境にあわせて最新の状態に保つには、プライマリ環境で日次メンテナンスが完了したらすぐに、次のスクリプトを使用してOracle Fusion Cloud Enterprise Performance Managementプライマリ環境をスタンバイ環境にクローニングします。

次のカスタム・スクリプトは、その日にスケジュールされた日次メンテナンスが完了しているかどうかを識別してから、環境をクローニングします。

Windowsスクリプト

次のPowerShellスクリプトをコピーすることで、dailyclone.ps1を作成します。
# Clone Environment script
#
# Update the following parameters
# -------------------------------
$users_and_predefined_roles="false"
$daily_maintenance_start_time="true"
$data_management="true"
$app_audit="true"
$job_console="true"
$stored_snapshots_and_files="false"
# -------------------------------

$source_username=$args[0]
$source_password=$args[1]
$source_url=$args[2]
$target_username=$args[3]
$target_password=$args[4]
$target_url=$args[5]

if ($($args.count) -ne 6) {
    echo "Usage: ./dailyclone.ps1 <SOURCE USERNAME> <SOURCE PASSWORD> <SOURCE URL> <TARGET USERNAME> <TARGET PASSWORD> <TARGET URL>"
    exit 1
}

$amw_time=""

function getDailyMaintenanceStartTime {
    $amwstring=$(epmautomate.bat getDailyMaintenanceStartTime)
    $elements=$amwstring.split(' ')
    $amwtime=$elements[0]
    return $amwtime
}

function goToSleep ($amw_time){
    $current_mdy=Get-Date -AsUTC -UFormat "%m/%d/%Y"
    $current_date_time=Get-Date -AsUTC -UFormat "%m/%d/%Y %H:%M:%S"
    $current_epoch=Get-Date -Date $current_date_time -UFormat "%s"
    $target_date_time=[DateTime]"${current_mdy} ${amw_time}"
    $target_epoch=Get-Date -Date $target_date_time -UFormat "%s"
    $sleep_seconds=$target_epoch - $current_epoch

    # Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if ($sleep_seconds -lt 0) {
        $sleep_seconds=$sleep_seconds + 86400
    }

    $sleep_ts=New-TimeSpan -Seconds ${sleep_seconds}
    $sleep_hms="${sleep_ts}" -replace '^\d+?\.'

    echo "Current time is ${current_date_time}. Sleeping for ${sleep_hms}, until daily maintenance start time of ${amw_time}."
    Start-Sleep -Seconds $sleep_seconds
}

function deleteArtifactSnapshotIfExists {
    if (artifactSnapshotExists) {
        $command_del=$(epmautomate.bat deletefile "Artifact Snapshot")
    }
}

function artifactSnapshotExists {
    $filelist=$(epmautomate.bat listfiles)
    if ("$filelist".contains("Artifact Snapshot")) {
        return $true
    else
        return $false
    }
}

function cloneEnvironment {
    echo "Checking to see if daily maintenance processing has completed ..."
    while ($true) {
        if (artifactSnapshotExists) {
            echo "Daily maintenance processing has completed ..."
            break
        } else {
            echo "Sleeping for 30 seconds before the next check to see if daily maintenance processing has completed ..."
            Start-Sleep -Seconds 30
        }
    }

    echo "Encrypting target password ..."
    epmautomate.bat encrypt "${target_password}" "oracleKey" "target_password.epw"

    echo "Cloning environment ..."
    epmautomate.bat cloneEnvironment "${target_username}" "target_password.epw" "${target_url}" "SnapshotName=Artifact Snapshot" "UsersAndPreDefinedRoles=${users_and_predefined_roles}" "DataManagement=${data_management}" "appAudit=${app_audit}" "jobConsole=${job_console}" "storedSnapshotsAndFiles=${stored_snapshots_and_files}" "dailyMaintenanceStartTime=${daily_maintenance_start_time}"
}

echo "Beginning clone environment script."
echo "Logging into server ..."
epmautomate.bat login ${source_username} ${source_password} ${source_url}
$amwtime=getDailyMaintenanceStartTime
goToSleep ($amwtime)
deleteArtifactSnapshotIfExists
cloneEnvironment
echo "Logging out of server ..."
epmautomate.bat logout
echo "Clone environment script processing has completed."

Linux/UNIXのスクリプト

次のスクリプトをコピーすることで、dailyclone.shを作成します。
#!/bin/bash

# Update the following parameters
# -------------------------------
epmautomatescript="LOCATION_EPM_AUTOMATE_EXECUTABLE"
javahome="LOCATION_JAVA_HOME"
users_and_predefined_roles="false"
data_management="true"
app_audit="true"
job_console="true"
stored_snapshots_and_files="false"
daily_maintenance_start_time="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: ./dailyclone.sh SOURCE_USERNAME SOURCE_PASSWORD SOURCE_URL TARGET_USERNAME TARGET_PASSWORD TARGET_URL"
    exit 1
fi

amw_time=""

getDailyMaintenanceStartTime() {
    amw_time=$(${epmautomatescript} getDailyMaintenanceStartTime | cut -d' ' -f1)
}

goToSleep() {
    current_mdy=$(date -u +%m/%d/%Y)
    current_date_time=$(date -u)
    current_epoch=$(date +%s)
    target_epoch=$(date -d "${current_mdy} ${amw_time}" +%s)
    sleep_seconds=$(($target_epoch - $current_epoch))

    # Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if [[ ${sleep_seconds} -lt 0 ]]
    then
        sleep_seconds=$((sleep_seconds + 86400))
    fi

    sleep_hms=$(date -d@${sleep_seconds} -u +%H:%M:%S)

    echo "Current time is ${current_date_time}. Sleeping for ${sleep_hms}, until daily maintenance start time of ${amw_time}."
    sleep $sleep_seconds
}

deleteArtifactSnapshotIfExists() {
    found=1
    filelist=$(${epmautomatescript} listfiles)
    if [[ ${filelist} == *"Artifact Snapshot"* ]]
    then
        command_del=$(${epmautomatescript} deletefile "Artifact Snapshot")
    fi
}

artifactSnapshotExists() {
    found=1

    filelist=$(${epmautomatescript} listfiles)
    if [[ ${filelist} == *"Artifact Snapshot"* ]]
    then
        found=0
    else
        found=1
    fi

    echo ${found}
}

cloneEnvironment() {
    local found=1

    while true
    do
        found=$(artifactSnapshotExists)
        if [[ ${found} -eq 0 ]]
        then
            echo "Daily maintenance processing has completed ..."
            break
        else
            echo "Sleeping for 30 seconds before the next check to see if daily maintenance processing has completed ..."
            sleep 30
        fi
    done

    echo "Encrypting target password ..."
    ${epmautomatescript} encrypt "${target_password}" "oracleKey" "target_password.epw"

    echo "Cloning environment ..."
    ${epmautomatescript} cloneEnvironment "${target_username}" "target_password.epw" "${target_url}" "SnapshotName=Artifact Snapshot" "UsersAndPreDefinedRoles=${users_and_predefined_roles}" "DataManagement=${data_management}" "appAudit=${app_audit}" "jobConsole=${job_console}" "storedSnapshotsAndFiles=${stored_snapshots_and_files}" "dailyMaintenanceStartTime=${daily_maintenance_start_time}"
}

echo "Beginning clone environment script."
echo "Logging into server ..."
${epmautomatescript} login ${source_username} ${source_password} ${source_url}
getDailyMaintenanceStartTime
goToSleep
deleteArtifactSnapshotIfExists
cloneEnvironment
echo "Logging out of server ..."
${epmautomatescript} logout
echo "Clone environment script processing has completed."

Groovyスクリプト

次のコードをコピーすることで、dailyclone Groovyスクリプトを作成します。
// Clone Environment script

// Update the following parameters
String source_username="USERNAME"
String source_password="PASSWORD!"
String source_url="URL OF THE SOURCE ENVIRONMENT"
String target_username="USERNAME"
String target_password="PASSWORD"
String target_url="URL OF THE TARGET ENVIRONMENT"
String snapshot_name="Artifact Snapshot"

// -------------------------------

// Do not update the following parameters
String users_and_predefined_roles="false"
String data_management="true"
String app_audit="true"
String job_console="true"
String stored_snapshots_and_files="false"
String daily_maintenance_start_time="true"
// -------------------------------

def LogMessage(String message) {
    def date = new Date()
    def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
    println('[' + sdf.format(date) + '] ' + message);
}

def LogOperationStatus(EpmAutomateStatus opstatus) {
    def returncode = opstatus.getStatus()
    if (returncode != 0){
        LogMessage(opstatus.getOutput())
    }
    LogMessage('return code: ' + returncode)
}

def getDailyMaintenanceStartTime(EpmAutomate automate) {
    LogMessage("Operation: getDailyMaintenanceStartTime")
    EpmAutomateStatus amwtimestatus = automate.execute('getDailyMaintenanceStartTime')
    LogOperationStatus(amwtimestatus)
    def amwstring=(amwtimestatus.getOutput())
    def elements=amwstring.split(' ')
    def amwtime=elements[0]
    return amwtime
}

def goToSleep(String amw_time){
    def date = new Date()
    def current_mdy = new SimpleDateFormat("MM/dd/yyyy")
    def current_date_time = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
    float current_epoch = date.getTime() / 1000
    def pattern = "MM/dd/yyyy HH:mm:ss"
    def input = current_mdy.format(date) + " " + amw_time + ":00"
    def target_date_time = Date.parse(pattern, input)
    float target_epoch = target_date_time.getTime() / 1000
    int sleep_seconds = Math.round(target_epoch - current_epoch)

    //Today's AMW start time has already passed, so add 24 hours to sleep_seconds
    if (sleep_seconds < 0) {
        sleep_seconds = sleep_seconds + 86400
    }
    
    def sleep_milliseconds = sleep_seconds * 1000
    LogMessage("Current time is " + current_date_time.format(date) + ". Sleeping until daily maintenance start time of " + amw_time + ":00.")
    sleep(sleep_milliseconds)
}

boolean artifactSnapshotExists(EpmAutomate automate,String snapshot_name) {
    LogMessage("Operation: listfiles")
    EpmAutomateStatus listfilesstatus = automate.execute('listfiles')
    String filelist=(listfilesstatus.getItemsList())
    LogOperationStatus(listfilesstatus)
    
    if (filelist.contains(snapshot_name)) {
        return true
    } else {
        return false
    }
}

def deleteArtifactSnapshotIfExists(EpmAutomate automate,String snapshot_name){
    if (artifactSnapshotExists(automate,snapshot_name)) {
        LogMessage("Operation: deletefile " + snapshot_name)
        EpmAutomateStatus deletefilestatus = automate.execute('deletefile',snapshot_name)
        LogOperationStatus(deletefilestatus)
    }
}

def waitForDailyMaintenanceToComplete(EpmAutomate automate,String snapshot_name) {
    LogMessage("Checking to see if daily maintenance processing has completed ...")
    while (true) {
        if (artifactSnapshotExists(automate,snapshot_name)) {
            LogMessage("Daily maintenance processing has completed ...")
            break
        } else {
            LogMessage("Sleeping for 30 seconds before the next check to see if daily maintenance processing has completed ...")
            sleep(30000)
        }
    }
}

LogMessage("Clone environment script processing beginning ...")

EpmAutomate automate = getEpmAutomate()

LogMessage("Operation: login " + source_username + " " + source_password + " " + source_url)
EpmAutomateStatus status = automate.execute('login',source_username,source_password,source_url)
LogOperationStatus(status)

String amwtime = getDailyMaintenanceStartTime(automate)
goToSleep (amwtime)
deleteArtifactSnapshotIfExists(automate,snapshot_name)
waitForDailyMaintenanceToComplete(automate,snapshot_name)

LogMessage("Operation: encrypt " + target_password + " oracleKey target_password.epw")
status = automate.execute('encrypt',target_password,'oracleKey','target_password.epw')
LogOperationStatus(status)

LogMessage("Operation: cloneEnvironment " + target_username + " target_password.epw " + target_url + " SnapshotName=" + snapshot_name + " UsersAndPreDefinedRoles=" + users_and_predefined_roles + " DataManagement=" + data_management + " appAudit=" + app_audit + " jobConsole=" + job_console + " storedSnapshotsAndFiles=" + stored_snapshots_and_files + " dailyMaintenanceStartTime=" + daily_maintenance_start_time)
EpmAutomateStatus cloneenvironmentstatus = automate.execute('cloneEnvironment',target_username,"target_password.epw",target_url,"SnapshotName=" + snapshot_name,"UsersAndPreDefinedRoles=" + users_and_predefined_roles,"DataManagement=" + data_management,"appAudit=" + app_audit,"jobConsole=" + job_console,"storedSnapshotsAndFiles=" + stored_snapshots_and_files,"dailyMaintenanceStartTime=" + daily_maintenance_start_time)
LogOperationStatus(cloneenvironmentstatus)

LogMessage("Operation: logout ")
status = automate.execute('logout')
LogOperationStatus(status)

LogMessage ("Clone environment script processing has completed.")

スクリプトの実行

  1. 前のセクションのいずれかからスクリプトをコピーして、dailyclone.ps1dailyclone.shまたはdailyclone Groovyスクリプトを作成します。
  2. スクリプトを更新します:

    dailyclone.shの更新:

    • epmautomatescript (EPM自動化の実行可能ファイルの場所を指定)。例: epmautomatescript="/home/utils/EPMAutomate/bin/epmautomate.sh"
    • javahome (EPM自動化で使用されるJDKがインストールされているディレクトリを指定)。例: "/home/user1/jdk1.8.0_191"
    dailyclone.ps1およびdailyclone.shの更新:
    • users_and_predefined_roles: ユーザーとその事前定義済役割割当てをクローニングするには、この値をtrueに設定します(アクセス制御グループは常にクローニングされます)。
    • data_management: データ統合レコードをクローニングしない場合は、この値をfalseに設定します。データ統合レコードは、ソース環境とターゲット環境の両方が同じ月次更新の場合、またはターゲット環境がソース環境よりも1つ新しい更新である場合のみクローニングできることに注意してください。たとえば、22.01のデータ管理レコードは、別の22.01環境または22.02環境のみにクローニングできます。

      Narrative Reporting環境およびOracle Fusion Cloud Enterprise Data Management環境では無視されます。

    • app_audit: PlanningフリーフォームおよびEnterprise Profitability and Cost Managementアプリケーションの、アプリケーション監査データをクローニングしない場合は、この値をfalseに設定します。

      Financial Consolidation and CloseおよびTax Reportingの監査情報は常にクローニングされます。

    • job_console: ジョブ・コンソール・データをクローニングしない場合は、この値をfalseに設定します。
    • stored_snapshots_and_files: ソース環境の受信ボックスおよび送信ボックスの最上位レベルにあるフォルダ(サブフォルダはクローニングされません)の内容をクローニングする場合は、この値をtrueに設定します。
    • daily_maintenance_start_time: クローニングされたターゲット環境のメンテナンス開始時間をソース環境の時間にリセットしない場合は、この値をfalseに設定します。
    dailyclone Groovyスクリプトの更新:
    • source_usernameは、サービス管理者のユーザー名です。ユーザー役割および事前定義済役割をクローニングするには、アイデンティティ・ドメイン管理者役割が必要です。
    • source_passwordは、SOURCE_USERNAMEによって識別されるユーザーのパスワードです。
    • source_urlは、クローニングする環境のURLです。
    • target_usernameは、サービス管理者のユーザー名です。ユーザー役割および事前定義済役割をクローニングするには、アイデンティティ・ドメイン管理者役割が必要です。
    • target_passwordは、TARGET_USERNAMEで識別されるユーザーのパスワードです。
    • target_URLは、ターゲット環境のURLです。
  3. dailyclone.ps1dailyclone.shまたはdailyclone Groovyスクリプトを実行します:

    Windows

    • コマンド・ウィンドウで、dailyclone.ps1が格納されているフォルダに移動します。
    • 次のコマンドを実行します: ./dailyclone.ps1 SOURCE_USERNAME SOURCE_PASSWORD SOURCE_URL TARGET_USERNAME TARGET_PASSWORD TARGET_URL。次の表で、これらの値の説明を参照してください。

    Table 3-7 パラメータの説明

    パラメータ 説明
    SOURCE_USERNAME サービス管理者のユーザー名。さらに、ユーザー役割および事前定義済役割をクローニングするには、このユーザーにアイデンティティ・ドメイン管理者役割が必要です。
    SOURCE_PASSWORD SOURCE_USERNAMEによって識別されるユーザーのパスワード。
    SOURCE_URL クローニングする環境のURL。
    TARGET_USERNAME ターゲット環境のサービス管理者のユーザー名。さらに、ユーザー役割および事前定義済役割をクローニングするには、このユーザーにアイデンティティ・ドメイン管理者役割が必要です。
    TARGET_PASSWORD TARGET_USERNAMEによって識別されるユーザーのパスワード。
    TARGET_URL ターゲット環境のURL。
    Linux/UNIX
    • UNIXまたはLinuxシェルで、dailyclone.shが格納されているディレクトリに移動します。
    • 次のコマンドを実行します: ./dailyclone.sh SOURCE_USERNAME SOURCE_PASSWORD SOURCE_URL TARGET_USERNAME TARGET_PASSWORD TARGET_URL。前の表で、これらの値の説明を参照してください。
    Groovy

    EPM自動化をインストールしないコマンドの実行を参照してください。