Based on the cool blog-post about Advanced Backup strategies for Oracle Enterprise Manager written by Robert Crames, I wrote a small script to export some target independent configurations which may be needed or helpful in the case of a recovery or migration to a new Enterprise Manager setup.
The setup is quite simple. Create the shell-script, mark them as executable, adapt the variables like the backup directory -> fire!
Configuration-Part
ORACLE_HOME
<<< the ORACLE_HOME of the OEM Installation. You can use Trivadis BasEnv by let this empty and uncomment the line containing „. oraenv.ksh …“ Do not forget to replace the placeholder **oem_name** with the correct value.SYSMAN_PW
<<< this variable contains the password. the password can be written in plaintext or you call your custom password function in a sub-shell likeSYSMAN_PW=$(password-function-xy)
.
Example:SYSMAN_PW="XYZInPlainText"
SYSMAN_PW=$(getpw.pl -p SYSMAN@OMS)
<- with BasEnv and KeePass ext.
BACKUP_DIR
<<< this is the directory where the backup-files are written to. in a multi-oms environment the usage of a sub-directory called the same as the node-name is a good approach.TMP_BACKUP_DIR
<<< During the exporting-process i.e. the metric templates are written in dedicated files per metric template will be combined in a single tar file. this needs a temporary directory. the required spaces is minimal and can be the/tmp
directory.TMP_COMMAND_DIR
<<< the script generates the emctl/emcli scripts for the export itself. this variable is used to define the patch for the commands. this can be set to the same value as ofTMP_BACKUP_DIR
.TMP_COMMAND_DIR=${TMP_BACKUP_DIR}
SWLIB_DIR
<<< the location of the software-library
Startup Parameters
Backup the OEM in a single-oms Environment is simple: take all you can and copy them to a save place. In a multi-oms Environment you may backup on the additional nodes only the node-specific content (the classic emctl exportconfig oms
…)
The scripts detects the First-OEM-Node automatically by checking the AdminServer is running on this Node. You can force this by setting the startup parameter -first_oem
.
The first_oem-Mode includes the following:
- SWLIB Backup (only wednesday and sunday) -> more about this below
- Admin-Groups
- OEM Properties
- Monitoring Templates
- Metric Extensions
- Incident Rulesets
- Information Publisher Reports
- BIPublisher Reports
- Export Config
the normal backup includes the export-config-Part only.
There is another startup parameter called -force_include_swlib
.
The SWLib can be growing with the time and a daily backup is not needed (my opinion…). by default the SWLib will be automatically included if the following prerequisites are met: It is the First-OEM-Node and Weekday is Wednesday or Sunday
You can force the SWLib by setting the startup parameter -force_include_swlib.
Scheduling
You can schedule the backup easy by using crontab as scheduling-tool
# Backup OEM-Nodes
15 23 * * * /u99/oem_backup.ksh >*myLogDir*/oem_backup_$$.log 2>&1
Script
#!/bin/ksh
###############################################################################################
# Trivadis AG, Infrastructure Managed Services
# Saegereistrasse 29, 8152 Glattbrugg, Switzerland
# -----------------------------------------------------------------------------
# Name.......: oem_backup.ksh
# Author.....: Gabriel Keusen
# Editor.....: Gabriel Keusen
# Date.......: 19.11.2020
# Purpose....: Script to refresh backup oem content (contains no database backup!)
# Notes......: can be used in combination with Trivadis Basenv (i.e. with configured KeePass extension) to enhance the security by removing plain-text passwords
# Reference..:
# Parameters.: -first_oem: force backup all content (if AdminServer is running on this Node -first_oem is set implicit)
# -force_include_swlib: force including Software-Library. normally SWLib is included only twice a week (day 3 and 7)
#Version: 1.0.0.0
#ChangeLog:
# 19.11.2020 - gak - Initial Version
# 20.11.2020 - gak - Export BIP-Reports if export-scripts exists
#
###############################################################################################
if [[ -f ${HOME}/.BE_HOME ]];then . ${HOME}/.BE_HOME >/dev/null && . ${BE_HOME}/bin/basenv.ksh >/dev/null; fi
####################################################################################################
# SET ENV
ORACLE_HOME="/u01/app/oracle/product/oem_latest"
# when Trivadis BasEnv, uncomment the following line and replace the placeholder **oem_name** with the correct value:
#. oraenv.ksh **oem_name** || exit 1
# SET CREDENTIALS
# you can enter the password in plaintext. better use a functionallity to hide the password i.e. with Trivadis Basenv and the KeePass extension
# SYSMAN_PW="myHighSecurePasswordForOEM"
# SYSMAN_PW=$(password-function-xy)
SYSMAN_PW=$(getpw.pl -p SYSMAN@OMS)
# SET DIRECTORIES
BACKUP_DIR="/u99/backup_oem/$(hostname)"
TMP_BACKUP_DIR=/tmp/backup_oem
TMP_COMMAND_DIR=/tmp/backup_oem
SWLIB_DIR="/u98/swlib"
# BIP (optional)
BIP_SCRIPT_PATH="/u99/scripts/export_bip_reports.ksh"
####################################################################################################
# SET ADDIDIONAL VARS
PATH="${ORACLE_HOME}/bin/:${PATH}"
MYDATE="$(date +"%m%d%y")_$$"
MYDATE_LONG="$(date +"%d %h %y / %T")"
ARGS=$*
if [[ "${ARGS}" =~ "-first_oem" || $(ps -ef | grep -v -e "grep" | grep -c -e "EMGC_ADMINSERVER") == "1" ]];then echo "INFO: Parameter -first_oem set or AdminServer is running" && FIRST_OEM=TRUE; fi
if [[ "${ARGS}" =~ "-force_include_swlib" ]]; then echo "INFO: Parameter -force_include_swlib set" && FORCE_INCLUDE_SWLIB=TRUE; fi
OEM_REPO_CONNECTION_STRING=$(emctl config oms -list_repos_details | grep -e "Repository Connect Descriptor" | sed -e "s/Repository Connect Descriptor : //g")
# FUNCTIONS
tar_it() { echo "--> tar it..."; tar_file=${BACKUP_DIR}/${1}_${MYDATE}.tar; cd ${TMP_BACKUP_DIR}; tar cfz ${tar_file} ${1} && ls -l ${tar_file} >/dev/null && echo "--> done"; }
splitline() { echo "-----------------------------------------------------------------------------------------------------------"; echo " "; }
export_by_query()
{
mkdir -p ${TMP_BACKUP_DIR}/${1}
sqlplus -s SYSMAN/${SYSMAN_PW}@"${OEM_REPO_CONNECTION_STRING}"<<EOF
set head off
set feedback off
set trimout on
set trimspool on
set lines 1000 pages 0
spool ${TMP_COMMAND_DIR}/${1}.command
${2}
spool off
EOF
. ${TMP_COMMAND_DIR}/${1}.command
tar_it ${1}
}
####################################################################################################
# LOGIN TO OEM
emcli sync > /dev/null || emcli login -username="SYSMAN" -password="${SYSMAN_PW}"
#CREATE BACKUP-DIR IF NOT EXISTS
mkdir -p ${BACKUP_DIR}
# CLEANUP TEMP-DIR
rm -rf ${TMP_BACKUP_DIR}
mkdir -p ${TMP_BACKUP_DIR}
# SWLIB Backup (First OEM Node only) (only wednesday and sunday)
if [[ ! -z "${FIRST_OEM}" ]]
then
if [[ $(date +%u) -eq 3 || $(date +%u) -eq 7 || ! -z "${FORCE_INCLUDE_SWLIB}" ]]
then
echo "+++ $(date +"%d %h %y / %T") - SWLIB Backup (First OEM Node only) (only wednesday and sunday or -force_include_swlib)"
tar cvfz ${BACKUP_DIR}/swlib_${MYDATE}.tar ${SWLIB_DIR}/*
splitline
fi
fi
# Export Admin-Groups (First OEM Node only)
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export Admin-Groups (First OEM Node only)"
emcli export_admin_group >${BACKUP_DIR}/AdmGrp_${MYDATE}.xml && echo "--> done"
splitline
fi
# Dump OEM Properties
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Dump OEM Properties"
emctl list properties -sysman_pwd "${SYSMAN_PW}" >${BACKUP_DIR}/OEM_Properties_${MYDATE}.txt && echo "--> done"
splitline
fi
# Export Monitoring Templates (First OEM Node only)
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export Monitoring Templates (First OEM Node only)"
export_by_query "MT" "select 'emcli export_template -name='''||template_name||''' -target_type='||target_type||' -output_file=${TMP_BACKUP_DIR}/MT/MT_'||replace(template_name,' ','')||'_' || target_type || '.xml' from sysman.mgmt_templates where is_public = 0 order by template_name;"
splitline
fi
# Export Metric Extensions (First OEM Node only)
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export Metric Extensions (First OEM Node only)"
export_by_query "ME" "select 'emcli export_metric_extension -file_name=''${TMP_BACKUP_DIR}/ME/'||name||'_V'||version||''' -target_type='||target_type||' -name='''||name||''' -version='||version from SYSMAN.EM_MEXT_VERSIONS_E order by name, version;"
splitline
fi
# Export Incident Rulesets (First OEM Node only)
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export Incident Rulesets (First OEM Node only)"
export_by_query "IR" "select 'emcli export_incident_rule_set -rule_set_name='''||ruleset_name||''' -rule_set_owner='||owner||' -export_file=${TMP_BACKUP_DIR}/IR/' || replace(owner,' ','') || '_' || replace(ruleset_name,' ','_') || '.xml' from EM_RULE_SETS where owner not in ('<SYSTEM>') and ruleset_name not like 'EMASR%' order by owner, ruleset_name;"
splitline
fi
# Export Information Publisher Reports (First OEM Node only)
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export Information Publisher Reports (First OEM Node only)"
mkdir -p ${TMP_BACKUP_DIR}/REP
emcli get_reports | sed "s/, / /g" | awk 'BEGIN{ FS=","}{x=$1; gsub(/ |-|=|:|\/|\(|\)/, "",x); print "emcli export_report -title="$1" -owner="$2" -output_file=${TMP_BACKUP_DIR}/REP/REP_"x".xml" }'
tar_it REP
splitline
fi
# Export Config
echo "+++ $(date +"%d %h %y / %T") - Export Config"
emctl exportconfig oms -dir ${BACKUP_DIR} -keep_host -sysman_pwd "${SYSMAN_PW}"
splitline
# Export BIP-Reports
if [[ ! -z ${FIRST_OEM} ]]
then
echo "+++ $(date +"%d %h %y / %T") - Export BIP-Reports (First OEM Node only)"
tar cfz ${BACKUP_DIR}/BIP_${MYDATE}.tar $(cat ${ORACLE_HOME}/domain-registry.xml | grep -e "domain location" | cut -d '"' -f2)/bidata/components/bipublisher/repository
splitline
fi
# Export done
SYSMAN_PW=""
echo "$(date +"%d %h %y / %T") Export done"