0% found this document useful (0 votes)
8 views

RMAN Setup

Oracle RMAN

Uploaded by

Nasir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

RMAN Setup

Oracle RMAN

Uploaded by

Nasir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

rman target / catalog rman/[email protected] auxiliary=sys/auxsystem@aux.

world

--note: do not keep the catalog db and target db on same db

--for itnbheem, catalog is on rman/[email protected]

RMAN configuration parameters for ITNPROD are:

connected to target database: ITNPROD (DBID=1536850883)


connected to recovery catalog database

RMAN> show all;

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;


CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
'/u11/oracle/backups/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
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 SNAPSHOT CONTROLFILE NAME TO
'/v01/app/oracle/product/9.2/dbs/snapcf_ITNPROD.f'; # default
#Configure compression. -- Oracle 10g
#CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;

-- the following are required only if you want to configure RMAN first time on a db
and create a new recovery catalog
-----------------------------------------------------
CREATE TABLESPACE "TOOLS" DATAFILE
'/u02/oradata/itnbheem/TOOLS_01.dbf' SIZE 200M REUSE
NOLOGGING ONLINE PERMANENT BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;

CREATE USER rman IDENTIFIED BY rman


TEMPORARY TABLESPACE temp
DEFAULT TABLESPACE tools
QUOTA UNLIMITED ON tools;

--List all archivelog backups for the past 24 hours:


RMAN> LIST BACKUP OF ARCHIVELOG FROM TIME 'sysdate-1';

GRANT RECOVERY_CATALOG_OWNER TO rman;

GRANT CONNECT, RESOURCE TO rman;

oracle@itnbheem$ rman CATALOG rman/[email protected]

Recovery Manager: Release 9.2.0.6.0 - 64bit Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to recovery catalog database


recovery catalog is not installed

RMAN>CREATE CATALOG;
recovery catalog created

RMAN> exit

Recovery Manager complete.


oracle@itnbheem$ rman TARGET / CATALOG rman/[email protected]

RMAN>REGISTER DATABASE;

database registered in recovery catalog


starting full resync of recovery catalog
full resync complete

RMAN>

RMAN> report schema;

Report of database schema


File K-bytes Tablespace RB segs Datafile Name
---- ---------- -------------------- ------- -------------------
1 409600 SYSTEM YES /u02/oradata/itnbheem/system01.dbf
2 358400 UNDOTBS1 YES /u02/oradata/itnbheem/undotbs01.dbf
3 10240 TS2008 NO /u02/oradata/itnbheem/TS2008_01.dbf
4 10240 IX2008 NO /u02/oradata/itnbheem/IX2008_01.dbf
5 204800 TOOLS NO /u02/oradata/itnbheem/TOOLS_01.dbf
9 25600 USERS NO /u02/oradata/itnbheem/users01.dbf
10 39040 XDB NO /u02/oradata/itnbheem/xdb01.dbf
11 1024000 TPAPP1 NO /u02/oradata/itnbheem/TPAPP1_01.dbf
12 1024000 TPIDX1 NO /u02/oradata/itnbheem/TPIDX1_01.dbf

RMAN>CONFIGURE RETENTION POLICY TO REDUNDANCY 2;


RMAN>CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
RMAN>CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
RMAN>CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/app/oracle/backup/ora_df%t_s
%s_s%p';
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
'/u01/app/oracle/backup/ora_cf%F';
RMAN>CONFIGURE BACKUP OPTIMIZATION ON;

------------------------------------------------------end first time


RMAN>BACKUP DATABASE ;

# Whole database and archivelogs. -- oracle 10g


BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;

# Datafiles 1 and 5 only. -- oracle 10g


BACKUP AS COMPRESSED BACKUPSET DATAFILE 1,5;

steps for backingup in NOARCHIVELOG mode


-------------------------
RMAN>shutdown immediate ;
RMAN>startup mount;
RMAN>BACKUP DATABASE ;
RMAN>alter database open;
-------------------------
RMAN>list backup;
RMAN>list backup summary;
RMAN>

$rman target / catalog rman/[email protected] auxiliary sys/[email protected]

$rman target /

RMAN> connect catalog rman/[email protected]

RMAN> connect auxiliary sys/[email protected]

connected to auxiliary database (not started)

RMAN> STARTUP CLONE NOMOUNT FORCE;

Oracle instance started

Total System Global Area 370641504 bytes

Fixed Size 731744 bytes


Variable Size 335544320 bytes
Database Buffers 33554432 bytes
Redo Buffers 811008 bytes

RMAN> DUPLICATE TARGET DATABASE TO AUX;


RMAN>duplicate target database to aux skip tablespace tpidx1;

rman TARGET / CATALOG rman/[email protected] auxiliary


sys/[email protected]
run {
set until time = "TO_DATE('01/08/2008 11:54:00','mm/dd/yyyy hh24:mi:ss')";
--set UNTIL TIME = 'SYSDATE-7'
DUPLICATE TARGET DATABASE TO PRODMIRROR ;
}

--to unregister a db using db_key and dbid (get these from rman.rc_database)
EXECUTE dbms_rcvcat.unregisterdatabase(1,475939196);

--to upgrade:
RMAN> upgrade catalog;

--to delete a backup


RMAN>DELETE NOPROMPT BACKUP OF DATABASE COMPLETED BEFORE 'SYSDATE-20';

--to list expired backups


RMAN> list expired backup;

Note: command to skip multiple tablespaces


SKIP TABLESPACE tbs1, tbs2, ...tbsX;

select * from
(select * from rc_backup_set
order by completion_time desc)
where rownum < 31;

select * from rc_backup_set where trunc(completion_time) = trunc(sysdate-14);


SELECT BS_KEY, BACKUP_TYPE, COMPLETION_TIME
FROM RC_DATABASE_INCARNATION i, RC_BACKUP_SET b
WHERE i.DB_KEY = 1
AND i.DB_KEY = b.DB_KEY
AND i.CURRENT_INCARNATION = 'YES';

Commands:
SQL 'ALTER DATABASE MOUNT'
SQL 'ALTER DATABASE OPEN'

ALTER SYSTEM SWITCH LOGFILE


ALTER SYSTEM ARCHIVE LOG CURRENT

ALLOCATE SINGLE TAPE CHANNEL (backup)


ALLOCATE SINGLE TAPE CHANNEL (restore)
ALLOCATE MULTIPLE TAPE CHANNELS (backup)
ALLOCATE MULTIPLE TAPE CHANNELS (restore)
ALLOCATE SINGLE DISK CHANNEL (backup)
ALLOCATE SINGLE DISK CHANNEL (restore)
ALLOCATE MULTIPLE DISK CHANNELS (backup)
ALLOCATE MULTIPLE DISK CHANNELS (restore)
CONFIGURE RETENTION POLICY TO REDUNDANCY 3
CONFIGURE DEFAULT DEVICE TYPE TO TAPE
CONFIGURE CONTROLFILE AUTOBACKUP ON

CREATE CATALOG

CROSSCHECK ARCHIVELOG ALL


CROSSCHECK BACKUP
DELETE EXPIRED BACKUP

LIST BACKUP
LIST BACKUP SUMMARY
LIST COPY
LIST INCARNATION OF DATABASE

REGISTER DATABASE
REPORT SCHEMA
REPORT NEED BACKUP INCREMENTAL 3 DATABASE
REPORT NEED BACKUP DAYS 3 DATABASE
REPORT NEED BACKUP DAYS 3 TABLESPACE SYSTEM
REPORT NEED BACKUP REDUNDANCY 3
REPORT UNRECOVERABLE
REPORT OBSOLETE

RESET DATABASE
RESYNC CATALOG
SHOW ALL

SHUTDOWN
STARTUP

VALIDATE
VIEW SCHEMA
SET UNTIL TIME='SYSDATE-1';
RESTORE DATABASE VALIDATE; # to get the file names involved in restore

#Restore Validation confirms that a restore could be run, by confirming that all
database files exist and are
#free of physical and logical corruption, this does not generate any output.

run
{
set until time='sysdate-1';
restore database validate;
}

# the following gives the file names


# full backup is taken on fridays
select handle, tag, start_time, completion_time from rc_backup_piece
where (trunc(completion_time) >= trunc(sysdate - 4) and trunc(completion_time) <=
trunc(sysdate - 3))
and (tag='BACKUP_DB_LEVEL_0' or tag is null);

#the following gives the set until time


select max(completion_time)+1/86400 from rc_backup_datafile where bs_level = 0;

####script to get the list of latest backupset files


declare
compl_time date :=null;
handle rman.rc_backup_piece.handle%type;
vOutputFileName VARCHAR2(60) := 'files_to_compress.dat';
vOutFileHandle UTL_FILE.FILE_TYPE;
vOutputFilePath VARCHAR2(40) := '/u01/app/oracle/admin/TPDEV/scripts';

cursor cFilesList is
select handle from rman.rc_backup_piece
where (trunc(completion_time) >= compl_time and trunc(completion_time) <=
compl_time+1)
and (tag='BACKUP_DB_LEVEL_0' or tag is null);

begin
select max(trunc(completion_time)) into compl_time
from rman.rc_backup_piece
where tag='BACKUP_DB_LEVEL_0';

vOutFileHandle := UTL_FILE.FOPEN(vOutputFilePath, vOutputFileName, 'w');


for vFilesList in cFilesList
loop
handle := vFilesList.handle;
UTL_FILE.PUT_LINE(vOutFileHandle, handle);
end loop;

UTL_FILE.FCLOSE(vOutFileHandle);

end;
##################

######
##steps for restore
##do these steps on the new host

RMAN> TARGET / NOCATALOG


SET DBID 1536850883; #ITNPROD production database, this must be outside the RUN
block
RUN
{

--DEBUG ON (FOR DEBUG MODE)


SHUTDOWN IMMEDIATE;
STARTUP FORCE NOMOUNT;

CONFIGURE DEVICE TYPE DISK PARALLELISM 6;

--ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='...';


--RESTORE SPFILE TO PFILE FROM AUTOBACKUP;
--SHUTDOWN ABORT;

SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO


'/u11/oracle/backups/%F';
allocate channel d1 type disk ;
allocate channel d2 type disk ;
allocate channel d2 type disk ;

RESTORE CONTROLFILE FROM AUTOBACKUP;


ALTER DATABASE MOUNT;

SET UNTIL TIME = "TO_DATE('2008-01-15 09:32:12','YYYY-MM-DD HH24:MI:SS')";


RESTORE DATABASE;
RECOVER DATABASE SKIP TABLESPACE
TS2004,IX2004,TS2005,IX2005,IX2007,TS2007,IX2006,TS2006,IXARCHNOPART,TS2008,IX2008;

CONFIGURE DEVICE TYPE DISK PARALLELISM 2;

ALTER DATABASE OPEN RESETLOGS;

RELEASE CHANNEL d1;


RELEASE CHANNEL d2;
RELEASE CHANNEL d3;
--DEBUG OFF
}
##################

############
--steps to prepare the auxiliary database instance on a new host
--all of the following steps are performaed on auxiliary host only
----------------------------------------------------------------
1. Create an Oracle Password File for the Auxiliary Instance
cd $ORACLE_HOME/dbs
orapwd file=$ORACLE_HOME/dbs/orapw password=firesys entries=15 force=y ignorecase=y

2.add auxiliary sid to tnsnames.


cd $ORACLE_HOME/network/admin
vi tnsnames.ora

add the following:


PRODMIRROR.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.28.6.231)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prodmirror.itradenetwork.com)
)
)

Important Note: Repeat the step #2 on prod server host too.

3.FTP the pfile from prod server to new auxiliary host


ftp the initITNPROD.ora
copy to $ORACLE_HOME/dbs/initPRODMIRROR.ora on new host

4. edit $ORACLE_HOME/dbs/initPRODMIRROR.ora file and make the following changes.

---
---
##########################
#to check and repair block corruption using RMAN

#Normally RMAN checks only for physically corrupt blocks


#with every backup it takes and every image copy it makes.
#This is a common misunderstanding amoung a lot of DBAs.
#RMAN doesn not automatically detect logical corruption by default!
#We have to tell it to do so by using CHECK LOGICAL!

##
run {

allocate channel c1 device type disk ;


allocate channel c2 device type disk ;
allocate channel c3 device type disk ;
allocate channel c4 device type disk ;
backup validate check logical database;

#rman populates a view with the block corruption results


select count(*) from v$database_block_corruption;�

Now we can tell RMAN to recover all the blocks


which it has found as being corrupt:
RMAN> blockrecover corruption list;
# (all blocks from v$database_block_corruption)

##########

UNREGISTER COMMANDS:

1. First start RMAN by connecting to target db and catalog.

rman target / catalog rman/[email protected]

2. Delete all backupsets recorded in the repository:


RMAN> LIST BACKUP SUMMARY;
RMAN> DELETE BACKUP DEVICE TYPE SBT; -- for tape
RMAN> DELETE BACKUP DEVICE TYPE DISK;
or
rman>delete noprompt expired backup;
rman>delete noprompt expired archivelog all;
rman>delete noprompt obsolete;
rman>crosscheck backup;
rman>crosscheck archivelog until time 'sysdate-1';
rman>delete noprompt expired archivelog until time 'sysdate-1';

3. Connect to RMAN db using SQL:

SQL> CONNECT rman/[email protected]


Connected.
SQL> SELECT db_key, db_id
2 FROM db
3 WHERE db_id = 1487421514;

DB_KEY DB_ID
---------- ----------
1 1487421514

1 row selected.

SQL>EXECUTE dbms_rcvcat.unregisterdatabase(1, 1487421514);

PL/SQL procedure successfully completed.

SQL>
--------------------------------------------------------------------

Check whether backup pieces, proxy copies, or disk copies still exist.
This fixes any problems too.

Examples:

Assuming you have configured automatic channels:

RMAN> CROSSCHECK BACKUP;


RMAN> CROSSCHECK COPY;
RMAN> CROSSCHECK backup of database;
RMAN> CROSSCHECK backup of controlfile;
RMAN> CROSSCHECK archivelog all;

##To run RMAN command from a command file and have the rman output go to a logfile,
call it like this:

rman target / cmdfile rman_backup.cmd log rman_backup.log 2>&1 &

You might also like