cent os 6.6 x64 自動配置oracle 11gr2物理standby指令碼

selectshen發表於2015-08-06

前提:
測試指令碼是根據上一篇cent os 6.6 x64 自動靜默安裝oracle 11gr2指令碼 安裝的兩臺db,比較乾淨,所以配置standby比較簡單


os:centos 6.6

oracle:11.2.0.4
primary ip:192.108.56.119
primary hostname:ct6602
standby ip:192.108.56.121
standby hostname:ct6604

----以下內容在primary DB上放在一個文字下,oracle使用者下sh執行即可:
#!/bin/bash

mkdir /u03/archivelog/ct6602
sqlplus  / as sysdba << EOF
shutdown immediate;
startup mount;
alter database archivelog;
alter system set log_archive_dest_1='LOCATION=/u03/archivelog/ct6602 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ct6602';
alter database open;
alter database force logging;
alter system set log_archive_config='DG_CONFIG=(ct6602,ct6602sb)';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=ct6602sb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,primary_ROLE) DB_UNIQUE_NAME=ct6602sb';
alter system set FAL_SERVER='ct6602sb';
alter system set FAL_CLIENT='ct6602';
alter system set db_file_name_convert='ct6602sb','ct6602' scope=spfile;
alter system set log_file_name_convert='ct6602sb','ct6602' scope=spfile;
alter system set standby_file_management=auto;
create pfile from spfile;
exit
EOF

mkdir /home/oracle/sbbackup
rman target / <<EOF
backup database format '/home/oracle/sbbackup/full_db_%U.dbfbk' plus archivelog format '/home/oracle/sbbackup/full_log_%U.logbk';
backup current controlfile for standby format '/home/oracle/sbbackup/sbctl.ctl';
exit
EOF


cat >> /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora << EOF
CT6602SB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.108.56.121)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ct6602sb)
    )
  )
EOF

cat > /home/oracle/scpbackup.sh <<EOF
set timeout -1
spawn scp -r /home/oracle/sbbackup  oracle@192.108.56.121:/home/oracle/
expect "password:"
send "system\r"
interact
set timeout -1
spawn scp -r /u01/app/oracle/product/11.2.0/db_1/dbs/orapwct6602  oracle@192.108.56.121:/home/oracle/orapwct6602
expect "password:"
send "system\r"
interact
set timeout -1
spawn scp -r /u01/app/oracle/product/11.2.0/db_1/dbs/initct6602.ora oracle@192.108.56.121:/home/oracle/initct6602.ora
expect "password:"
send "system\r"
interact
EOF

expect /home/oracle/scpbackup.sh


----以下內容在standby DB上放在一個文字下,oracle使用者下sh執行即可:
#!/bin/bash

mv /home/oracle/orapwct6602 /u01/app/oracle/product/11.2.0/db_1/dbs/orapwct6602sb
mv /home/oracle/initct6602.ora $ORACLE_HOME/dbs/initct6602sb.ora
cp $ORACLE_HOME/dbs/initct6602sb.ora $ORACLE_HOME/dbs/initct6602sb.ora.bak

cat >> /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora << EOF
CT6602 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.108.56.119)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ct6602)
    )
  )
EOF

sed -i 's/ct6602sb/selectshen/g' $ORACLE_HOME/dbs/initct6602sb.ora
sed -i 's/ct6602/ct6602sb/g' $ORACLE_HOME/dbs/initct6602sb.ora
sed -i 's/selectshen/ct6602/g' $ORACLE_HOME/dbs/initct6602sb.ora
sed -i "s/db_name='ct6602sb'/db_name='ct6602'/" $ORACLE_HOME/dbs/initct6602sb.ora
echo "*.db_unique_name=ct6602sb" >> $ORACLE_HOME/dbs/initct6602sb.ora


mkdir -p /u01/app/oracle/admin/ct6602sb/adump /u02/oradata/ct6602sb /u01/app/oracle/fast_recovery_area/ct6602sb /u03/archivelog/ct6602sb

ORACLE_SID=ct6602sb
sqlplus / as sysdba <<EOF
create spfile from pfile;
startup nomount;
exit
EOF
 
rman target / <<EOF
restore standby controlfile from '/home/oracle/sbbackup/sbctl.ctl';
sql 'alter database mount';
restore database;
recover database;
exit;
EOF

sqlplus / as sysdba <<EOF
alter database open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE disconnect;
select process,thread#,sequence#,status from v\$managed_standby;
exit;
EOF

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1764041/,如需轉載,請註明出處,否則將追究法律責任。

相關文章