Thursday, August 23, 2012

Restore from primary to standby using sqlbacktrack


It is assumed the location of oracle files is same in primary and standby server and the database name is PROD.

1. Disable (comment off) CRON jobs that may impact or interrupt the refresh process.

2. Ensure the sqlbacktrack backup is complete at primary. (Type "dtwach" to monitor the backup progress).

Example:

>dtwatch

SQL-BackTrack Activity Display (wbrsnp01)                                                                       06/03/2012 22:27:48
Version 4.0.00                                                                                      Serial number  OB-12345678-2966
Licensed to: XYZ

Active:
  Thu 21:45 dtoarchmon 4317: dtoarchmon listening on port: 5555
  Sat 09:36 dtobackup 7762: getting list of archive logfiles

Completed:
  Sat 21:48 dtobackup 9182: completed successfully
  Sat 21:48 dtoexpire 10693: completed successfully
  Sat 21:48 obsi/adsm 10700: Completed successfully
  Sat 21:48 obsi/adsm 10698: Completed successfully

3. Verify backup logs. Ensure the sqlbacktrack backup that we use for the restore are successful, highest return code should be Zero.

Example:

*** finished on 03/03/2012 21:48:49
*** files(s) processed: 78
*** elapsed time: 1 hour 48 minutes 45 seconds
*** highest return code: 0
*** dtobackup completed successfully
Hot Backup of uswbp on wbrsnp01 - Successfull @ Sat Mar  3 21:48:49 CST 2012

4. Copy the oracatalog (backup related information) from primary to standby and change the necessary values in the parameter file. Tar the primary catalog and copy to standby. Prior to that, clean up and backup old catalog.

Example:

cd $DT_ORACATALOG                       =======> primary:/opt/bmc/obacktrack-4.0.10/oracatalog 
cd ..                                   =======> primary:/opt/bmc/obacktrack-4.0.10/
tar -cvf /tmp/oracatalog.tar oracatalog
cd /tmp
ls -la oracatalog.tar
ftp standby <password>
ftp> bin
ftp> put oracatalog.tar
ftp> bye


5. Expand the Tar Ball at standby and change the NODE value on standby.

tar -xvf /tmp/oracatalog.tar
cd /db/app/oracle/oracatalog/PROD.db/config
vi opsconfig.rdf

"opsconfig.rdf" 14 lines, 357 characters
;
;    This is a required BackTrack file; DO NOT DELETE! ;
;
; The NODE name should be  FULLY QUALIFIED ;
; as <machine name>.<domain name> ;
; For example,  begin node=prod1.bmc.com ;
;
begin node=standby  ##<====== Change this value for standby refresh

  thread=1
  oraclehome=/db/app/oracle/product/9.2.0
  oraclesid=prod
  initora=/db/app/oracle/product/9.2.0/dbs/inituswbp.ora
end node
;; RDFEOF ;;

6. Ensure no process is running for standby database

ps –efa | grep ora

7. Export the values for DT_ORACATALOG, DSMI_CONFIG, DTTEMPDIR, DSMI_LOG, DSMI_DIR.

Example:

DT_ORACATALOG=/tmp/oracatalog; export DT_ORACATALOG
DSMI_CONFIG=/opt/tivoli/tsm/client/api/bin/prod.opt; export DSMI_CONFIG
DTTEMPDIR=/opt/bmc/obacktrack-4.0.10/tmpdir; export DTTEMPDIR
DSMI_LOG=/opt/tivoli/tsm/client/api/bin/; export DSMI_LOG
DSMI_DIR=/opt/tivoli/tsm/client/api/bin; export DSMI_DIR

8. Restore using “dtorestore” command

dtorestore /tmp/oracatalog -database uswbp -datafile SOURCE_FILE_NAME -nodict -copyover -noconfirm -status -destdir DEST_DIR

Example

dtorestore /tmp/oracatalog -database prod -datafile /prod/db01/system/system_01.dbf -nodict -copyover -noconfirm -status  -destdir /prod/db01/system


9. Copy primary archive logs to standby archive log location from the time the backup in primary begin/started.

Example:

ftp standby <password>
ftp> cd /stdby/archivelog/
ftp> binary
ftp> prompt off
ftp > mput arch_114047.alg arch_114048.alg  arch_114046.alg
ftp> bye
     

10. Create standby control file from primary database and move appropriate locations as given at standby parameter file.

SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/standby/oracle/oradata/control01.ctl';
SQL> exit

ftp standby <password>
ftp> bin
ftp> put /standby/oracle/oradata/control01.ctl /standby/oracle/control
ftp> bye

11. Start standby database in “mount” stage and run the Restore command.

STARTUP NOMOUNT;
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

12. Check alert logs for error. Once successful check primary and standby are in sync.

At Primary

SELECT THREAD# "Thread",SEQUENCE# "Last Sequence Generated" FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#) ORDER BY 1;

Thread     Last Sequence Generated
---------- -----------------------
1          19
2          13
3          11

At Standby

SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference" FROM (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH, (SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL WHERE ARCH.THREAD# = APPL.THREAD# ORDER BY 1;

Thread     Last Sequence Received Last Sequence Applied Difference
---------- ---------------------- --------------------- ----------
1          19                     19                    0
2          13                     13                    0
3          11                     11                    0