Pages

Saturday 14 May 2016

Rman Backup and Restore Steps

Rman Restore Backup Steps:
--------------------------

On Source Database:
-------------------


*********************************************************************

Datafiles Information:
-----------------------

set head off pages 0 feed off echo off verify off
set lines 200
spool rename_datafiles.lst
select 'set newname for datafile ' || file_id || ' to ''/u01/oradata/dhana/' ||
substr(file_name,instr(file_name,'/',-1)+1) || ''';'
from dba_data_files;

spool off
exit;

Redo log Location:
------------------------

set head off pages 0 feed off echo off verify off
set lines 200
spool rename_logfiles.lst
select 'alter database rename file '||''''||member||''''||' to '||''''||'/u01/oradata/dhana/'||substr(member,instr(member,'/',-1)+1)||''''||';' from

v$logfile ;
spool off
exit;

Temp files Information:
-------------------------
set head off pages 0 feed off echo off verify off
set lines 200
spool rename_tempfiles.lst
select 'set newname for tempfile '||''''||name||''''||' to ''/u01/oradata/dhana/' ||
substr(name,instr(name,'/',-1)+1) || ''';'
from v$tempfile;

spool off
exit;

********************************************************************

Execute Rman script:
------------------------

***************************************************************************
today=$(date +'%m-%d-%C%y;%H:%M')
echo $today

ORACLE_SID=testdb

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH:.

export ORACLE_HOME PATH ORACLE_SID

now=$(date +"%d-%m-%Y")

mkdir /u01/Rman_Backup/FULLDB_testdb_$now

export DAY='date +%d'

export NUM='expr $DAY / 7'

$ORACLE_HOME/bin/rman << EOF connect target / run { allocate channel ch00 type disk; allocate channel ch01 type disk; set command id to 'hot_database_backup'; backup as compressed backupset incremental level = 0 check logical database tag='WEEKLY_BACKUP' FORMAT '/u01/Rman_Backup/FULLDB_testdb_$now/testdb_%c_%d_S_%s_P_%p_T_%t' ; backup format '/u01/Rman_Backup/FULLDB_testdb_$now/c_%d_%Y%M%D.%s.%p.%t' current controlfile; release channel ch00; release channel ch01; } delete noprompt obsolete ; list backup; crosscheck backup; delete noprompt expired backup; delete noprompt expired copy; delete noprompt expired archivelog all; EOF today=$(date +'%m-%d-%C%y;%H:%M') echo $today ************************************************************************** Create pfile from spfile; cp init<>.ora

need to create same database name.

scp -r FULLDB_testdb_14-05-2016 oracle@192.168.2.142:/home/oracle

scp -r files oracle@192.168.2.142:/home/oracle

----------------------------------------------------------------------------

Target Machine
--------------


chmod -R 777 FULLDB_testdb_14-05-2016/

After making the necessary changes to the PFILE we now will bring the database back up in NOMOUNT mode so we can restore the control files. When

bringing the database up in NOMOUNT mode we will use the PFILE we edited earlier.

need to create necessary folders for control and datafiles.

add this parameter also must db_unique_name=dhana

mkdir -p /u01/app/oracle/admin/dhana/adump
mkdir -p /u01/oradata/dhana
mkdir -p /u01/oradata/dhana/arc

. oraenv

set source database sid now.

. oraenv
ORACLE_SID = [final] ? testdb
ORACLE_HOME = [/home/oracle] ? /u01/app/oracle/product/11.2.0/dbhome_1

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdhana.ora';
ORACLE instance started.

Total System Global Area 313159680 bytes
Fixed Size 2252824 bytes
Variable Size 180359144 bytes
Database Buffers 125829120 bytes
Redo Buffers 4718592 bytes
SQL>exit


$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 14 00:35:01 2016

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

connected to target database: TESTDB (not mounted)

RMAN> restore controlfile from '/home/oracle/FULLDB_testdb_14-05-2016/c_TESTDB_20160514.34.1.911779959';

Starting restore at 14-MAY-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=25 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/oradata/dhana/control01.ctl
output file name=/u01/oradata/dhana/control02.ctl
Finished restore at 14-MAY-16


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> catalog start with '/home/oracle/FULLDB_testdb_14-05-2016';

Example Output:

searching for all files that match the pattern /home/oracle/FULLDB_testdb_14-05-2016

List of Files Unknown to the Database
=====================================
File Name: /home/oracle/FULLDB_testdb_14-05-2016/testdb_1_TESTDB_S_33_P_1_T_911779903
File Name: /home/oracle/FULLDB_testdb_14-05-2016/testdb_1_TESTDB_S_32_P_1_T_911779903
File Name: /home/oracle/FULLDB_testdb_14-05-2016/c_TESTDB_20160514.34.1.911779959

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oracle/FULLDB_testdb_14-05-2016/testdb_1_TESTDB_S_33_P_1_T_911779903
File Name: /home/oracle/FULLDB_testdb_14-05-2016/testdb_1_TESTDB_S_32_P_1_T_911779903
File Name: /home/oracle/FULLDB_testdb_14-05-2016/c_TESTDB_20160514.34.1.911779959


RMAN> list backup;


RMAN> run {
2> @rename_datafiles.lst
3> set newname for datafile 4 to '/u01/oradata/dhana/users01.dbf';


4> set newname for datafile 3 to '/u01/oradata/dhana/undotbs01.dbf';


5> set newname for datafile 2 to '/u01/oradata/dhana/sysaux01.dbf';


6> set newname for datafile 1 to '/u01/oradata/dhana/system01.dbf';


7> **end-of-file**
8> restore database;
9> switch datafile all;
10> recover database;
11> }

need to add set newname for tempfile '/u01/oradata/testdb/temp01.dbf' to '/u01/oradata/dhana/temp01.dbf';

SQL> @rename_logfiles.lst;

Database altered.


Database altered.


Database altered.

SQL> alter database open resetlogs;

Database altered.


********************************************************

Change database name using NID

cd $ORACLE_HOME/dbs

$ orapwd file=orapwdhana password=****** entries=5

nid target=sys/admin123 dbname=dhana

sqlplus / as sysdba
SQL> startup nomount;
SQL> ALTER SYSTEM SET db_name=dhana SCOPE=SPFILE; (using pfile change db name manually)
SQL> shut IMMEDIATE
SQL> startup mount;
SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> SELECT name, open_mode FROM v$database;


****************************************************













No comments:

Post a Comment