Monday, July 21, 2014

Recover a datafile in primary db using catalog with dataguard environment


step 1: delete the datafile users01.dbf;
step 2: backup the users01.dbf datafile from standby database;
step 3: connect using the below line
[oracle@adgrptdb ~]$  rman target sys/sys123@stanrpt auxiliary sys/sys123@primdb
step 4: run the following script for backup that datafile
backup as copy datafile 4 auxiliary format ='/u01/app/oracle/oradata/users01.dbf';

Starting backup at 21-JUL-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/stanrpt/users01.dbf
output file name=/u01/app/oracle/oradata/users01.dbf tag=TAG20140721T090536
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 21-JUL-14

step 5:

[oracle@catalogdb ~]$ rman catalog rcat/rcat@catdb target sys/sys123@primdb

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jul 21 09:29:37 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PRIMDB (DBID=527540791)
connected to recovery catalog database

RMAN> catalog datafilecopy '/u01/app/oracle/oradata/users01.dbf';

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/users01.dbf RECID=3 STAMP=853516578

step 6: make the datafile 4 offline

sql>alter database datafile 4 offline;

step 7:

RMAN> run{
set newname for datafile 4 to '/u01/app/oracle/oradata/users01.dbf';
switch datafile 4 ;
}2> 3> 4>

executing command: SET NEWNAME

datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=853516578 file name=/u01/app/oracle/oradata/users01.dbf
starting full resync of recovery catalog
full resync complete

RMAN> restore datafile 4;

Starting restore at 21-JUL-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=22 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PRIMDB/backupset/2014_07_21/o1_mf_nnndf_TAG20140721T151938_9wspsc9n_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PRIMDB/backupset/2014_07_21/o1_mf_nnndf_TAG20140721T151938_9wspsc9n_.bkp tag=TAG20140721T151938
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 21-JUL-14

RMAN> recover datafile 4;

Starting recover at 21-JUL-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 21-JUL-14

RMAN>


step 7: make the datafile 4 online

sql>alter database datafile 4 online;


Wednesday, July 16, 2014

Catalog Server setup in dataguard environment

To setup RMAN using catalog database follow these steps :



Here i am using prim as primary database and CATDB as catalog database.


Step1: Enable the archive log in primary prim database.


Step2: Create the tablespace and user in catalog database to hold backup information.

SQL> CONNECT sys/password@catdb AS SYSDBA
Connected.

SQL> CREATE TABLESPACE cattbs datafile '/u01/app/oracle/catdb/cattbs01.DBF' SIZE 30G;

Tablespace created.

SQL> CREATE USER rcat IDENTIFIED BY rcat  TEMPORARY TABLESPACE temp  DEFAULT TABLESPACE cattbs  QUOTA UNLIMITED ON cattbs;

User created.

SQL> GRANT connect, resource, recovery_catalog_owner TO rcat;

Grant succeeded.

The role RECOVERY_CATALOG_OWNER has all of the privileges need to query and maintain the recovery catalog.

   
SQL> select privilege from dba_sys_privs where grantee = 'RECOVERY_CATALOG_OWNER';

PRIVILEGE
----------------------------------------
CREATE SYNONYM
CREATE CLUSTER
ALTER SESSION
CREATE DATABASE LINK
CREATE PROCEDURE
CREATE SEQUENCE
CREATE TABLE
CREATE SESSION
CREATE TYPE
CREATE VIEW
CREATE TRIGGER

11 rows selected.


Step 3: Create the recovery catalog in catalog database.

$ rman catalog rcat/rcat@catdb

Recovery Manager: Release 11.2.0.3.0 - Production on Thu May 21 09:59:26 2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

connected to recovery catalog database

RMAN> create catalog tablespace cattbs;

recovery catalog created


Step 4: Make Sure to ping the tns connections from target database to catalog and catalog database to target database.


Configure the Listener @Target Side and @Catalog Side.
   
SID_LIST_LISTENER =
 
(SID_LIST =
   
(SID_DESC =
     
(GLOBAL_DBNAME = prim)
     
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
     
(SID_NAME = prim)
    )
  )



LISTENER =
 
(DESCRIPTION =
   
(ADDRESS =
(PROTOCOL = TCP)(HOST = 192.168.0.74)(PORT = 1521))
 
)



ADR_BASE_LISTENER = /u01/app/oracle



SID_LIST_LISTENER =
 
(SID_LIST =
   
(SID_DESC =
     
(GLOBAL_DBNAME = catdb)
     
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
     
(SID_NAME = catdb)
    )
  )



LISTENER =
 
(DESCRIPTION =
   
(ADDRESS =
(PROTOCOL = TCP)(HOST = 192.168.0.75)(PORT = 1521))
 
)



ADR_BASE_LISTENER = /u01/app/oracle


Step 5: Add tns entries into target database and Catalog side database:

   
prim =
 
(DESCRIPTION =
   
(ADDRESS =
(PROTOCOL = TCP)(HOST = 192.168.0.74)(PORT = 1521))
   
(CONNECT_DATA =
     
(SERVER = DEDICATED)
     
(SERVICE_NAME = prim)
   
 )
 
   )


CATDB =
 
(DESCRIPTION =
   
(ADDRESS =
(PROTOCOL = TCP)(HOST = 192.168.0.74)(PORT = 1521))
   
(CONNECT_DATA =
     
(SERVER = DEDICATED)
     
(SERVICE_NAME = CATDB)
   
 )
 
   )


Step 6 : Register the database with Catalog database. Each database should be registered to catalog database to run RMAN backup.


$ rman catalog rcat/rcat@catdb target sys/sys123@prim

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 21 10:02:01 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: PRIM (DBID=1215124933)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete


Step 7: Check the target database is registered into the catalog database.

SQL> select * from rc_database;

DB_KEY  DBINC_KEY       DBID NAME     RESETLOGS_CHANGE# RESETLOGS
———- ———- ———- ——– —————– ———
1          2  701459141 prim                  1 02-JUN-11


RMAN> list db_unique_name all;


List of Databases
DB Key  DB Name  DB ID            Database Role    Db_unique_name
------- ------- ----------------- ---------------  ------------------
2       PRIM  2502578563       PRIMARY          PRIM


Step 8 : Check the RMAN configuration Parameters.

RMAN> Show all;

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/d01/mydb/RMANB
KPS/DEV_%D%M%Y_%s_%p_%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/d01/mydb/RMANBKPS/DEV_%D%M%Y_%s_%p';
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/d02/DEV/tech_st/11.1.0/dbs/snapcf_DEV.f'; # default


Step 9 : Take database full backup. The full database backup should be taken first time. Afterwards, archivelog backup will be taken.

$ rman catalog rman/rman@catdb target sys/password@prim

Recovery Manager: Release 11.3.0.1.0 - Production on Thu May 21 10:16:09 2009

Copyright (c) 1982, 2009, Oracle. All rights reserved.

connected to target database: prim(DBID=1215124933)
connected to recovery catalog database

RMAN> run{
     backup database plus archivelog;
     delete noprompt obsolete;
     }


Step 10 : Now the full backup is taken. Every day, the below script should run and backup the new archive log files.

$ rman catalog rman/rman@catdb target sys/password@prim

Recovery Manager: Release 11.2.0.1.0 - Production on Thu May 21 10:25:40 2013

Copyright (c) 1982, 2009, Oracle. All rights reserved.

connected to target database: prim(DBID=1215124933)
connected to recovery catalog database

RMAN> run{
2> delete noprompt obsolete;
3> backup archivelog all;
4> }

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 2 days
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=133 devtype=DISK
no obsolete backups found

Finished backup at 21-MAY-13

Starting Control File and SPFILE Autobackup at 21-MAY-13
piece handle=C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\C-1215124933-20090521-01 com
ment=NONE
Finished Control File and SPFILE Autobackup at 21-MAY-13

Step 10 : Lists the RMAN Backups:


RMAN> list backup;

Restore and recover a database to another host with RMAN Backup

Steps to restore into another host using RMAN Backup
1) RMAN> backup database; (source db)

2)Transfer this two backup pieces to target machine from source.

3)Determine the DBID of source machine.

SQL> select dbid from v$database;
( DBA (DBID=1130256874) ERA_h (three Schema database backup) (Personal))

4) Now perform task on target machine
$export ORACLE_SID=dba

Then connect to rman,

$ rman target /

5)Set DBID and restore spfile to pfile.

RMAN> set dbid 3386862614
RMAN> startup nomount
RMAN> restore spfile to pfile '/oracle/app/oracle/product/10.2.0/db_1/dbs/initdbase1.ora' from '/oradata2/o1_mf_s_654016132_421c64vl_.bkp';

6)start the instance with pfile.
RMAN> STARTUP FORCE NOMOUNT PFILE='/oracle/app/oracle/product/10.2.0/db_1/dbs/initdbase1.ora';

7)Restore controlfile and mount the database.RMAN> RESTORE CONTROLFILE FROM '/oradata2/o1_mf_s_654016132_421c64vl_.bkp';
RMAN> ALTER DATABASE MOUNT;

8)From SQL*Plus determine the data file and redo log file name.
SQL> COLUMN NAME FORMAT a70SQL> SELECT FILE# AS "File/Grp#", NAME FROM V$DATAFILE
UNION
SELECT GROUP#,MEMBER FROM V$LOGFILE ;

9)Catalog your backuppiece.

RMAN> catalog backuppiece '/oradata2/o1_mf_nnndf_TAG20080506T150716_421c355f_.bkp';

RMAN> list backup;

10)Make a script by issuing SET NEWNAME if you want different file name other than source.
In the script issue SET UNTIL clause and restore and recover database.

RMAN> @/export/home/oracle/rman

RMAN> run{
2> set newname for datafile 1 to '/oradata2/DBA/system01.dbf';
3> set newname for datafile 2 to '/oradata2/DBA/undotbs01.dbf';
4> set newname for datafile 3 to '/oradata2/DBA/sysaux01.dbf';
5> set newname for datafile 4 to '/oradata2/DBA/users01.dbf';
6> set newname for datafile 5 to '/oradata2/DBA/tbs201.dbf';
7> set newname for datafile 6 to '/oradata2/DBA/after_01.dbf';
8> set newname for datafile 7 to '/oradata2/DBA/after_02.dbf';
9> set newname for datafile 8 to '/oradata2/DBA/after_03.dbf';
10> set newname for datafile 1 to '/oradata2/DBA/system01.dbf';
11>
12> SET UNTIL SCN 745212;
13> RESTORE DATABASE;
14> SWITCH DATAFILE ALL;
15> RECOVER DATABASE;
16> }


11)Open the Database resetlogs option.
RMAN> alter database open resetlogs;

RMAN-04006: error from auxiliary database: ORA-01031: insufficient privileges

[oracle@test1 admin]$ rman target sys/oracle@testdb_source auxiliary sys/oracle@testdb_destination
Recovery Manager: Release 11.2.0.1.0 - Production on Thu May 9 21:28:21 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: TESTDB (DBID=2596658962)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-01031: insufficient privileges
 
 
Check the listener.ora and tnsnames.ora file for oracle_sid/db_name entry is upper case or lower case .
I changed the sid name entry of all the mentioned files in the same case  and then tried to connect the auxiliary database, it was successfull at that time.

[oracle@test1 admin]$ rman target sys/oracle@db_source auxiliary sys/oracle@db_destination
Recovery Manager: Release 11.2.0.3.0 - Production on Thu May 10 21:29:47 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DB (DBID=2596658962)
connected to auxiliary database (not started)
RMAN>