Escolar Documentos
Profissional Documentos
Cultura Documentos
sh
#!/bin/bash
# UPDATES:
#----------
# 20181126 - 2.0.2 - BONGE: adding alter system checkpoint before the backup,
cd `dirname ${0}`
CURR_DIR=${PWD}
LIB_FILE=${CURR_DIR}/../lib/sby_lib.sh
if [ ! -f ${LIB_FILE} ]; then
exit 1
else
. ${LIB_FILE}
fi;
###############################################################################
# Fonctions communes
###############################################################################
f_usage() {
echo " -d: debug mode (log file will contain more detais)"
echo " -n: noprompt (you won't be asked for confirmation to go ahead)"
echo " transfer: send the backup file to the standby server"
f_check() {
if [ $# -ne 2 ]; then
f_usage
exit 1
fi;
f_init_primary $*
###############################################################################
###############################################################################
f_backup() {
f_wait_user
# f_check_DB_started primary ${ORACLE_SID} >> ${LOG_FILE}
# if [ $? -ne 0 ]; then
# f_log_display "Erreur : Base de donnee primaire non demarree. Sauvegarde de la base impossible."
# exit 1
# fik
if [ ! -d ${PRIMARY_BACKUPFILE_PATH} ]; then
mkdir -p ${PRIMARY_BACKUPFILE_PATH}
if [ ! -d ${PRIMARY_BACKUPFILE_PATH} ]; then
exit 1
fi
fi;
if [ ! -d ${PRIMARY_ARCLOG_PATH} ]; then
mkdir -p ${PRIMARY_ARCLOG_PATH}
if [ ! -d ${PRIMARY_ARCLOG_PATH} ]; then
exit 1
fi
fi;
f_check_archivelog_mode
f_set_archivelog_mode
if [ $? -eq 1 ]; then
exit 1
fi
fi
f_check_force_logging
f_set_force_logging
if [ $? -eq 1 ]; then
f_log_display " >> Error when setting FORCE LOGGING mode. Exiting."
exit 1
fi
fi
#Do not force LOG_ARCHIVE_FORMAT on primary right now. It will be done once sync starts
if [ $? -eq 0 ]; then
fi
RMAN_OUT=${WORKING_PATH}/${DBNAME}_${SYSDATE}_rman_config.$$
crosscheck copy;
crosscheck backup;
exit
EOF
f_log_check ${RMAN_OUT}
if [ $? -ge 1 ]; then
f_log_display " >> Errors have been found in ${RMAN_OUT}. Please check."
else
fi
f_log_display "Backup will be executed now: please confirm you want to go ahead"
f_wait_user
###############################################################################
exit
EOF
f_log_check ${RMAN_OUT}
if [ $? -eq 0 ]; then
else
exit 1
fi
}
###############################################################################
###############################################################################
f_check_user_db(){
DBUSER_INFO=${WORKING_PATH}/${DBNAME}_${SYSDATE}_checkusers.$$
connect / as sysdba
set echo off trim on trims on linesize 255 head off pagesize 0 term off
from v\$session s
order by s.osuser ;
exit
EOF
if [ ${NB_USER} == 0 ]; then
DISPLAY_RES=`cat ${DBUSER_INFO}`
f_log_display "${DISPLAY_RES}"
DBUSER_KILL=${WORKING_PATH}/${DBNAME}_${SYSDATE}_killusers.$$
set trim on trims on linesize 255 head off pagesize 0 term off
from v\$session s
order by s.osuser ;
exit
EOF
DISPLAY_KILLCMD=`cat ${DBUSER_KILL}`
f_log_display "${DISPLAY_KILLCMD}"
echo -n "Supprimer les utilisateurs dans une autre fenetre puis appuyer sur entree pour continuer : "
read reponse
else
fi
return 0
}
###############################################################################
###############################################################################
f_transfer_files() {
f_log_display "This script will send backup files to standby server ${STANDBY_SERVER}..."
f_wait_user
f_debug "$cmd"
eval $cmd
if [ $? -ge 1 ]; then
exit 1
fi
f_debug "$cmd"
eval $cmd
if [ $? -ge 1 ]; then
f_log_display " >> error - Impossible to copy backup files to ${STANDBY_SERVER}:${STANDBY_BACKUPFILE_PATH} "
exit 1
fi
f_create_sby_pfile
if [ $? -eq 1 ]; then
f_log_display " >> Error when creating standby pfile. Exiting."
exit 1
fi
STANDBY_PFILE=${ORACLE_HOME}/dbs/init${STANDBY_SID}.ora
TMP_PFILE=${WORKING_PATH}/${DBNAME}_${SYSDATE}_sbypfile.$$
f_debug "$cmd"
eval $cmd
if [ $? -ge 1 ]; then
exit 1
fi
rm ${TMP_PFILE}
rm ${STANDBY_PFILE}
cmd="${REMOTE_COPY_CMD} ${ORACLE_HOME}/dbs/orapw${ORACLE_SID}
${STANDBY_SERVER}:${ORACLE_HOME}/dbs/orapw${STANDBY_SID}"
f_debug "$cmd"
eval $cmd
if [ $? -ge 1 ]; then
fi
f_debug "$cmd"
eval $cmd
if [ $? -ge 1 ]; then
exit 1
fi
###############################################################################
###############################################################################
f_create_standby () {
f_wait_user
export ORACLE_SID=${STANDBY_SID}
shutdown abort
EOF
SSHPART
# checking result..
exit 1
fi
fi # if1
export ORACLE_SID=${STANDBY_SID}
EOF
SSHPART
if [ $? -eq 0 ]; then
else
fi
#note: STANDBY_DBFILES_PATH includes ALL dir where files reside (even archivelogs)
[ -z "${STANDBY_FILES_PATH}" ] && f_log_display "No value for STANDBY_FILES_PATH. Exiting" && exit 1
f_log_display "Deleting all Standby files..."
err=0
do
else
fi
done
[ ! $err -eq 0 ] && f_log_display >> "error - during standby system cleanup. Exiting" && exit 1
f_log_display " >> ok - Standby directories are ready for a new standby db!"
# Restore Standby
RMAN_LOG=${WORKING_PATH}/${DBNAME}_${SYSDATE}_restore_standby.$$
export ORACLE_SID=${STANDBY_SID}
startup nomount;
restore database;
recover database;
exit
EOF
SSHPART
f_log_checkfilter ${RMAN_LOG}
if [ $? -ge 1 ]; then
fi
###############################################################################
###############################################################################
f_activate_standby () {
f_wait_user
###############################################################################
# Main
###############################################################################
DEBUG_MODE=false
while getopts ":dn" opt; do
case $opt in
d)
DEBUG_MODE=true ;;
n)
SILENT_MODE=Y;;
\?)
exit 1;;
esac
done
if [ $# -lt 2 ]; then
f_usage
exit 1
fi;
f_init $1
f_check_primary_server
f_check_user
#===========================
# SPECIFIC VARIABLES
#===========================
f_log_display "======================================"
f_log_display "======================================"
case $2 in
backup)
f_backup ;;
transfer)
f_transfer_files ;;
create_standby)
f_create_standby;;
activate_standby)
f_activate_standby;;
all)
f_backup
f_transfer_files
f_create_standby
f_activate_standby;;
*)
f_usage
exit 1
;;
esac
exit 0