自訂指令碼

定義執行預先清除作業的 LiveClone 備份和 DR 工作流程時,您可以選擇使用 Optim 隱私資料遮蔽功能或自訂指令碼。

如為自訂指令碼,請至少指定一個前置或後置處理指令碼。

  • 視需要指定預先指令碼。預先指令碼可用於在掛載或卸載應用程式之前設定環境。這個指令碼必須位於代管已掛載映像檔的伺服器上名為 /act/scripts 的資料夾中。
  • 在對應的「逾時時間 (以秒為單位)」中,指定腳本完成所需的時間。
  • 視需要指定附註。用於在資料掛載或卸載後,對資料執行作業的後置文字。這個指令碼必須位於代管已掛載映像檔的伺服器上名為 /act/scripts 的資料夾中。
  • 在對應的「逾時時間 (以秒為單位)」中,指定腳本完成所需的時間。

備份和災難復原工作流程前置和後置指令碼

備份和 DR 工作流程會根據排程或需求掛載及卸載備份映像檔。在備份和災難復原工作流程中,您可以呼叫下列項目:

  • 在掛載或卸載映像檔前執行的預先指令碼
  • 在掛載或卸載映像檔後執行的後置指令碼

在掛載或卸載資料之前和之後執行指令碼,可讓您執行下列操作:

  • 清除機密資訊
  • 產生報表
  • 倉儲資料,特別是用於擷取、轉換及載入 (ETL) 作業

指令碼必須位於代管已掛載備份和 DR 工作流程映像檔的伺服器上,且位於名為 /act/scripts 的資料夾中。

環境變數

您可以使用環境變數叫用適用於特定工作、工作類型或應用程式的指令。環境變數開頭為 ACT_。例如,資料庫的環境變數可能如下所示:

    [$ACT_APPNAME =="productiondb"]

或掛載作業的環境變數可能會像這樣:

    [$ACT_JOBTYPE == "mount"]

以下列出常見環境變數及其範例值:

  • JOBNAME:工作名稱,例如 Job_0123456。
  • APPID:應用程式 ID,例如 4186。
  • APPNAME:應用程式名稱,例如 My-DB。
  • HOSTNAME:主機名稱是指這項工作的目標,例如 Jupiter。
  • SOURCEHOST:這個應用程式的來源主機名稱,例如 Saturn。
  • JOBTYPE:工作類別的文字版本,例如掛載或卸載。
  • PHASE:描述工作階段的文字字串,例如「前」或「後」。
  • TIMEOUT:定義指令碼的時間長度,也就是允許指令碼執行的時間長度。
  • 選項:適用於此工作的政策選項。

範例指令碼

以下指令碼範例使用三個環境變數:

  • ACT_JOBTYPE:指出工作是掛載或卸載作業。
  • ACT_PHASE:指出階段是前置還是後置。
  • ACT_MULTI_END:僅在資料庫和其記錄都已掛載時使用。如果為 True,表示資料庫處於可存取的狀態。

    ```sh
    #!/bin/sh
    set +x
    echo "*** Running user script: Job - $ACT_JOBNAME Type - $ACT_JOBTYPE Phase - $ACT_PHASE***"
    
    #Use the first if clause to perform application specific operations during mount and in this example scrub-mount operation.
    
    #Use the second if clause to perform any application specific operation during unmount and in this example, #scrub-unmount operation.
    
    #if [[ $ACT_JOBTYPE == "mount" ]] || [[ $ACT_JOBTYPE == "scrub-mount" ]]; then
    if [[ $ACT_JOBTYPE == "unmount" ]] || [[ $ACT_JOBTYPE == "scrub-unmount" ]]; then
        echo "NO-OP for job type $ACT_JOBTYPE"
        exit 0
    fi
    
    #Use the first if clause to perform application specific operations during the pre phase.
    
    #Use the second if clause to perform application specific operations during the post phase.
    
    #if [[ $ACT_PHASE == "post" ]]; then
    if [[ $ACT_PHASE == "pre" ]]; then
        echo "NO-OP for phase $ACT_PHASE"
        exit 0
    fi
    
    #For multi-phase jobs (database and logs) check if the database has been mounted and the logs applied then #skip logs.
    
    #If the operation needs to be performed in phases other than the last phase, modify the clause.
    
    if [[ -z "$ACT_MULTI_END" ]] && [[ $ACT_MULTI_END != "true" ]]; then
        echo "NO-OP for multi-phase operation"
        exit 0
    fi
    
    cd /act/scripts
    
    echo "**** Running application specific logic: Job - $ACT_JOBNAME Type - $ACT_JOBTYPE Phase - $ACT_PHASE *"
    
    Any application specific commands will go here
    
    echo "** Finished running application specific logic : Job - $ACT_JOBNAME Type - $ACT_JOBTYPE Phase - $ACT_PHASE*"
    exit $?
    ```