Backing up Planning Analytics

A Planning Analytics administrator can use the Planning Analytics administration console to create a backup.

Before you begin

The workstation where you run the installation is set up as a client workstation and includes the OpenShift CLI.

Procedure

  1. Ensure you are logged into the OpenShift cluster with the oc command line tool.
  2. Create a new file called backup-pa.sh
  3. Copy and paste the following script into backup-pa.sh:
    #!/usr/bin/env bash
    #
    #       Licensed Materials - Property of IBM
    #
    #       IBM Cognos Products: pa
    #
    #       (C) Copyright IBM Corp. 2022
    #
    #       US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
    # -----------------------------------------------------------------------------
    #
    set +x
    
    PA_NAMESPACE=${1:zen}
    
    BACKUP_DATE_FORMAT="${BACKUP_DATE_FORMAT:-%Y_%m_%d_%H_%M_%S}"
    DATE=$(date +"${BACKUP_DATE_FORMAT}")
    BACKUP_DIRECTORY=./backup-${DATE}
    
    PA_COUCHDB_POD=""
    PA_MONGO_POD=""
    PA_MYSQL_POD=""
    PA_MYSQL_POD_1=""
    PA_MYSQL_POD_2=""
    PA_REDIS_POD=""
    
    KUBERNETES_CMD=oc
    
    
    function _getPod {
      local idx=0
      local maxIdx=0	
      local pod=''
      local pods=()
      local result=''
      local container=''
      
      pod="${1}${PAW_INSTANCE_ID}"
      container="${2}"
      
      if ! read -r -a pods <<< "$( ${KUBERNETES_CMD} get pods -o=jsonpath='{range .items[*]}{.metadata.name}{.name}{" "}{end}' -l name="${pod}" -n "${PA_NAMESPACE}" 2>&1 )"; then
        exit "${pods[@]}"
      fi
    
      if [ "${#pods[@]}" != "1" ]; then
        exit "${pods[@]}"
      fi
      
      maxIdx=${MAX_TIME:-30}
      while [ "${idx}" -lt "${maxIdx}" ]; do
    	result=$( ${KUBERNETES_CMD} exec "${pods[0]}" -c "${container}" -n "${PA_NAMESPACE}" -- /bin/bash -c 'ls >& /dev/null' 2>&1 )
        if [[ "${result}" != *"container not found"* ]]; then
    	  break
        fi
        sleep 1
        (( idx=idx+1 ))
      done
    
      if [ "${idx}" -eq "${maxIdx}" ]; then
        exit "$( _getMessage MSG_CONTAINER_NOT_FOUND "${container}" )"
      fi
        
      echo "${pods[0]}"
    }
    
    function _getPods {
      PA_COUCHDB_POD=$( _getPod 'couchdb-data1' 'couchdb1-data1' )
      PA_MONGO_POD=$( _getPod 'mongo-data1' 'mongo-data1' )
      PA_MYSQL_POD=$( _getPod 'mysql-server' 'mysql-server' )
      PA_MYSQL_POD_1=$( _getPod 'mysql-server1' 'mysql-server1' )
      PA_MYSQL_POD_2=$( _getPod 'mysql-server2' 'mysql-server2' )
      PA_REDIS_POD=$( _getPod 'redis-data1' 'redis-data1' )
    }
    
    function _flushMySQLHost {
      local result=''
      
      if ! result=$( ${KUBERNETES_CMD} exec "${1}" -c "${2}" -n "${PA_NAMESPACE}" -- /bin/bash -c "/tools/flush-hosts.sh" 2>&1 ); then
        exit "${result}"
      fi  
    }
    
    function _flushMySQLHosts {
      _flushMySQLHost "${PA_MYSQL_POD}" "mysql-server"
      _flushMySQLHost "${PA_MYSQL_POD_1}" "mysql-server1"
      _flushMySQLHost "${PA_MYSQL_POD_2}" "mysql-server2"    
    }
    
    function _backupDatabase {
      local result=''
    
      result=$( ${KUBERNETES_CMD} exec "${2}" -c "${3}" -n "${PA_NAMESPACE}" -- /bin/bash -c "/tools/backup.sh" 2>&1 )
    
      if ! result=$( ${KUBERNETES_CMD} cp "${PA_NAMESPACE}/${2}:/tmp/${1}.tgz" "${BACKUP_DIRECTORY}/${1}.tgz" -c "${3}" 2>&1 ); then
        exit "${result}"
      fi
    
      if ! result=$( ${KUBERNETES_CMD} exec "${2}" -c "${3}" -n "${PA_NAMESPACE}" -- /bin/bash -c "rm /tmp/${1}.tgz" 2>&1 ); then
        exit "${result}"
      fi
    }
    
    
    _getPods
    _backupDatabase couchdb "${PA_COUCHDB_POD}" couchdb-data1
    _flushMySQLHosts
    _backupDatabase mongo "${PA_MONGO_POD}" mongo-data1
    _backupDatabase mysql "${PA_MYSQL_POD}" mysql-server
    _backupDatabase redis "${PA_REDIS_POD}" redis-data1
  4. Execute the script ./backup-pa.sh <NAMESPACE WHERE PA IS RUNNING>
  5. A folder named backup-${DATE}x in the current directory is created and contains the Planning Analytics instance backup.