DATAGUARD Scripts

create_standby.rcv
crash_primary_db.sh
dg_failover.sh
dg_failover_post_conf_as_newprimary.sh
dg_status.sh
create_new_standby.rcv
create_new_standby.sh
dg_failover_post_conf_as_newstandby.sh

create_standby.rcv

DUPLICATE TARGET DATABASE
FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='sdb' COMMENT 'Is standby'
    SET LOG_ARCHIVE_DEST_2='SERVICE=pdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=pdb'
    SET FAL_SERVER='pdb' COMMENT 'Is primary'
    SET audit_file_dest='/u01/app/oracle/admin/sdb/adump'
    SET db_file_name_convert='/u01/app/oracle/oradata/pdb','/u01/app/oracle/oradata/sdb'
    SET log_file_name_convert='/u01/app/oracle/oradata/pdb','/u01/app/oracle/oradata/sdb'
    SET CONTROL_FILES='/u01/app/oracle/oradata/sdb/control01.ctl','/u01/app/oracle/fast_recovery_area/sdb/control02.ctl'
  NOFILENAMECHECK;

crash_primary_db.sh

#!/bin/sh
doContinue=n
echo -n "Do you really want to down primary database)? (y/n) "
read doContinue

if [ "$doContinue" != "y" ]; then
      echo "Quitting..."
      exit
fi
echo "Enter password of sys"
read pass
echo "Enter the ORACLE_SID for PRIMARY DATABASE"
read primary
sqlplus -S sys/$pass@$primary as sysdba << EOF
  SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
  SHUTDOWN IMMEDIATE;
 exit;
EOF
lsnrctl stop

dg_failover.sh

#!/bin/sh
echo "Enter password of sys"
read pass
echo "Enter the ORACLE_SID for STANDBY DATABASE"
read standby
doContinue=n
echo -n "Do you really want to do dg failover? (y/n) "
read doContinue

if [ "$doContinue" != "y" ]; then
      echo "Quitting..."
      exit
fi
sqlplus -S sys/$pass@$standby as sysdba << EOF
    SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
  ALTER DATABASE ACTIVATE STANDBY DATABASE;
  ALTER DATABASE OPEN;
  SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
 exit;
EOF

dg_failover_post_conf_as_newprimary.sh

#!/bin/sh
doContinue=n
echo -n "Do you really want to do config on new primary database for reconfig the dg (new parimary to new standby)? (y/n) "
read doContinue

if [ "$doContinue" != "y" ]; then
      echo "Quitting..."
      exit
fi
echo "Enter password of sys"
read pass
echo "Enter the ORACLE_SID for NEW PRIMARY DATABASE"
read  primary
sqlplus -S sys/$pass@$primary as sysdba << EOF
  SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
  ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=pdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=pdb';
  ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=BOTH;
 exit;
EOF

dg_status.sh

#!/bin/sh
echo "Enter password of sys"
read pass
sqlplus -S sys/$pass as sysdba << EOF
set linesize 500 pages 0
col value for a90
col name for a50
select name, value from v$parameter
where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2',
               'log_archive_dest_state_1','log_archive_dest_state_2', 'remote_login_passwordfile',
               'log_archive_format','log_archive_max_processes','fal_server','fal_client','db_file_name_convert',
               'log_file_name_convert', 'standby_file_management');
  SHOW PARAMETER STANDBY_FILE_MANAGEMENT
  SET LINESIZE 100
  SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
  ARCHIVE LOG LIST
 exit;
EOF

create_new_standby.rcv

DUPLICATE TARGET DATABASE
FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='pdb' COMMENT 'Is standby'
    SET LOG_ARCHIVE_DEST_2='SERVICE=sdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=sdb'
    SET FAL_SERVER='sdb' COMMENT 'Is primary'
    SET audit_file_dest='/u01/app/oracle/admin/pdb/adump'
    SET db_file_name_convert='/u01/app/oracle/oradata/sdb','/u01/app/oracle/oradata/pdb'
    SET log_file_name_convert='/u01/app/oracle/oradata/sdb','/u01/app/oracle/oradata/pdb'
    SET CONTROL_FILES='/u01/app/oracle/oradata/pdb/control01.ctl','/u01/app/oracle/fast_recovery_area/pdb/control02.ctl'
  NOFILENAMECHECK;

create_new_standby.sh

#!/bin/sh
. /home/oracle/.bash_profile
/u01/app/oracle/product/11.2.0/db_1/bin/rman TARGET sys/eliteAAA123@sdb AUXILIARY sys/eliteAAA123@pdb cmdfile=create_new_standby.rcv log=create_new_standby.log

dg_failover_post_conf_as_newstandby.sh

#!/bin/sh
doContinue=n
echo -n "Do you really want to do config on new standby database for reconfig the dg (new parimary to new standby)? (y/n) "
read doContinue

if [ "$doContinue" != "y" ]; then
      echo "Quitting..."
      exit
fi
echo "Enter password of sys"
read pass
echo "Enter the ORACLE_SID for NEW STANDBY DATABASE"
read standby
sqlplus -S sys/$pass@$standby as sysdba << EOF
  SELECT NAME,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS,OPEN_MODE FROM V$DATABASE;
  ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oraarch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=pdb';
  ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=sdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=sdb';
  ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER SCOPE=BOTH;
 exit;
EOF
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s