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 <planned>
- 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 # ############################################################################################### 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_DIR} SWLIB_DIR="/u98/swlib" #################################################################################################### # 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") 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 " "; } # 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 "+++ ${MYDATE_LONG} - 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 "+++ ${MYDATE_LONG} - 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 "+++ ${MYDATE_LONG} - 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 "+++ ${MYDATE_LONG} - Export Monitoring Templates (First OEM Node only)" mkdir -p ${TMP_BACKUP_DIR}/MT 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}/oem_export_template.command select 'emcli export_template -name='''||template_name||''' -target_type='||target_type||' -output_file=${TMP_BACKUP_DIR}/MT/MT_'||template_name||'_' || target_type || '.xml' from sysman.mgmt_templates where is_public = 0 order by template_name; spool off EOF . ${TMP_COMMAND_DIR}/oem_export_template.command tar_it MT splitline fi # Export Metric Extensions (First OEM Node only) if [[ ! -z ${FIRST_OEM} ]] then echo "+++ ${MYDATE_LONG} - Export Metric Extensions (First OEM Node only)" mkdir -p ${TMP_BACKUP_DIR}/ME 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}/oem_export_metric_extension.command 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; spool off EOF . ${TMP_COMMAND_DIR}/oem_export_metric_extension.command tar_it ME splitline fi # Export Incident Rulesets (First OEM Node only) if [[ ! -z ${FIRST_OEM} ]] then echo "+++ ${MYDATE_LONG} - Export Incident Rulesets (First OEM Node only)" mkdir -p ${TMP_BACKUP_DIR}/IR 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}/oem_export_incident_rule_set.command select 'emcli export_incident_rule_set -rule_set_name='''||ruleset_name||''' -rule_set_owner='||owner||' -export_file="${TMP_BACKUP_DIR}/IR/'|| owner || '_' || ruleset_name || '.xml"' from EM_RULE_SETS where owner not in ('<SYSTEM>') and ruleset_name not like 'EMASR%' order by owner, ruleset_name; spool off EOF . ${TMP_COMMAND_DIR}/oem_export_incident_rule_set.command tar_it IR splitline fi # Export Information Publisher Reports (First OEM Node only) if [[ ! -z ${FIRST_OEM} ]] then echo "+++ ${MYDATE_LONG} - 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 "+++ ${MYDATE_LONG} - Export Config" emctl exportconfig oms -dir ${BACKUP_DIR} -keep_host -sysman_pwd "${SYSMAN_PW}" splitline # Export done SYSMAN_PW="" echo "Export done"