The following shell script is used to restore the database automatically. After the restoration is successful, the database is disabled. Because we do not need the bak slave database in the case of no exception in the Prod database.
The following shell script is used to restore the database automatically. After the restoration is successful, the database is disabled. Because we do not need the bak slave database in the case of no exception in the Prod database.
Small and Medium databases are characterized by low database concurrency, low database capacity, limited version functions, and N multiple single instances. Even so, there will be zero loss of the database. Enterprises do not want to spend too much money to ensure the reliability and stability of the database, but I am suffering from these DB jobs. In the last article, the Small and Medium databases rman catalog Backup recovery solution (1), we will continue to provide the recovery scripts and deployment based on the Small and Medium databases.
Small and Medium databases rman catalog Backup Recovery Solution Series:
1. RMAN restores shell scripts
-- The following shell script is used to restore the database automatically. After the restoration is successful, the database is disabled. Because we do not need the bak standby database open in the case of no exception in the Prod database.
-- The global script global_restore in catalog is called during shell script restoration.
-- At the end of the script, we output the database restoration success status to the log file db_restore_rman.log. The advantage of this is that we can set the recovery status of multiple databases for easy viewing.
$ More db_restore_rman_catalog.sh
##=================================================== ====================================
# File name: db_restore_rman_catalog.sh
# Usage: db_restore_rman_catalog.sh <$ Oracle_SID>
# Desc:
# The script uses to restore database with level 0 backupset.
# Author: Robinson
# Blog:
##=================================================== ====================================
#! /Bin/bash
#--------------------
# Define variable
#--------------------
If [-f ~ /. Bash_profile]; then
.~ /. Bash_profile
Fi
#--------------------------
# Check SID
#--------------------------
If [-z "$ {1}"]; then
Echo "Usage :"
Echo "'basename $0 'oracle_sid"
Exit 1
Fi
ORACLE_SID =$ {1}; export ORACLE_SID
LOG_DIR =/u02/database/$ {ORACLE_SID}/backup; export RMAN_DIR
TIMESTAMP = 'date + % Y % m % d % H % m' export TIMESTAMP
RMAN_LOG =$ {LOG_DIR}/$ {ORACLE_SID} _ restore _ $ {TIMESTAMP}. log; export RMAN_LOG
SSH_LOG =$ {LOG_DIR}/$ {ORACLE_SID} _ restore_full _ $ {TIMESTAMP}. log; export SSH_LOG
RETENTION = 5
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
Echo "Start rman to backup at 'date'." >$ {SSH_LOG}
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
$ ORACLE_HOME/bin/rman target/catalog rman_user/xxx @ catadb log =$ {RMAN_LOG} < Startup nomount;
Run {execute global script global_restore ;}
Exit;
EOF
RV =$?
Cat $ {RMAN_LOG }>$ {SSH_LOG}
Echo "" >>$ {SSH_LOG}
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
Echo "MSG1: RMAN restore end at 'date'." >$ {SSH_LOG}
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
If [$ RV-ne "0"]; then
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
Echo "MSG2: RMAN restore error at 'date'." >$ {SSH_LOG}
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
RMAN_STAT = 'failed'
Mail-s "Failed RMAN restore for $ ORACLE_SID on 'hostname'." dba@12306.com <$ {SSH_LOG}
Else
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
Echo "MSG2: No error found for RMAN restore at 'date'." >$ {SSH_LOG}
Echo "------------------------------------------------------------------" >$ {SSH_LOG}
RMAN_STAT = 'succeed'
Rm-rf $ {RMAN_LOG} 2>/dev/null
Fi
Echo "'date' + % F % x' -- $0 $1 $ RMAN_STAT">/u01/comm_scripts/db_restore_rman.log
Exit