使用 rman 與 cold standby DB 同步之設定

2013-07-14 02:30

 

1. 在 primary DB 建立以下檔案

 

[oracle@SIPDB voip_dbsync]$ cat backup_db.rman
run {
 allocate channel c1 type disk;
 allocate channel c2 type disk;
 allocate channel c3 type disk;
 allocate channel c4 type disk;
 allocate channel c5 type disk;
 backup database format '/data/backup/%d_%U_%n_%T' ;
 backup archivelog all format '/data/backup/ARC_%U_%n_%T';
 backup current controlfile format '/data/backup/%d_control.ctl';
     }
 
 
[oracle@SIPDB voip_dbsync]$ cat voip_dbsync.sh
#!/bin/bash
 
###################################################
 
ORACLE_BASE=/opt/u01/app/oracle
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_SID
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_HOME
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:
export PATH
 
####################################################
 
 
/bin/rm -rf /data/backup/*
/usr/bin/ssh SIPDB2 "rm -rf /data/backup/*"
/usr/bin/ssh SIPDB2 "rm -rf /opt/u01/app/oracle/flash_recovery_area/ORCL/*"
 
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "Recover Manager Start " >> /home/oracle/voip_dbsync/backup_db.log
date >> /home/oracle/voip_dbsync/backup_db.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_dbsync/backup_db.rman >> /home/oracle/voip_dbsync/backup_db.log
 
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
echo "   " >>  /home/oracle/voip_dbsync/backup_db.log
date >> /home/oracle/voip_dbsync/backup_db.log
echo "Recover Manager Finish " >> /home/oracle/voip_dbsync/backup_db.log
 
/usr/bin/scp /data/backup/* SIPDB2:/data/backup/
/usr/bin/scp -r /opt/u01/app/oracle/flash_recovery_area/ORCL/* SIPDB2:/opt/u01/app/oracle/flash_recovery_area/ORCL/
 
/usr/bin/ssh SIPDB2 "mkdir -p /opt/u01/app/oracle/oradata/orcl/"
#####/usr/bin/scp /opt/u01/app/oracle/oradata/orcl/control01.ctl SIPDB2:/opt/u01/app/oracle/oradata/orcl/
 
/usr/bin/ssh SIPDB2 "mkdir -p /opt/u01/app/oracle/flash_recovery_area/orcl/"
#####/usr/bin/scp /opt/u01/app/oracle/flash_recovery_area/orcl/control02.ctl SIPDB2:/opt/u01/app/oracle/flash_recovery_area/orcl/
 
/usr/bin/ssh SIPDB2 "mkdir -p /opt/u01/app/oracle/product/11.2.0/dbhome_1/dbs/"
/usr/bin/scp /opt/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora SIPDB2:/opt/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
/usr/bin/scp /opt/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl SIPDB2:/opt/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
 
#####/usr/bin/scp /opt/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora SIPDB2:/opt/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
#####/usr/bin/scp /opt/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora SIPDB2:/opt/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/
 
 
/usr/bin/ssh SIPDB2 "/home/oracle/voip_restore/voip_restore.sh" >> /home/oracle/voip_dbsync/backup_db.log
 
/home/oracle/voip_dbsync/db_select.sh  >> /home/oracle/voip_dbsync/backup_db.log
 
/home/oracle/voip_dbsync/db_select1.sh  >> /home/oracle/voip_dbsync/backup_db.log
 
 
[oracle@SIPDB voip_dbsync]$ cat db_select.sh
#!/bin/sh
sqlplus / as sysdba<
select count(*) from voip.cdr;
exit
EOF
 
 
[oracle@SIPDB voip_dbsync]$ cat db_select1.sh
#!/bin/sh
sqlplus system/1qaz2wsx@orcl2<
select count(*) from voip.cdr;
exit
EOF
 

 

2. 在 Slave DB 建立以下檔案

 

[oracle@SIPDB2 voip_restore]$ cat db_shutdown.sh
#!/bin/sh
sqlplus / as sysdba<
shutdown immediate
exit
EOF
 
 
[oracle@SIPDB2 voip_restore]$ cat restore_db.rman
SET DBID=1333674623;
startup nomount;
restore controlfile from '/data/backup/ORCL_control.ctl';
alter database mount;
 
 
[oracle@SIPDB2 voip_restore]$ cat restore_db1.rman
startup mount;
 
 
[oracle@SIPDB2 voip_restore]$ cat restore_db2.rman
restore database;
 
 
[oracle@SIPDB2 voip_restore]$ cat restore_db3.rman
recover database;
 
 
[oracle@SIPDB2 voip_restore]$ cat restore_db4.rman
alter database open resetlogs;
 
 
[oracle@SIPDB2 voip_restore]$ cat voip_restore.sh
#!/bin/bash
 
 
###################################################
 
ORACLE_BASE=/opt/u01/app/oracle
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_SID
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_HOME
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:
export PATH
 
####################################################
 
 
 
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
date >> /home/oracle/voip_restore/voip_restore.log
echo "Database shutdown immediate " >> /home/oracle/voip_restore/voip_restore.log
 
/home/oracle/voip_restore/db_shutdown.sh  >> /home/oracle/voip_restore/voip_restore.log
 
/bin/rm -rf /opt/u01/app/oracle/oradata/orcl/*.dbf
/bin/rm -rf /opt/u01/app/oracle/oradata/orcl/control01.ctl
/bin/rm -rf /opt/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
 
 
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
date >> /home/oracle/voip_restore/voip_restore.log
echo "Recover manager restore start " >> /home/oracle/voip_restore/voip_restore.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_restore/restore_db.rman >> /home/oracle/voip_restore/voip_restore.log
 
/home/oracle/voip_restore/db_shutdown.sh  >> /home/oracle/voip_restore/voip_restore.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_restore/restore_db1.rman >> /home/oracle/voip_restore/voip_restore.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_restore/restore_db2.rman >> /home/oracle/voip_restore/voip_restore.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_restore/restore_db3.rman >> /home/oracle/voip_restore/voip_restore.log
 
/opt/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog @/home/oracle/voip_restore/restore_db4.rman >> /home/oracle/voip_restore/voip_restore.log
 
 
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
echo "   " >>  /home/oracle/voip_restore/voip_restore.log
date >> /home/oracle/voip_restore/voip_restore.log
echo "Recover manager restore finish " >> /home/oracle/voip_restore/voip_restore.log