两种shell脚本:验证rman备份集的有效性,用rmab备份集做定期恢复实验
脚本1:rman_validate_v2.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | Quanwen Zhao |
# | guestart@163.com |
# | guestart.blog.51cto.com |
# |-----------------------------------------------------------------------|
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# |-----------------------------------------------------------------------|
# | DATABASE : Oracle |
# | OS ENV : CentOS 6.6 X86_64 Bit |
# | File : rman_validate_v2.sh |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | PURPOSE : This bash script file used to validate rman backupset |
# | that is generated last night via validate command on |
# | Oracle Database Server. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/17/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to test this script in a |
# | development environment before attempting to run it in |
# | production. |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# | 导入.bash_profile中的环境变量 |
# +-----------------------------------------------------------------------+
source ~/.bash_profile;
# +-----------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT THE ABSOLUTE PATH OF THE SHELL COMMAND |
# | 定义shell外部变量的绝对路径 |
# +-----------------------------------------------------------------------+
export AWK=`which awk`
export DATE=`which date`
export ECHO=`which echo`
# +-----------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# | 定义一些常用的字符集变量,如rman备份集的位置,rman备份日志的位置 |
# +-----------------------------------------------------------------------+
export BACK_LOG=~/rman_backup/log
export RMAN=$ORACLE_HOME/bin/rman
export SQLPLUS=$ORACLE_HOME/bin/sqlplus
export YESTERDAY=`$DATE +%Y-%m-%d -d yesterday`
export DAY_OF_WEEK=`$DATE +%u`
export BSKEY_LIST=
export BSKEY_LIST_WITH_COMMA=
# +-----------------------------------------------------------------------+
# | QUERY ALL OF BS_KEY VALUE OF RMAN BACKUPSET YESTERDAY INTO BSKEY_LIST |
# | 查询rman备份集的BS_KEY值部分,即用sql语句查出前一天生成的rman备份集的 |
# | 的BS_KEY值存到一个变量BS_KEY中,不止一个bs_key,所以又用一个变量 |
# | BSKEY_LIST_WITH_COMMA将这些值用逗号括起来 |
# +-----------------------------------------------------------------------+
BSKEY_LIST=`
$SQLPLUS -S /nolog << EOF
connect / as sysdba
set echo off feedback off heading off underline off
select bs_key from v\\$backup_set_details where device_type='DISK' and completion_time > to_date('$YESTERDAY','yyyy-mm-dd') order by 1;
exit;
EOF`
# +-----------------------------------------------------------------------+
# | WITH AWK COMMAND TO PROCESS BSKEY_LIST SAVE TO BSKEY_LIST_WITH_COMMA |
# +-----------------------------------------------------------------------+
BSKEY_LIST_WITH_COMMA=`$ECHO $BSKEY_LIST | $AWK -F' ' '{ for ( i=1; i<NF; i++ ) print $i","; print $NF }'`
# +-----------------------------------------------------------------------+
# | VALIDATE RMAN BACKUPSET THAT IS GENERATED LAST NIGHT |
# | 用"validate backupset BS_KEY值列表check logical;",形如 |
# | validate backupset 6197,6198,6199... check logical;这条命令依次校验前 |
# | 一天生成的所有rman备份集的有效性,可以根据实际情况修改 |
# +-----------------------------------------------------------------------+
case $DAY_OF_WEEK in
6)
$RMAN nocatalog log $BACK_LOG/validate_`$DATE +%Y-%m-%d`.log <<EOF
connect target /
run {
allocate channel d1 type disk maxpiecesize 16g;
allocate channel d2 type disk maxpiecesize 16g;
allocate channel d3 type disk maxpiecesize 16g;
allocate channel d4 type disk maxpiecesize 16g;
validate backupset $BSKEY_LIST_WITH_COMMA check logical;
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
exit;
EOF
;;
1|2|3|4|5|7)
$RMAN nocatalog log $BACK_LOG/validate_`$DATE +%Y-%m-%d`.log <<EOF
connect target /
validate backupset $BSKEY_LIST_WITH_COMMA check logical;
exit;
EOF
;;
esac
脚本2:
read_me.txt:
总述
----
这个README_CN.txt文件是专门用于在Oracle数据库服务器上做RMAN备份和恢复实验的.
有两台Oracle数据库服务器,一台是源Oracle数据库,即生产环境;另一台是目标Oracle数据库,
它只安装了Linux操作系统和Oracle数据库软件。我们需要在这台服务器上用源Oracle数据库
的RMAN备份集恢复出一个数据库.
整个RMAN恢复过程包括5个SHELL脚本文件(包括每个脚本文件的介绍)
------------------------------------------------------------
-- 1. ssh_mutual_trust_linux_for_source.sh ==> ( 在源主机上设置目标主机的SSH互信功能 )
-- 2. ssh_mutual_trust_linux_for_target.sh ==> ( 在目标主机上设置源主机的SSH互信功能 )
-- 3. collect_info_from_source_oracle.sh ==> ( 从源主机收集一些信息 )
-- 4. scp_log_file_to_target.sh ==> ( 远程复制文件"/tmp/source_oracle_dbinfo.log"到目标主机 )
-- 5. rman_restore_and_recover_to_target_oracle.sh ==> ( 从目标主机用RMAN还原和恢复Oracle )
执行SHELL脚本的流程
-------------------
所有的SHELL脚本都是在Oracle用户下执行.
首先,在源和目标的Oracle数据库服务器上设置SSH互信功能,即在源主机上执行脚本"ssh_mutual_trust_linux_for_source.sh",
在目标主机上执行脚本"ssh_mutual_trust_linux_for_target.sh".
其次,在源主机上执行脚本"collect_info_from_source_oracle.sh"用来收集一些基本信息,然后再执行脚本"scp_log_file_to_target.sh",
即远程复制文件"/tmp/source_oracle_dbinfo.log"到目标主机的"/tmp"目录.
最后,在目标主机执行脚本"rman_restore_and_recover_to_target_oracle.sh",用来还原和恢复Oracle数据库.
scripts1: ssh_mutual_trust_linux_for_source.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | Quanwen Zhao |
# | guestart@163.com |
# | guestart.blog.51cto.com |
# |-----------------------------------------------------------------------|
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# |-----------------------------------------------------------------------|
# | DATABASE : Oracle |
# | OS ENV : Linux |
# | File : ssh_mutual_trust_linux_for_source.sh |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | PURPOSE : This bash script file used to set ssh mutual trust |
# | between source and target linux server.Therefore,every |
# | operation between two,such as ssh and scp,have no |
# | password to interaction. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/10/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to test this script in a |
# | development environment before attempting to run it in |
# | production. |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# +-----------------------------------------------------------------------+
source ~/.bash_profile;
# +-----------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# +-----------------------------------------------------------------------+
export DATE=`which date`
export ECHO=`which echo`
export HOSTNAME=`which hostname`
export PING=`which ping`
export SSH_KEYGEN=`which ssh-keygen`
export SSH_COPY_ID=`which ssh-copy-id`
export TEE=`which tee`
export LOCAL_HOST=`$HOSTNAME`
# Define Remote Host,For example,REMOTE_HOST='orcl1',According to your situation to set.
# At same time,Please add the host name and IP address of the remote host to hosts file
# that is located in etc subdir of '/' directory in root user.
# For example,as follows:
# 127.0.0.1 localhost localhost.localdomain
# ::1 localhost6 localhost6.localdomain6
# 172.16.10.11 orac11
# 172.16.10.13 orcl13 <<== Remote Host's host name and IP address
export REMOTE_HOST='orcl_adg'
export ALIVEHOST=""
export DEADHOST=""
export EXITCODE=""
export LOGFILE=/tmp/ssh_mutual_trust_`$DATE +%F-%H-%M-%S`.log
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | CHECKING IF THE REMOTE HOST ARE REACHABLE |" | $TEE -a $LOGFILE
$ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE
$PING -c 5 -w 5 $REMOTE_HOST
EXITCODE=`$ECHO $?`
if [ $EXITCODE = 0 ]
then
ALIVEHOST="$ALIVEHOST $REMOTE_HOST"
else
DEADHOST="$DEADHOST $REMOTE_HOST"
fi
if test -z "$DEADHOST"
then
$ECHO Remote host reachability check succeeded. | $TEE -a $LOGFILE
$ECHO The following host is reachable: $ALIVEHOST. | $TEE -a $LOGFILE
$ECHO -e "Proceeding further...\n" | $TEE -a $LOGFILE
else
$ECHO Remote host reachability check failed. | $TEE -a $LOGFILE
$ECHO The following host is not reachable: $DEADHOST. | $TEE -a $LOGFILE
$ECHO -e "Exiting now...\n" | $TEE -a $LOGFILE
exit 1
fi
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | CREATE SSH PRIVATE AND PUBLIC KEY,COPY PUBLIC KEY TO REMOTE HOST |" | $TEE -a $LOGFILE
$ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | The script will setup SSH connectivity from local host to remote host.|" | $TEE -a $LOGFILE
$ECHO "# | After the script is executed, the user can use SSH to run commands on |" | $TEE -a $LOGFILE
$ECHO "# | the remote host or copy files between local host and the remote host |" | $TEE -a $LOGFILE
$ECHO "# | without being prompted for passwords or confirmations. |" | $TEE -a $LOGFILE
$ECHO "# | |" | $TEE -a $LOGFILE
$ECHO "# | NOTE 1: |" | $TEE -a $LOGFILE
$ECHO "# | As part of the setup procedure, this script will use 'ssh' and 'scp' |" | $TEE -a $LOGFILE
$ECHO "# | to copy files between the local host and the remote host. Since the |" | $TEE -a $LOGFILE
$ECHO "# | script does not store passwords, you may be prompted for the pass- |" | $TEE -a $LOGFILE
$ECHO "# | words during the execution of the script whenever 'ssh' or 'scp' is |" | $TEE -a $LOGFILE
$ECHO "# | invoked. |" | $TEE -a $LOGFILE
$ECHO "# | |" | $TEE -a $LOGFILE
$ECHO "# | NOTE 2: |" | $TEE -a $LOGFILE
$ECHO "# | As per ssh requirements, this script will secure the user home |" | $TEE -a $LOGFILE
$ECHO "# | directory and the .ssh directory by revoking group and world write |" | $TEE -a $LOGFILE
$ECHO "# | privileges to those directories. |" | $TEE -a $LOGFILE
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO -e "\nThe Local Host is: "$LOCAL_HOST | $TEE -a $LOGFILE
$ECHO -e "The Remote Host is: "$REMOTE_HOST"\n" | $TEE -a $LOGFILE
$SSH_KEYGEN -t rsa | $TEE -a $LOGFILE
$SSH_COPY_ID -i ~/.ssh/id_rsa.pub oracle@$REMOTE_HOST | $TEE -a $LOGFILE
script2: ssh_mutual_trust_linux_for_target.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | Quanwen Zhao |
# | guestart@163.com |
# | guestart.blog.51cto.com |
# |-----------------------------------------------------------------------|
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# |-----------------------------------------------------------------------|
# | DATABASE : Oracle |
# | OS ENV : Linux |
# | File : ssh_mutual_trust_linux_for_target.sh |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | PURPOSE : This bash script file used to set ssh mutual trust |
# | between source and target linux server.Therefore,every |
# | operation between two,such as ssh and scp,have no |
# | password to interaction. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/10/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to test this script in a |
# | development environment before attempting to run it in |
# | production. |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# +-----------------------------------------------------------------------+
source ~/.bash_profile;
# +-----------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# +-----------------------------------------------------------------------+
export DATE=`which date`
export ECHO=`which echo`
export HOSTNAME=`which hostname`
export PING=`which ping`
export SSH_KEYGEN=`which ssh-keygen`
export SSH_COPY_ID=`which ssh-copy-id`
export TEE=`which tee`
export LOCAL_HOST=`$HOSTNAME`
# Define Remote Host,For example,REMOTE_HOST='orcl1',According to your situation to set.
# At same time,Please add the host name and IP address of the remote host to hosts file
# that is located in etc subdir of '/' directory in root user.
# For example,as follows:
# 127.0.0.1 localhost localhost.localdomain
# ::1 localhost6 localhost6.localdomain6
# 172.16.10.13 orcl13
# 172.16.10.11 orac11 <<== Remote Host's host name and IP address
export REMOTE_HOST='orcl'
export ALIVEHOST=""
export DEADHOST=""
export EXITCODE=""
export LOGFILE=/tmp/ssh_mutual_trust_`$DATE +%F-%H-%M-%S`.log
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | CHECKING IF THE REMOTE HOST ARE REACHABLE |" | $TEE -a $LOGFILE
$ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE
$PING -c 5 -w 5 $REMOTE_HOST
EXITCODE=`$ECHO $?`
if [ $EXITCODE = 0 ]
then
ALIVEHOST="$ALIVEHOST $REMOTE_HOST"
else
DEADHOST="$DEADHOST $REMOTE_HOST"
fi
if test -z "$DEADHOST"
then
$ECHO Remote host reachability check succeeded. | $TEE -a $LOGFILE
$ECHO The following host is reachable: $ALIVEHOST. | $TEE -a $LOGFILE
$ECHO -e "Proceeding further...\n" | $TEE -a $LOGFILE
else
$ECHO Remote host reachability check failed. | $TEE -a $LOGFILE
$ECHO The following host is not reachable: $DEADHOST. | $TEE -a $LOGFILE
$ECHO -e "Exiting now...\n" | $TEE -a $LOGFILE
exit 1
fi
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | CREATE SSH PRIVATE AND PUBLIC KEY,COPY PUBLIC KEY TO REMOTE HOST |" | $TEE -a $LOGFILE
$ECHO -e "# +-----------------------------------------------------------------------+\n" | $TEE -a $LOGFILE
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO "# | The script will setup SSH connectivity from local host to remote host.|" | $TEE -a $LOGFILE
$ECHO "# | After the script is executed, the user can use SSH to run commands on |" | $TEE -a $LOGFILE
$ECHO "# | the remote host or copy files between local host and the remote host |" | $TEE -a $LOGFILE
$ECHO "# | without being prompted for passwords or confirmations. |" | $TEE -a $LOGFILE
$ECHO "# | |" | $TEE -a $LOGFILE
$ECHO "# | NOTE 1: |" | $TEE -a $LOGFILE
$ECHO "# | As part of the setup procedure, this script will use 'ssh' and 'scp' |" | $TEE -a $LOGFILE
$ECHO "# | to copy files between the local host and the remote host. Since the |" | $TEE -a $LOGFILE
$ECHO "# | script does not store passwords, you may be prompted for the pass- |" | $TEE -a $LOGFILE
$ECHO "# | words during the execution of the script whenever 'ssh' or 'scp' is |" | $TEE -a $LOGFILE
$ECHO "# | invoked. |" | $TEE -a $LOGFILE
$ECHO "# | |" | $TEE -a $LOGFILE
$ECHO "# | NOTE 2: |" | $TEE -a $LOGFILE
$ECHO "# | As per ssh requirements, this script will secure the user home |" | $TEE -a $LOGFILE
$ECHO "# | directory and the .ssh directory by revoking group and world write |" | $TEE -a $LOGFILE
$ECHO "# | privileges to those directories. |" | $TEE -a $LOGFILE
$ECHO "# +-----------------------------------------------------------------------+" | $TEE -a $LOGFILE
$ECHO -e "\nThe Local Host is: "$LOCAL_HOST | $TEE -a $LOGFILE
$ECHO -e "The Remote Host is: "$REMOTE_HOST"\n" | $TEE -a $LOGFILE
$SSH_KEYGEN -t rsa | $TEE -a $LOGFILE
$SSH_COPY_ID -i ~/.ssh/id_rsa.pub oracle@$REMOTE_HOST | $TEE -a $LOGFILE
script3: collect_info_from_source_oracle.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | |
# | Quanwen Zhao |
# | |
# | guestart@163.com |
# | |
# | guestart.blog.51cto.com |
# | |
# |-----------------------------------------------------------------------|
# | |
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# | |
# |-----------------------------------------------------------------------|
# | |
# | DATABASE : Oracle |
# | |
# | OS ENV : Linux |
# | |
# | File : collect_info_from_source_oracle.sh |
# | |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | |
# | PURPOSE : This bash script file used to collect some information |
# | |
# | from local oracle database server,and save them to a log |
# | |
# | file. |
# | |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/10/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to test this script in a |
# | |
# | development environment before attempting to run it in |
# | |
# | production. |
# | |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | |
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
source ~/.bash_profile;
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
export AWK=`which awk`
export CAT=`which cat`
export DATE=`which date`
export DU=`which du`
export ECHO=`which echo`
export GREP=`which grep`
export LS=`which ls`
export TEE=`which tee`
export TOUCH=`which touch`
export TR=`which tr`
export UNIQ=`which uniq`
###########################################################################
export LSNRCTL=$ORACLE_HOME/bin/lsnrctl
export SQLPLUS=$ORACLE_HOME/bin/sqlplus
###########################################################################
export YESTERDAY=`$DATE +%Y-%m-%d -d yesterday`
###########################################################################
export DBINFO=
export DBID=
export DBNAME=
export OSNAME=
###########################################################################
export HOST_AND_VER=
export HOST_NAME=
export DBVERSION=
###########################################################################
export ARCH_LOG=
export ARCH_LOG_PATH=
export ARCH_LOG_SIZE_M=
export ARCH_LOG_TOTAL_SIZE_M=
###########################################################################
export DB_FILE=
export DB_FILE_PATH=
export DB_FILE_SIZE_M=
export DB_FILE_TOTAL_SIZE_M=
export DBFILE_PATH='/tmp/dbfile_path.log'
###########################################################################
export BLOCK_CHANGE_TRACKING_FILE=
export BLOCK_CHANGE_TRACKING_FILE_DIR=
export BLOCK_CHANGE_TRACKING_FILE_PATH=
export BLOCK_CHANGE_TRACKING_FILE_SIZE_M=
###########################################################################
export FAST_OR_FLASH_RECO_AREA=
export FAST_OR_FLASH_RECO_AREA_PATH=
###########################################################################
export RMAN_BACK=
export RMAN_BACK_PATH=
export RMAN_BACK_SIZE_M=
export RMAN_BACK_TOTAL_SIZE_M=
export RMANBACK_PATH='/tmp/rmanback_path.log'
###########################################################################
export RMAN_LATEST_SPFILE=
export RMAN_LATEST_SPFILE_DIR=
export RMAN_LATEST_SPFILE_PATH=
export RMAN_LATEST_SPFILE_SIZE_M=
###########################################################################
export RMAN_LATEST_CTL_FILE=
export RMAN_LATEST_CTL_FILE_DIR=
export RMAN_LATEST_CTL_FILE_PATH=
export RMAN_LATEST_CTL_FILE_SIZE_M=
###########################################################################
export LISTENER_FILE_PATH=
###########################################################################
export BASE_ADMIN_DBNAME_DIR=
###########################################################################
export PASSWORD_FILE_PATH=
###########################################################################
export ORACLE_SERVICE_NAME=
export ORACLE_SERVICE_NAME_VALUE=
###########################################################################
export SOURCE_DBINFO='/tmp/source_oracle_dbinfo.log'
export LOGFILE="/tmp/collect_info_from_source_oracle_`$DATE +%F-%H-%M-%S`.log"
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY VALUE OF DBID,DBNAME AND OSNAME |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_dbinfo () {
DBINFO=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select dbid || ',' || lower(name) || ',' || platform_name as dbinfo from v\\$database;
exit;
EOF`
DBID=`$ECHO $DBINFO | $AWK -F',' '{ print $1 }'`
DBNAME=`$ECHO $DBINFO | $AWK -F',' '{ print $2 }'`
OSNAME=`$ECHO $DBINFO | $AWK -F',' '{ print $3 }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY VALUE OF HOST_NAME AND DBVERSION |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_hostname_and_dbver () {
HOST_AND_VER=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select host_name || ',' || version from v\\$instance;
exit;
EOF`
HOST_NAME=`$ECHO $HOST_AND_VER | $AWK -F',' '{ print $1 }'`
DBVERSION=`$ECHO $HOST_AND_VER | $AWK -F',' '{ print $2 }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH AND TOTAL SIZE (MB) OF ARCHIVE LOG |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_arch_log () {
ARCH_LOG=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select distinct destination from v\\$archive_dest order by 1;
exit;
EOF`
ARCH_LOG_PATH=`$ECHO $ARCH_LOG | $AWK '{ print $1 }'`
ARCH_LOG_SIZE_M=`$DU -sm $ARCH_LOG_PATH | $AWK '{ print $1 }'`
ARCH_LOG_TOTAL_SIZE_M=`$ECHO $ARCH_LOG_SIZE_M | $AWK '{ sum=0;for(i=1;i<=NF;i++) {sum+=$i} print sum }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH AND TOTAL SIZE (MB) OF DB FILE (DATA FILE AND TEMP FILE) |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_db_file () {
DB_FILE=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select name from v\\$datafile union all select name from v\\$tempfile;
exit;
EOF`
if [ ! -f "$DBFILE_PATH" ]; then
$TOUCH "$DBFILE_PATH"
else
> "$DBFILE_PATH"
fi
for name in ${DB_FILE[@]}
do
$ECHO ${name%/*} >> $DBFILE_PATH
done
DB_FILE_PATH=`$CAT $DBFILE_PATH | $UNIQ | $TR '\n' ' '`
DB_FILE_SIZE_M=`$DU -sm $DB_FILE_PATH | $AWK '{ print $1 }'`
DB_FILE_TOTAL_SIZE_M=`$ECHO $DB_FILE_SIZE_M | $AWK '{ sum=0;for(i=1;i<=NF;i++) {sum+=$i} print sum }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH,DIR AND SIZE (MB) OF BLOCK CHANGE TRACKING FILE |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_block_change_tracking_file () {
BLOCK_CHANGE_TRACKING_FILE=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select filename from v\\$block_change_tracking;
exit;
EOF`
BLOCK_CHANGE_TRACKING_FILE_PATH=`$ECHO $BLOCK_CHANGE_TRACKING_FILE | $AWK '{ print $1 }'`
if [ -z "$BLOCK_CHANGE_TRACKING_FILE_PATH" ]; then
BLOCK_CHANGE_TRACKING_FILE_PATH=""
BLOCK_CHANGE_TRACKING_FILE_DIR=""
BLOCK_CHANGE_TRACKING_FILE_SIZE_M=0
else
BLOCK_CHANGE_TRACKING_FILE_DIR=`$ECHO ${BLOCK_CHANGE_TRACKING_FILE_PATH%/*}`
BLOCK_CHANGE_TRACKING_FILE_SIZE_M=`$DU -sm $BLOCK_CHANGE_TRACKING_FILE_PATH | $AWK '{ print $1 }'`
fi
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH OF FAST OR FLASH RECO AREA |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_fast_or_flash_reco_area () {
FAST_OR_FLASH_RECO_AREA=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select value from v\\$parameter where name='db_recovery_file_dest';
exit;
EOF`
FAST_OR_FLASH_RECO_AREA_PATH=`$ECHO $FAST_OR_FLASH_RECO_AREA`
if [ -z "$FAST_OR_FLASH_RECO_AREA_PATH" ]; then
FAST_OR_FLASH_RECO_AREA_PATH=""
fi
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH AND TOTAL SIZE (MB) OF ALL OF RMAN BACKUPSETS |
# | |
# | (EXCLUDE RMAN BACKUP SPFILE AND RMAN BACKUP CONTROL FILE) |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_rman_back () {
RMAN_BACK=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select distinct p.handle from v\\$backup_piece_details p,v\\$backup_set_details s
where p.bs_key=s.bs_key
and p.status='A'
and p.device_type='DISK'
and s.controlfile_included='NO'
order by 1;
exit;
EOF`
if [ ! -f "$RMANBACK_PATH" ]; then
$TOUCH "$RMANBACK_PATH"
else
> "$RMANBACK_PATH"
fi
for name in ${RMAN_BACK[@]}
do
$ECHO ${name%/*} >> $RMANBACK_PATH
done
RMAN_BACK_PATH=`$CAT $RMANBACK_PATH | $UNIQ | $TR '\n' ' '`
RMAN_BACK_SIZE_M=`$DU -sm $RMAN_BACK_PATH | $AWK '{ print $1 }'`
RMAN_BACK_TOTAL_SIZE_M=`$ECHO $RMAN_BACK_SIZE_M | $AWK '{ sum=0;for(i=1;i<=NF;i++) {sum+=$i} print sum }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH,DIR AND SIZE (MB) OF THE LATEST RMAN BACKUP SPFILE |
# | |
# +-----------------------------------------------------------------------+
function query_rman_latest_spfile () {
RMAN_LATEST_SPFILE=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select distinct p.handle from v\\$backup_piece_details p,v\\$backup_spfile sp,v\\$backup_spfile_details s
where p.bs_key=s.bs_key
and p.status='A'
and p.device_type='DISK'
and p.completion_time > to_date ('$YESTERDAY','yyyy-mm-dd')
order by 1;
exit;
EOF`
RMAN_LATEST_SPFILE_PATH=`$ECHO $RMAN_LATEST_SPFILE | $AWK '{ print $1 }'`
RMAN_LATEST_SPFILE_DIR=`$ECHO ${RMAN_LATEST_SPFILE_PATH%/*}`
RMAN_LATEST_SPFILE_SIZE_M=`$DU -sm $RMAN_LATEST_SPFILE_PATH | $AWK '{ print $1 }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH,DIR AND SIZE (MB) OF THE LATEST RMAN BACKUP CONTROL FILE |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function query_rman_latest_ctl_file () {
RMAN_LATEST_CTL_FILE=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select distinct p.handle from v\\$backup_piece_details p,v\\$backup_set_details s
where p.bs_key=s.bs_key
and p.status='A'
and p.device_type='DISK'
and s.controlfile_included='YES'
and s.completion_time > to_date ('$YESTERDAY','yyyy-mm-dd')
order by 1;
exit;
EOF`
RMAN_LATEST_CTL_FILE_PATH=`$ECHO $RMAN_LATEST_CTL_FILE | $AWK '{ print $1 }'`
RMAN_LATEST_CTL_FILE_DIR=`$ECHO ${RMAN_LATEST_CTL_FILE_PATH%/*}`
RMAN_LATEST_CTL_FILE_SIZE_M=`$DU -sm $RMAN_LATEST_CTL_FILE_PATH | $AWK '{ print $1 }'`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH OF ORACLE LISTENER FILE |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
LISTENER_FILE_PATH=`$LSNRCTL status | $GREP "Listener Parameter File" | $AWK '{ print $4 }'`
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | PERFORM FOLLOWING TWO STEPS: |
# | |
# | 1. QUERY VALUE OF DBNAME BY FUNCTION 'query_dbinfo' WROTE ABOVE |
# | |
# | 2. QUERY VALUE OF STRING VARIABLE ABOUT BASE_ADMIN_DBNAME_DIR |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
query_dbinfo
BASE_ADMIN_DBNAME_DIR=`$LS $ORACLE_BASE/admin/$DBNAME`
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | QUERY PATH OF ORACLE PASSWORD FILE |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
PASSWORD_FILE_PATH=`$LS $ORACLE_HOME/dbs/orapw$ORACLE_SID`
###########################################################################
function query_oracle_service_name () {
ORACLE_SERVICE_NAME=`$SQLPLUS -S / as sysdba << EOF
set echo off feedback off heading off underline off;
select value from v\\$parameter where name='service_names';
exit;
EOF`
ORACLE_SERVICE_NAME_VALUE=`$ECHO $ORACLE_SERVICE_NAME`
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | PRINT SOME PROMPT MESSAGES AND VALUE OF FOLLOWING STRING VARIABLE TO |
# | |
# | COMPUTER SCREEN,AT THE SAME TIME,WRITE THEM TO A LOG FILE. |
# | |
# | STRING VARIABLES AS FOLLWS: |
# | |
# | 1.HOSTNAME |
# | |
# | 2.OSNAME |
# | |
# | 3.DBVERSION |
# | |
# | 4.DBNAME |
# | |
# | 5.DBID |
# | |
# | 6.ARCH_LOG_PATH |
# | |
# | 7.ARCH_LOG_TOTAL_SIZE_M |
# | |
# | 8.DB_FILE_PATH |
# | |
# | 9.DB_FILE_TOTAL_SIZE_M |
# | |
# | 10.BLOCK_CHANGE_TRACKING_FILE_PATH |
# | |
# | 11.BLOCK_CHANGE_TRACKING_FILE_DIR |
# | |
# | 12.BLOCK_CHANGE_TRACKING_FILE_SIZE_M |
# | |
# | 13.FAST_OR_FLASH_RECO_AREA_PATH |
# | |
# | 14.RMAN_BACK_PATH |
# | |
# | 15.RMAN_BACK_TOTAL_SIZE_M |
# | |
# | 16.RMAN_LATEST_SPFILE_PATH |
# | |
# | 17.RMAN_LATEST_SPFILE_DIR |
# | |
# | 18.RMAN_LATEST_SPFILE_SIZE_M |
# | |
# | 19.RMAN_LATEST_CTL_FILE_PATH |
# | |
# | 20.RMAN_LATEST_CTL_FILE_DIR |
# | |
# | 21.RMAN_LATEST_CTL_FILE_SIZE_M |
# | |
# | 22.LISTENER_FILE_PATH |
# | |
# | 23.BASE_ADMIN_DBNAME_DIR |
# | |
# | 24.PASSWORD_FILE_PATH |
# | |
# | 25.ORACLE_BASE_PATH |
# | |
# | 26.ORACLE_HOME_PATH |
# | |
# | 27.ORACLE_SID |
# | |
# | 28.ORACLE_SERVICE_NAME |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
function print_info_to_file () {
if [ ! -f "$SOURCE_DBINFO" ]; then
$TOUCH "$SOURCE_DBINFO"
else
> "$SOURCE_DBINFO"
fi
$ECHO "#################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SOME BASIC INFORMATION OBTAINED FROM SOURCE ORACLE DATABASE #" | $TEE -a $LOGFILE
$ECHO "# SERVER AS FOLLOWS: #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#################################################################\n" | $TEE -a $LOGFILE
$ECHO 'HOSTNAME:'$HOST_NAME | $TEE -a $SOURCE_DBINFO
$ECHO 'OSNAME:'$OSNAME | $TEE -a $SOURCE_DBINFO
$ECHO 'DBVERSION:Oracle '$DBVERSION | $TEE -a $SOURCE_DBINFO
$ECHO 'DBNAME:'$DBNAME | $TEE -a $SOURCE_DBINFO
$ECHO 'DBID:'$DBID | $TEE -a $SOURCE_DBINFO
$ECHO 'ARCH_LOG_PATH:'$ARCH_LOG_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'ARCH_LOG_TOTAL_SIZE(MB):'$ARCH_LOG_TOTAL_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'DB_FILE_PATH:'$DB_FILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'DB_FILE_TOTAL_SIZE(MB):'$DB_FILE_TOTAL_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'BLOCK_CHANGE_TRACKING_FILE_PATH:'$BLOCK_CHANGE_TRACKING_FILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'BLOCK_CHANGE_TRACKING_FILE_DIR:'$BLOCK_CHANGE_TRACKING_FILE_DIR | $TEE -a $SOURCE_DBINFO
$ECHO 'BLOCK_CHANGE_TRACKING_FILE_SIZE(MB):'$BLOCK_CHANGE_TRACKING_FILE_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'FAST_OR_FLASH_RECO_AREA_PATH:'$FAST_OR_FLASH_RECO_AREA_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_BACK_PATH:'$RMAN_BACK_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_BACK_TOTAL_SIZE(MB):'$RMAN_BACK_TOTAL_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_SPFILE_PATH:'$RMAN_LATEST_SPFILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_SPFILE_DIR:'$RMAN_LATEST_SPFILE_DIR | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_SPFILE_SIZE(MB):'$RMAN_LATEST_SPFILE_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_CTL_FILE_PATH:'$RMAN_LATEST_CTL_FILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_CTL_FILE_DIR:'$RMAN_LATEST_CTL_FILE_DIR | $TEE -a $SOURCE_DBINFO
$ECHO 'RMAN_LATEST_CTL_FILE_SIZE(MB):'$RMAN_LATEST_CTL_FILE_SIZE_M | $TEE -a $SOURCE_DBINFO
$ECHO 'LISTENER_FILE_PATH:'$LISTENER_FILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'BASE_ADMIN_DBNAME_DIR:'$BASE_ADMIN_DBNAME_DIR | $TEE -a $SOURCE_DBINFO
$ECHO 'PASSWORD_FILE_PATH:'$PASSWORD_FILE_PATH | $TEE -a $SOURCE_DBINFO
$ECHO 'ORACLE_BASE_PATH:'$ORACLE_BASE | $TEE -a $SOURCE_DBINFO
$ECHO 'ORACLE_HOME_PATH:'$ORACLE_HOME | $TEE -a $SOURCE_DBINFO
$ECHO 'ORACLE_SID:'$ORACLE_SID | $TEE -a $SOURCE_DBINFO
$ECHO 'ORACLE_SERVICE_NAME:'$ORACLE_SERVICE_NAME_VALUE | $TEE -a $SOURCE_DBINFO
}
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | CALL FOLLOW TEN FUNCTIONS ORDINALLY: |
# | |
# | 1.QUERY_DBINFO |
# | |
# | 2.QUERY_HOSTNAME_AND_DBVER |
# | |
# | 3.QUERY_ARCH_LOG |
# | |
# | 4.QUERY_DB_FILE |
# | |
# | 5.QUERY_BLOCK_CHANGE_TRACKING_FILE |
# | |
# | 6.QUERY_FAST_OR_FLASH_RECO_AREA |
# | |
# | 7.QUERY_RMAN_BACK |
# | |
# | 8.QUERY_RMAN_LATEST_SPFILE |
# | |
# | 9.QUERY_RMAN_LATEST_CTL_FILE |
# | |
# | 10.QUERY_ORACLE_SERVICE_NAME |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
query_dbinfo
query_hostname_and_dbver
query_arch_log
query_db_file
query_block_change_tracking_file
query_fast_or_flash_reco_area
query_rman_back
query_rman_latest_spfile
query_rman_latest_ctl_file
query_oracle_service_name
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | PRINT LOG MESSAGES AFTER THIS SCRIPT EXECUTE AND WRITE A LOG FILE |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
$ECHO "#################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# Attention #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO -e "From local oracle database server,collect some basic information and print them to screen,and they are written to a log file at same time.\n" | $TEE -a $LOGFILE
$ECHO -e "This log file is located in [ \033[31;7m"$LOGFILE"\033[0m ].\n"
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | CALL FUNCTION ABOUT 'PRINT_INFO_TO_FILE' |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
print_info_to_file
###########################################################################
$CAT $SOURCE_DBINFO >> $LOGFILE
$ECHO -e "\n#################################################################"
$ECHO -e "\nPlease remote copy a log file that is located in [ \033[31;7m"$SOURCE_DBINFO"\033[0m ] with scp command to remote host that restore and recover oracle database via local rman backupsets!!!\n"
###########################################################################
script 4: scp_log_file_to_target.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | Quanwen Zhao |
# | guestart@163.com |
# | guestart.blog.51cto.com |
# |-----------------------------------------------------------------------|
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# |-----------------------------------------------------------------------|
# | DATABASE : Oracle |
# | OS ENV : Linux |
# | File : scp_log_file_to_target.sh |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | PURPOSE : This bash script file used to remote copy a local log |
# | file to remote host. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/10/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to test this script in a |
# | development environment before attempting to run it in |
# | production. |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# +-----------------------------------------------------------------------+
source ~/.bash_profile;
# +-----------------------------------------------------------------------+
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# +-----------------------------------------------------------------------+
export SCP=`which scp`
export LOCAL_LOGFILE='/tmp/source_oracle_dbinfo.log'
# Define Remote Host,For example,REMOTE_HOST='orcl1',According to your situation to set.
export REMOTE_HOST='orcl_adg'
# +-----------------------------------------------------------------------+
# | USE SCP COMMAND TO COPY A LOCAL LOG FILE TO TARGET HOST |
# +-----------------------------------------------------------------------+
$SCP $LOCAL_LOGFILE oracle@$REMOTE_HOST:/tmp
script 5: rman_restore_and_recover_to_target_oracle.sh
#!/bin/bash
# +-----------------------------------------------------------------------+
# | |
# | Quanwen Zhao |
# | |
# | guestart@163.com |
# | |
# | guestart.blog.51cto.com |
# | |
# |-----------------------------------------------------------------------|
# | |
# | Copyright (c) 2016-2017 Quanwen Zhao. All rights reserved. |
# | |
# |-----------------------------------------------------------------------|
# | |
# | DATABASE : Oracle |
# | |
# | OS ENV : Linux |
# | |
# | File : rman_restore_and_recover_to_target_oracle.sh |
# | |
# | CLASS : LINUX Bourne-Again Shell Scripts |
# | |
# | PURPOSE : This bash script file used to restore and recover full |
# | |
# | database to local with rman utility from rman backupset |
# | |
# | of remote and used to do a regular backup recovery |
# | |
# | experiment,the premise is that there is a need to have a |
# | |
# | set of oracle database software installed and same to |
# | |
# | version of remote oracle database server,same to |
# | |
# | operation system category and version. |
# | |
# | PARAMETERS : None. |
# | |
# | MODIFIED : 03/10/2017 (mm/dd/yyyy) |
# | |
# | NOTE : As with any code,ensure to use this script in a test |
# | |
# | environment only. |
# | |
# +-----------------------------------------------------------------------+
# +-----------------------------------------------------------------------+
# | |
# | EXPORT ENVIRONMENT VARIABLE OF ORACLE USER |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
source ~/.bash_profile;
###########################################################################
# +-----------------------------------------------------------------------+
# | |
# | GLOBAL VARIABLES ABOUT STRINGS AND BACKTICK EXECUTION RESULT OF SHELL |
# | |
# +-----------------------------------------------------------------------+
###########################################################################
export AWK=`which awk`
export CAT=`which cat`
export DATE=`which date`
export DF=`which df`
export ECHO=`which echo`
export GREP=`which grep`
export HOSTNAME=`which hostname`
export MKDIR=`which mkdir`
export SCP=`which scp`
export SCRIPT=`which script`
export SED=`which sed`
export SSH=`which ssh`
export TEE=`which tee`
###########################################################################
export LSNRCTL=$ORACLE_HOME/bin/lsnrctl
export RMAN=$ORACLE_HOME/bin/rman
export SQLPLUS=$ORACLE_HOME/bin/sqlplus
###########################################################################
export SOURCE_DBINFO='/tmp/source_oracle_dbinfo.log'
export LOGFILE="/tmp/rman_restore_and_recover_to_target_oracle_`$DATE +%F-%H-%M-%S`.log"
###########################################################################
export SOURCE_HOSTNAME=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==1{print $2}'`
export SOURCE_OSNAME=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==2{print $2}'`
export SOURCE_DBVERSION=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==3{print $2}'`
export SOURCE_DBNAME=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==4{print $2}'`
export SOURCE_DBID=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==5{print $2}'`
export SOURCE_ARCH_LOG_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==6{print $2}'`
export SOURCE_ARCH_LOG_TOTAL_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==7{print $2}'`
export SOURCE_DB_FILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==8{print $2}'`
export SOURCE_DB_FILE_TOTAL_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==9{print $2}'`
export SOURCE_BLOCK_CHANGE_TRACKING_FILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==10{print $2}'`
export SOURCE_BLOCK_CHANGE_TRACKING_FILE_DIR=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==11{print $2}'`
export SOURCE_BLOCK_CHANGE_TRACKING_FILE_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==12{print $2}'`
export SOURCE_FAST_OR_FLASH_RECO_AREA_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==13{print $2}'`
export SOURCE_RMAN_BACK_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==14{print $2}'`
export SOURCE_RMAN_BACK_TOTAL_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==15{print $2}'`
export SOURCE_RMAN_LATEST_SPFILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==16{print $2}'`
export SOURCE_RMAN_LATEST_SPFILE_DIR=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==17{print $2}'`
export SOURCE_RMAN_LATEST_SPFILE_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==18{print $2}'`
export SOURCE_RMAN_LATEST_CTL_FILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==19{print $2}'`
export SOURCE_RMAN_LATEST_CTL_FILE_DIR=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==20{print $2}'`
export SOURCE_RMAN_LATEST_CTL_FILE_SIZE_M=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==21{print $2}'`
export SOURCE_LISTENER_FILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==22{print $2}'`
export SOURCE_BASE_ADMIN_DBNAME_DIR=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==23{print $2}'`
export SOURCE_PASSWORD_FILE_PATH=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==24{print $2}'`
export SOURCE_ORACLE_SID=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==27{print $2}'`
export SOURCE_ORACLE_SERVICE_NAME=`$CAT $SOURCE_DBINFO | $AWK -F':' 'NR==28{print $2}'`
export SOURCE_REDO_LOG_SEQUENCE_CURRENT=
export SOURCE_REDO_LOG_SEQUENCE_PREVIEW=
###########################################################################
export TARGET_DBNAME=$SOURCE_DBNAME
export TARGET_DBID=$SOURCE_DBID
export TARGET_ARCH_LOG_PATH=$SOURCE_ARCH_LOG_PATH
export TARGET_ARCH_LOG_TOTAL_SIZE_M=$SOURCE_ARCH_LOG_TOTAL_SIZE_M
export TARGET_DB_FILE_PATH=$SOURCE_DB_FILE_PATH
export TARGET_DB_FILE_TOTAL_SIZE_M=$SOURCE_DB_FILE_TOTAL_SIZE_M
export TARGET_BLOCK_CHANGE_TRACKING_FILE=`$ECHO $SOURCE_BLOCK_CHANGE_TRACKING_FILE_PATH | $AWK -F'/' '{print $NF}'`
export TARGET_BLOCK_CHANGE_TRACKING_FILE_PATH=$SOURCE_BLOCK_CHANGE_TRACKING_FILE_PATH
export TARGET_BLOCK_CHANGE_TRACKING_FILE_DIR=$SOURCE_BLOCK_CHANGE_TRACKING_FILE_DIR
export TARGET_BLOCK_CHANGE_TRACKING_FILE_SIZE_M=$SOURCE_BLOCK_CHANGE_TRACKING_FILE_SIZE_M
export TARGET_FAST_OR_FLASH_RECO_AREA_PATH=$SOURCE_FAST_OR_FLASH_RECO_AREA_PATH
export TARGET_RMAN_BACK_PATH=$SOURCE_RMAN_BACK_PATH
export TARGET_RMAN_BACK_TOTAL_SIZE_M=$SOURCE_RMAN_BACK_TOTAL_SIZE_M
export TARGET_RMAN_LATEST_SPFILE_PATH=$SOURCE_RMAN_LATEST_SPFILE_PATH
export TARGET_RMAN_LATEST_SPFILE=`$ECHO $TARGET_RMAN_LATEST_SPFILE_PATH | $AWK -F'/' '{print $NF}'`
export TARGET_RMAN_LATEST_SPFILE_DIR=$SOURCE_RMAN_LATEST_SPFILE_DIR
export TARGET_RMAN_LATEST_SPFILE_SIZE_M=$SOURCE_RMAN_LATEST_SPFILE_SIZE_M
export TARGET_RMAN_LATEST_CTL_FILE_PATH=$SOURCE_RMAN_LATEST_CTL_FILE_PATH
export TARGET_RMAN_LATEST_CTL_FILE=`$ECHO $TARGET_RMAN_LATEST_CTL_FILE_PATH | $AWK -F'/' '{print $NF}'`
export TARGET_RMAN_LATEST_CTL_FILE_DIR=$SOURCE_RMAN_LATEST_CTL_FILE_DIR
export TARGET_RMAN_LATEST_CTL_FILE_SIZE_M=$SOURCE_RMAN_LATEST_CTL_FILE_SIZE_M
export TARGET_LISTENER_FILE=`$ECHO $SOURCE_LISTENER_FILE_PATH | $AWK -F'/' '{print $NF}'`
export TARGET_BASE_ADMIN_DBNAME_DIR=$SOURCE_BASE_ADMIN_DBNAME_DIR
export TARGET_PASSWORD_FILE=`$ECHO $SOURCE_PASSWORD_FILE_PATH | $AWK -F'/' '{print $NF}'`
export TARGET_ORACLE_SID=$SOURCE_ORACLE_SID
###########################################################################
export SOURCE_LISTENER_PORT=`$SSH $SOURCE_HOSTNAME $CAT $SOURCE_LISTENER_FILE_PATH | $GREP PORT | $AWK '{ print $NF }' | $AWK -F')' '{ print $1 }'`
export TARGET_LISTENER_PORT=1521
###########################################################################
export SOURCE_ADR_BASE=`$SSH $SOURCE_HOSTNAME $CAT $SOURCE_LISTENER_FILE_PATH | $GREP ADR_BASE | $AWK '{ print $NF }'`
###########################################################################
export TARGET_HOSTNAME=`$HOSTNAME`
###########################################################################
$ECHO "#################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# Attention #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO -e "From now on,we are ready to restore and recover oracle database via remote rman backupsets on local host,all of processes are as follows and written to a log file.\n" | $TEE -a $LOGFILE
$ECHO -e "This log file is located in [ \033[31;7m"$LOGFILE"\033[0m ].\n"
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# CREATE EIGHT NECESSARY DIRECTORY ON LOCAL ORACLE DATABASE SERVER #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# WITH MKDIR ABOUT BUILT-IN SHELL COMMAND ADDITIONAL PARAMETER '-p'. #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 1. ORACLE ARCHIVE LOG DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 2. ORACLE DATABASE FILE DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 3. ORACLE BLOCK CHANGE TRACKING FILE DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 4. ORACLE FAST OR FLASH RECO AREA DIRECTORY(INCLUDE SUBDIR OF DBNAME) #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 5. ORACLE RMAN BACKUP DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 6. LATEST RMAN BACKUP SPFILE DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 7. LATEST RMAN BACKUP CONTROL FILE DIRECTORY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 8. ORACLE DBNAME AND ITS SUBDIR(\$ORACLE_BASE/admin's SUBDIR) #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
for arch_log_path in $TARGET_ARCH_LOG_PATH
do
$MKDIR -p $arch_log_path
$ECHO -e 1. Create archive log directory \"$arch_log_path\" successfully."\n" | $TEE -a $LOGFILE
done
###########################################################################
for db_file_path in $TARGET_DB_FILE_PATH
do
$MKDIR -p $db_file_path
$ECHO -e 2. Create database file directory \"$db_file_path\" successfully."\n" | $TEE -a $LOGFILE
done
###########################################################################
if [ ! -z $TARGET_BLOCK_CHANGE_TRACKING_FILE_PATH ]; then
$MKDIR -p $TARGET_BLOCK_CHANGE_TRACKING_FILE_DIR
$ECHO -e 3. Create block change tracking file directory \"$TARGET_BLOCK_CHANGE_TRACKING_FILE_DIR\" successfully."\n" | $TEE -a $LOGFILE
else
$ECHO -e 3. Oracle database server don\'t configure block change tracking file."\n" | $TEE -a $LOGFILE
fi
###########################################################################
if [ ! -z $TARGET_FAST_OR_FLASH_RECO_AREA_PATH ]; then
$MKDIR -p $TARGET_FAST_OR_FLASH_RECO_AREA_PATH/$TARGET_DBNAME
$ECHO -e 4. Create fast or flash recovery area directory \"$TARGET_FAST_OR_FLASH_RECO_AREA_PATH\" and its subdir \"$TARGET_DBNAME\" successfully."\n" | $TEE -a $LOGFILE
TARGET_DBNAME=`$ECHO $TARGET_DBNAME | $AWK '{ print toupper($0)}'`
$MKDIR -p $TARGET_FAST_OR_FLASH_RECO_AREA_PATH/$TARGET_DBNAME
$ECHO -e 4. Create fast or flash recovery area directory \"$TARGET_FAST_OR_FLASH_RECO_AREA_PATH\" and its subdir \"$TARGET_DBNAME\" successfully."\n" | $TEE -a $LOGFILE
else
$ECHO -e 4. Oracle database server don\'t configure fast or flash recovery area."\n" | $TEE -a $LOGFILE
fi
TARGET_DBNAME=`$ECHO $TARGET_DBNAME | $AWK '{ print tolower($0)}'`
###########################################################################
for rman_back_path in $TARGET_RMAN_BACK_PATH
do
$MKDIR -p $rman_back_path
$ECHO -e 5. Create rman backup directory \"$rman_back_path\" successfully."\n" | $TEE -a $LOGFILE
done
###########################################################################
if [ ! -d $TARGET_RMAN_LATEST_SPFILE_DIR ]; then
$MKDIR -p $TARGET_RMAN_LATEST_SPFILE_DIR
fi
$ECHO -e 6. Create latest rman backup spfile directory \"$TARGET_RMAN_LATEST_SPFILE_DIR\" successfully."\n" | $TEE -a $LOGFILE
###########################################################################
if [ ! -d $TARGET_RMAN_LATEST_CTL_FILE_DIR ]; then
$MKDIR -p $TARGET_RMAN_LATEST_CTL_FILE_DIR
fi
$ECHO -e 7. Create latest rman backup control file directory \"$TARGET_RMAN_LATEST_CTL_FILE_DIR\" successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$MKDIR -p $ORACLE_BASE/admin/$TARGET_DBNAME
$ECHO -e 8. Create dbname directory \"$ORACLE_BASE/admin/$TARGET_DBNAME\" successfully."\n" | $TEE -a $LOGFILE
for dbname_subdir in $TARGET_BASE_ADMIN_DBNAME_DIR
do
$MKDIR -p $ORACLE_BASE/admin/$TARGET_DBNAME/$dbname_subdir
$ECHO -e " "Create dbname directory\'s subdir \"$dbname_subdir\" successfully."\n" | $TEE -a $LOGFILE
done
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP PASSWORD FILE AND LISTENER FILE TO LOCAL ORACLE DATABASE SERVER #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$SOURCE_LISTENER_FILE_PATH $ORACLE_HOME/network/admin" > /dev/null
$ECHO -e "\n"Remote copy listener file \"$TARGET_LISTENER_FILE\" with scp command to local successfully."\n" | $TEE -a $LOGFILE
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$SOURCE_PASSWORD_FILE_PATH $ORACLE_HOME/dbs" > /dev/null
$ECHO -e "\n"Remote copy password file \"$TARGET_PASSWORD_FILE\" with scp command to local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# CHANGE VALUE OF \"HOST\" IN FILE \"listener.ora\" TO HOSTNAME OF LOCAL #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SED -i "s/$SOURCE_HOSTNAME/$TARGET_HOSTNAME/g" $ORACLE_HOME/network/admin/$TARGET_LISTENER_FILE
$ECHO -e Change value of \"HOST\" in file \"$TARGET_LISTENER_FILE\" to hostname of local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP LATEST RMAN BACKUP SPFILE OF SOURCE ORACLE DATABASE TO LOCAL #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$SOURCE_RMAN_LATEST_SPFILE_PATH $TARGET_RMAN_LATEST_SPFILE_DIR" > /dev/null
$ECHO -e "\n"Remote copy latest rman backup spfile \"$TARGET_RMAN_LATEST_SPFILE\" to local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP LATEST RMAN BACKUP CTLFILE OF SOURCE ORACLE DATABASE TO LOCAL #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$SOURCE_RMAN_LATEST_CTL_FILE_PATH $TARGET_RMAN_LATEST_CTL_FILE_DIR" > /dev/null
$ECHO -e "\n"Remote copy latest rman backup control file \"$TARGET_RMAN_LATEST_CTL_FILE\" to local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP BLOCK CHANGE TRACKING FILE OF SOURCE ORACLE DATABASE TO LOCAL #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
if [ ! -z $TARGET_BLOCK_CHANGE_TRACKING_FILE_PATH ]; then
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$SOURCE_BLOCK_CHANGE_TRACKING_FILE_PATH $TARGET_BLOCK_CHANGE_TRACKING_FILE_DIR" > /dev/null
$ECHO -e "\n"Remote copy block change tracking file \"$TARGET_BLOCK_CHANGE_TRACKING_FILE\" to local successfully."\n" | $TEE -a $LOGFILE
fi
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP RMAN BACKUPSETS OF SOURCE ORACLE DATABASE TO LOCAL HOST #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
for rman_back_path in $TARGET_RMAN_BACK_PATH
do
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$rman_back_path/* $rman_back_path"
done
$ECHO -e "\n"Remote copy all of valid rman backupsets to local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# RESTORE SPFILE,CTLFILE AND DB FILES WITH RMAN BACKUPSETS ORDINALLY #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################" | $TEE -a $LOGFILE
###########################################################################
export ORACLE_SID=$TARGET_ORACLE_SID
$RMAN target / nocatalog log $LOGFILE append <<EOF
set dbid=$TARGET_DBID;
startup nomount;
restore spfile from '$TARGET_RMAN_LATEST_SPFILE_PATH';
shutdown immediate;
startup nomount;
restore controlfile from '$TARGET_RMAN_LATEST_CTL_FILE_PATH';
alter database mount;
run
{
allocate channel d1 type disk maxpiecesize 16g;
allocate channel d2 type disk maxpiecesize 16g;
allocate channel d3 type disk maxpiecesize 16g;
allocate channel d4 type disk maxpiecesize 16g;
restore database;
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
exit;
EOF
###########################################################################
$ECHO -e "\n#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# PERFORM TWO STEPS AS FOLLOWS: #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 1. QUERY GROUP NUMS OF REDO LOG OF SOURCE ORACLE DATABASE #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# 2. SWITCH CURRENT REDO LOG OF SOURCE ORACLE DATABASE TO ARCHIVE #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SQLPLUS -S system/oracle@$SOURCE_HOSTNAME:1521/$SOURCE_ORACLE_SERVICE_NAME << EOF
set echo off feedback off heading off underline off;
set serveroutput on;
declare
nums number;
str_exec_sql varchar2(512);
begin
select count(group#) into nums from v\$log;
str_exec_sql :='alter system archive log current';
for num in 1 .. nums
loop
execute immediate str_exec_sql;
end loop;
end;
/
exit;
EOF
$ECHO -e Switch all online redo log to be archive log successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# SCP ALL ARCHIVE LOG FILES OF SOURCE ORACLE DATABASE TO LOCAL HOST #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
for arch_log_path in $TARGET_ARCH_LOG_PATH
do
$SCRIPT -a $LOGFILE -c "$SCP -p $SOURCE_HOSTNAME:$arch_log_path/* $arch_log_path"
done
$ECHO -e "\n"Remote copy all archive log files to local successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# RECOVER DATABASE WITH RMAN INCREMENTAL BACKUPSETS AND ARCHIVE LOG #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################" | $TEE -a $LOGFILE
###########################################################################
SOURCE_REDO_LOG_SEQUENCE_CURRENT=`$SQLPLUS -S system/oracle@$SOURCE_HOSTNAME:1521/$SOURCE_ORACLE_SERVICE_NAME << EOF
set echo off feedback off heading off underline off;
select sequence# from v\\$log where status='CURRENT';
exit;
EOF`
SOURCE_REDO_LOG_SEQUENCE_PREVIEW=$((SOURCE_REDO_LOG_SEQUENCE_CURRENT-1))
$RMAN target / nocatalog log $LOGFILE append <<EOF
run
{
allocate channel d1 type disk maxpiecesize 16g;
allocate channel d2 type disk maxpiecesize 16g;
allocate channel d3 type disk maxpiecesize 16g;
allocate channel d4 type disk maxpiecesize 16g;
recover database until sequence $SOURCE_REDO_LOG_SEQUENCE_PREVIEW;
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
exit;
EOF
###########################################################################
$ECHO -e "\n#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# OPEN LOCAL'S ORACLE DATABASE WITH 'RESETLOGS' #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$SQLPLUS -S / as sysdba << EOF
alter database open resetlogs;
exit;
EOF
$ECHO -e Open oracle database with \'resetlogs\' successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# START LOCAL ORACLE DATABASE SERVER'S LISTENER #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
#$LSNRCTL START
$ECHO -e Start listener successfully."\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO "#########################################################################" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO "# APPEND '\$ORACLE_SID:\$ORACLE_HOME:N' TO FILE '/etc/oratab' #" | $TEE -a $LOGFILE
$ECHO "# #" | $TEE -a $LOGFILE
$ECHO -e "#########################################################################\n" | $TEE -a $LOGFILE
###########################################################################
$ECHO $TARGET_DBNAME:$ORACLE_HOME:N >> /etc/oratab
$ECHO -e Append \"\$ORACLE_SID:\$ORACLE_HOME:N\" to file \"/etc/oratab\" successfully."\n" | $TEE -a $LOGFILE
###########################################################################