Small and medium-sized databases are characterized by less database concurrency, smaller database capacity, limited version functionality, and more than one instance of N. However, the loss level of the database can also be lost in 0 cases. Enterprises do not want to spend too much money and to ensure the reliable stability of the database, but the bitter evil I do these db. Next to an article, the small and medium database RMAN CATALOG Backup recovery Scenario (i), we continue to give a small and medium-sized database based on the recovery of the script and its deployment.
1. Rman Restore shell Script
[Python]View PlainCopyprint?
- --The following shell script is used to automate the database restore, and the database is closed after the restore succeeds. Because we have no exception in the PROD database, we do not need Bak's standby library open
- The--shell script does a restore when the global script in catalog is called Global_restore
- --At the very end of the script, we output the DB Restore success status to the log file Db_restore_rman.log, and the benefit is that we can set the restore state of multiple db to make it easier to see
- $ 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:http://blog.csdn.net/robinson_0612
- ##====================================================================
- #!/bin/bash
- # --------------------
- # Define Variable
- # --------------------
- If [-f ~/.bash_profile]; Then
- . ~/.bash_profile
- Fi
- # --------------------------
- # Check SID
- # --------------------------
- If [-Z ' ${1} '];then
- Echo "Usage:"
- echo "' basename ' 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/[email protected] Log=${rman_log} <<eof
- 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 '." [Email protected] 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 '--$ $RMAN _stat" >>/u01/comm_scripts/db_restore_rman.log
- Exit
2. Detect the Restore state shell script
[Python]View PlainCopyprint?
- --We used a shell script to detect the success of the final restore state on the day of multiple db and output all current records to the Ck_restore.log log
- --The end of the script sends a message that lists all the states after the restore, and is a summary report for multiple DB restore.
- $ more ck_restore.sh
- ##====================================================================
- # # File Name:ck_restore.sh
- # # Usage:ck_restore.sh
- # Desc:
- # # The script uses to check RMAN restore Log for current day
- # # and send mail to DBA
- # # Author:robinson
- # # blog:http://blog.csdn.net/robinson_0612
- ##====================================================================
- #!/bin/bash
- If [-f ~/.bash_profile];
- Then
- . ~/.bash_profile
- Fi
- Rev_dir=/u01/comm_scripts
- dt= ' Date ' +%f '
- Cat/dev/null >${rev_dir}/ck_restore.log
- Cat ${rev_dir}/db_restore_rman.log | grep "${dt}" >>${rev_dir}/ck_restore.log
- Total= ' Cat ${rev_dir}/ck_restore.log |wc-l '
- Suc= ' grep succeed ${rev_dir}/ck_restore.log |wc-l '
- Fail= ' grep FAILED ${rev_dir}/ck_restore.log |wc-l '
- echo "" >>ck_restore.log
- ECHO-E "The total DB of current recovery are $total in ' hostname ' \ n" >>${rev_dir}/ck_restore.log
- ECHO-E "The number of Succee is: ${suc} \ n" >>${rev_dir}/ck_restore.log
- ECHO-E "The number of fail is: ${fail} \ n" >>${rev_dir}/ck_restore.log
- Mail-s "RMAN Restore Summary for ' hostname ' at ' date + '%a%b%d%Y '" [email protected]12306.com <${rev_dir}/c K_restore.log
3. Deploy the Restore shell script to crontab
[Python]View PlainCopyprint?
- --first encapsulate multiple db requiring automatic restore into a single file, as follows:
- --finally call ck_restore.sh footstep to detect all DB restore status and send Rman summary report message
- $ more full_resotre_by_rman.sh
- #!/bin/bash
- /u01/comm_scripts/db_restore_rman_catalog.sh BC1200
- /u01/comm_scripts/db_restore_rman_catalog.sh AF2630
- /u01/comm_scripts/ck_restore.sh
- --Deploy to Crontab
- -note, whether it is a backup or a recovery script, we are deployed through Bak server crontab to relieve prod pressure
- #Rman RESTORE Database
- 0 3 * * 1-6/u01/comm_scripts/full_resotre_by_rman.sh
Ext.: http://blog.csdn.net/leshami/article/details/9850665
Small and Medium database RMAN CATALOG Backup recovery Scheme (ii)