Showing posts with label Rman. Show all posts
Showing posts with label Rman. Show all posts

Saturday, August 22, 2020

Recovery From Loss Of Datafile For Which No Backup Is Available Using RMAN Utility

 

Recovery From Loss Of Datafile For Which No Backup Is Available Using RMAN Utility


SCENARIO – 10g Database Loss of datafile which has not been backed up.



CREATE NEW TABLESPACE TESTCHAITANYA


SQL> create tablespace testchaitanya datafile ‘/u02/oradata/testdb/testchaitanya.dbf’ size 25m;


Tablespace created.


TAKE A BACKUP OF THE DATABASE AT THIS POINT 


ADD DATAFILE TO TESTCHAITANYA TABLESPACE


SQL> alter tablespace testchaitanya add datafile ‘/u02/oradata/testdb/testchaitanya01.dbf’ size 25m;


Tablespace altered.


SIMULATE FAILURE BY REMOVING DATAFILES FOR TESTCHAITANYA TABLESPACE FROM DISK


Note: The tablespace TESTCHAITANYA has two datafiles, but only one has been backed up at this point in time


testdb:/u02/oradata/testdb> rm test*

testdb:/u02/oradata/testdb> sql


SQL> alter tablespace testchaitanya offline immediate;


Tablespace altered.


RESTORE DATAFILE 5; – The datafile which was backed up.


testdb:/u02/oradata/testdb> rman target / catalog rman11p/xxx@rcatp


Recovery Manager: Release 11.1.0.6.0 – Production on Thu AUG 20 09:19:28 2020


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


connected to target database: TESTDB (DBID=2358982414)

connected to recovery catalog database


RMAN> restore datafile 5;


Starting restore at 20/AUG/20

starting full resync of recovery catalog

full resync complete

Finished restore at 20/AUG/20


RMAN> restore tablespace testchaitanya;


Starting restore at 20/AUG/20

using channel ORA_SBT_TAPE_1

using channel ORA_SBT_TAPE_2

using channel ORA_DISK_1


creating datafile file number=6 name=/u02/oradata/testdb/testchaitanya01.dbf >>> In 10g, Oracle creates the missing datafile .

skipping datafile 5; already restored to file /u02/oradata/testdb/testchaitanya.dbf

Finished restore at 14/MAY/09


RECOVER TABLESPACE TEST


SQL> recover tablespace testchaitanya;

Media recovery complete.


SQL> alter tablespace testchaitanya online;


Tablespace altered.


Note: Info on Recovery From Loss Of Datafile For Which No Backup Is Available Using RMAN Utility it may differ from your environment production,testing,development and mountpoints etc


THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME OR SUBSCRIBE ME


Friday, July 31, 2020

RMAN COMMANDS IN ORACLE


RMAN COMMANDS IN ORACLE 
---------------------------------------------

rman target /
rman> show all
rman >backup database plus archivelog;
rman>shutdown immediate;
rman>startup force dba;
rman>shutdown immediate;
rman>startup mount;
rman>backup database;
rman>backup as copy database;
rman>alter database open;


RMAN> BACKUP DATABASE;
RMAN> BACKUP ARCHIVELOG ALL;
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

Note that the PLUS ARCHIVELOG clause performs the following:

Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command
Runs the BACKUP ARCHIVELOG ALL command. If backup optimization is enabled only backs up logs that have not already been backed up.
Backs up files specified in the BACKUP command
Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command
Backs up any remaining archived logs including those generated during the backup
A FORMAT can be specified for each subclause in the BACKUP DATABASE PLUS ARCHIVELOG command. For example:

RUN
{
  ALLOCATE CHANNEL chan01 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/u03/app/oracle/PROD/%d_D_%T_%u_s%s_p%p'
  DATABASE
  PLUS ARCHIVELOG
  FORMAT '/u03/app/oracle/PROD/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL chan01;
}

Note that FORMAT clause precedes the DATABASE clause, but follows the PLUS ARCHIVELOG clause.

The BACKUP command can be extended to backup the current control file and the SPFILE.

For example:

RUN
{
  ALLOCATE CHANNEL chan01 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/u03/app/oracle/PROD/%d_D_%T_%u_s%s_p%p'
  DATABASE
  CURRENT CONTROLFILE
  FORMAT '/u03/app/oracle/PROD/%d_C_%T_%u'
  SPFILE
  FORMAT '/u03/app/oracle/PROD/%d_S_%T_%u'
  PLUS ARCHIVELOG
  FORMAT '/u03/app/oracle/PROD/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL chan01;
}

RMAN> BACKUP CURRENT CONTROLFILE;

RMAN> BACKUP SPFILE;

RMAN> BACKUP DATAFILE '/u01/app/oradata/PROD/users01.dbf';

RMAN> BACKUP DATAFILE 4;

Controlfile backups
-------------------------
The current controlfile can be automatically backed up by the BACKUP command by configuring the CONTROLFILE AUTOBACKUP parameters

To backup the current controlfile explicitly use:

RMAN> BACKUP CURRENT CONTROLFILE;
SPFILE backups The SPFILE can be automatically backed up with the control file during database backups by configuring the CONTROLFILE AUTOBACKUP parameters

To backup up the SPFILE explicitly use:

RMAN> BACKUP SPFILE;
Datafile backups To backup a specific data file use BACKUP DATAFILE. For example:

RMAN> BACKUP DATAFILE '/u01/app/oradata/PROD/users01.dbf';
Altermatively specify the data file number. For example:

RMAN> BACKUP DATAFILE 4;
The data file number can be obtained from V$DATAFILE. For example:

SQL> SELECT file#, name FROM v$datafile;
Tablespace Backups
To backup a tablespace use the BACKUP TABLESPACE command. For example:

RMAN> BACKUP TABLESPACE USERS;
Compressed Backups
To compress the backup use:

RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;
The resulting compressed backup is around 20%-30% of the size of the uncompressed equivalent.

Format clause
The format clause allows the backup files to be directed to a specific location.

For example:

BACKUP FORMAT '/u01/app/oracle/backup/%U' DATABASE;
The above statement created the following files in /u01/app/oracle/backup:

[oracle@vm3]$ ls -l /u01/app/oracle/backup
total 1161280
-rw-r----- 1 oracle oinstall 1178050560 Jul 31 06:31 15qeibgs_1_1
-rw-r----- 1 oracle oinstall    9928704 Jul 31 06:31 16qeibld_1_1

Other formats can be specified. For example:

BACKUP FORMAT '/backup2/PROD/PROD_df_%t_s%s_p%p' DATABASE;
In the above example %t is the backup set timestamp, %s is the backup set number and %p is the piece number within the backup set.

Tags:A backup tag can optionally be specified with the BACKUP command.

For example:

BACKUP DATABASE TAG = 'Full_Backup';
The tag is reported by the LIST command.

If a tag is not specified then a system-generated tag is assigned.

Incremental Backups
-------------------------------
By default backups are full (level 0). Backups can also be incremental (level 1).

Incremental backups can be:
-----------------------------------

Differential - includes all changes since the last full or incremental backup
Cumulative - includes all changes since the last full backup
Differential backups require less space. Cumulative backups are faster to restore

Differential backups are the default.

To run a diffential incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;
To run a cumulative incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
Note that in order to take a level 1 backup, a level 0 backup must already exist.

A full backup using BACKUP DATABASE is not the same as a level 0 backup. - the LV column of the LIST BACKUP output is NULL after a full backup.

In order to take a level 0 backup use

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;
To create an image copy of an entire database use:

RMAN> BACKUP AS COPY DATABASE;
To create an image copy of a specific datafile use:

RMAN> BACKUP AS COPY DATAFILE <file#>
For example:

RMAN> BACKUP AS COPY DATAFILE 4 FORMAT '/u01/app/oracle/copy/users01.dbf';
Alternatively specify the source file name. For example:

RMAN> BACKUP AS COPY DATAFILE '/u01/app/oradata/PROD/users01.dbf'
FORMAT '/u01/app/oracle/copy/users01.dbf';
Recovery Area
To backup the recovery area use:

RMAN> BACKUP RECOVERY AREA TO DESTINATION '/u02/app/oracle';
Note that a destination must be specified if the recovery area is being backed up to disk.



Note : Info on Rman commands it may be differ in your environment like production,development,testing


THANK YOU FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME

Thursday, July 23, 2020

ORACLE RMAN(RECOVERY MANAGER) COMPONENTS AND CONFIGURATIONS

ORACLE RMAN(RECOVERY MANAGER) COMPONENTS AND CONFIGURATIONS:  

RMAN:
             Rman or Oracle Recovery Manager introduced in oracle 8i,oracle proprietary software client or utility similar to sqlplus used to perform backups,restores,recoveries and other Database operations,Rman takes backup only usedblocks in entire database blocklevel backup,it performs block level backup parallelism,Rman is the utility to take backups and restore oracle recommends,Rman is faster it takes block level backups,Rman is faster because we can initiative parallesism,validate your database using Rman detect block corruption,Rman will repair the database block corruption for you validating backup,incremental backup,recovery catalog.and it is a platform independent tool.
            Rman stores backup metadata inforamtion in the database ,use control file to hold backup metadata information catalog, also using remote repsitory catalog schema database it is a online backup tool its a special feature does block backup with incremental concept,metadata is the control file data stores the information into different database on server,Multi destination backups like tapes,Archive log mode is must to use Rman. Rman utility comes with oracle binaries,no special installation orlicence required for using Rman at command prompt just type rman,it defaults connects to database environmental variables defined, Rman utility can be used only when Database is atleast mount stage,Rman is used while the database is UP and running and have a very little performance impact is backup is running .

COMPONENTS OF RMAN
------------------------------------
RMAN PROMPT
TARGET DATABASE
RECOVERY CATALOG
AUXILAR DATABASE-->clone DB connection target clone
MEDIA MANAGEMENT LAYER-->RMAN and third party tools (net backup)
RMAN CHANNELS---> back up is speed 

FULL BACKUP-----> ENTIRE DATABASE BACKUP (RMAN FULL BACKUP IS EQUAL TO HOT BACKUP  CANNOT APPLY INCREMENTAL BACKUP ON FULL BACKUP)
              

INCREMENTAL BACKUP----> LEVEL 0--->FULL DB BACKUP--> Full Db backup takes bakup of the used blocks( we can restore Db level0)

  |----> LEVEL 1--->BACKUP CHANGES ONLY FROM LAST LEVEL 0 BACKUP--->Takes Backup of only the changed blocks from last backup,Rman will know which block will be changed block header SCN number backup only changed block  taken by referrring data block header for updated SCN (we can recover DB applying archives and open database)

RECOVERY IN TWO PARTS----->RESTORE--->LEVEL 0
                                              |--->RECOVERY--> LEVEL 1

CONFIGURATIONS OF RMAN
-----------------------------------------
To connect using rman
----------------------
$rman target/

To Display the configuration of RMAN.
------------------------------------
rman>show all;


Configuring Device Type - Tape / Disk
----------------------- --------------
For Tape: Tivoli manager (IBM)

rman>Configure default device type to sbt;

For Disk : Default
-------------------
rman>Configure default device type to disk;

Configuring Channels with Parallelism Option - EE
---------------------------------------------
Multiple backupsets can run with parallel option.

Depends on number of cores, can increase the performance of the backup using multiple channels.

$mkdir -p /orabackup/prod/rman/stream1
$mkdir -p /orabackup/prod/rman/stream2

rman>Configure device type disk parallelism 2;
rman>CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/orabackup/prod/rman/stream1/backup%U';
rman>CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/orabackup/prod/rman/stream2/backup%U';

Maximum Piece Size
------------------
Limit the backup piece size 
rman>CONFIGURE CHANNEL  DEVICE TYPE DISK MAXPIECESIZE 1000m;


Optimization
------------
oracle skips the files that are already backedup by enabling optimization.

rman>configure backup optimization on;


Control file autobackup
-----------------------
Control file holds data and control information of database
 as well metadata of backup information.

On every backup event, the control has to get backed up. Enable autobackup.
With control file - includes spfile also

rman>configure controlfile autobackup on;

rman>configure controlfile autobackup off;


rman>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/orabackup/prod/rman/%F';

Eg:
Output :
--------
Starting Control File and SPFILE Autobackup at 23-JUL-20
piece handle=/orabackup/prod/rman/c-369100151-20171110-00 comment=NONE
Finished Control File and SPFILE Autobackup at 23-JUL-20


Retention Policy - default 1 day
----------------
is defined , how to long to hold the backups ..
Once retention value reached, the backup files will expire.

rman>CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;


Snapshot controlfile
---------------------
rman>CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/orabackup/prod/rman/snapcf_prod.f';

To update the recovery catalog to get sync for consistent , will have a snapshot controlfile.


Backup sets / Backup Pieces
---------------------------

RMAN can also store its backups in an RMAN-specific format called a backup set.

A backup set is a collection of files called backup pieces, each of which may contain the backup of one or several database files.


retention
optimization
control on , path/loc
snapshot
parallelism
channels 
maxpiecesize
disk/tape
---------------------------------------------
How to have a backup using rman?

rman target/
rman>backup database plus archivelog;

Only datafiles
rman>backup database;

only archivelog files
rman>backup archivelog all;

Image backup - same as dbf format
rman>backup as copy database;

list of backup files
rman>list backup;
rman>list backup summary;






Error : scenario:
----------------
ORA-19625: error identifying file /archives/prod/1_986936449_51.arc
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory

in case : 
archive log missing , cannot continue backup.

for that , use crosscheck command . will validate the existing archives and mark has expired for
those missing archives in control file. so next backup will skip those missing archives found expired.

rman>crosscheck archivelog all;
rman>backup database plus archivelog;

For backups 
rman>crosscheck backup;

Error : Scenario:-
-----------------
ORA-19502: write error on file "/orabackup/prod/rman/stream2/backup0kth1k51_1_1", block number 51456 (block size=8192)
ORA-27072: File I/O error

Verify the physical file system space on /orabackup
$df -h
if 100% 
remove old files using

Step1 : rman>report obsolete;
will list all files that are expired/obsolete;
Step2 : rman>delete obsolete;
will delete those listed obsolete files.

If those files not listed and not part of the same database.
then delete using rm -rf * from /orbackup/prod/rman/stream1
1. cd /orabackup/prod/rman/stream1
2. ls -ltrh
3. $rm -rf *


Compressed backup
-----------------
rman>BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;

Validate the db
RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

Skip those archives missing,and free up space on archive location while 
backup.
----------------------------------------------------
RMAN>backup archivelog all delete input skip inaccessible;

/archives - 100%
Take a archive log backup,and resume space by deleteing those backedup archives.

move -/archives - /orabackup (1-10 -old ls -ltr)
backup - delete - space resumed
/orabackup-/archives (1-10) - free already
crosscheck
backup - delete

Connect - RMAN
Backup and Recovery
Configuration
retention policy
controlfile auto
path - controlfile
parallelism - faster
channels
optimization - to skip
snapshot -
maxpiece size

Backup sets - specific format
Backup pieces - files
backup database plus archivelog
crosscheck - validate
delete obsolete
report obsolete

Incremental - Level0 - level 1 | Cummulative
Difference - delete obsolete | delete expired
compressed

Backup Strategy - Explain ?
--------------------------
Incremental backup - Block Level - only changes.

Two types of incremental backup.
    Level 0 - Full incremental backup
    Level 1
        Differential incremental backup.
        Cummulative Backup

Full Incremental - Level 0 Backup -is the full complete
 base backup taken normally on peak off hours.


RMAN>BACKUP INCREMENTAL LEVEL 0 DATABASE;

Level - 1

Differential Backup
-----------------
Sunday – full backup Including all archivelogs – this is a base backup.
Up on this – all changes made will be backedup on every day since last
 incremental backup.

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

Cummulative – Including all Previous Changes from
base backup (Level 0) on Sunday.
----------

RMAN>BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

So we can use next incremental backup for recovery , if previous level 1 backups are lost.
Its the best backup. If no redundancy.

But still, having multiple reduncies in terms tapes/disks. Will
recommend differential.

Crosscheck
---------

we have archives ,... while backup if archives are missing ? can we continue
 the backup?
What happens ?
 The backup fails.
How to continue ?...

ORA-19625: error identifying file /archives/prod/1_998901437_22.arc

RMAN> crosscheck archivelog all;
Crosscheck command validates archives physically exists and updates control
 file repository the file status.
So while rman backup , will verify the catalog and skip those files are
expired(marked) which are physically not exists.

rman>backup archivelog all;
But recommended to continue with full backup in this situation.

every 2/4 hrs will have archive log backup.


Difference between delete obsolete and delete expired?
------------------------------------------------------

Obsolete? : out of retention period. physically files exists and files are
 out retention.

Expired : physically not exists and marked has expired in catalog.

rman>report obsolete;
rman>delete obsolete;

rman>delete expired backup;
will delete records from catalog those expird.


Note:
Level 0 - Full Incremental Backup - Complete
1TB
Level 1
Differential -- Only changes from last incremental
Mon - 1GB -
Tues - 0.5G
Wed - 0.25G -
Only those changes - the difference
Cummulative - best - including previous changes on top of base backup
Mon - 1G
Tues - 1G+0.5G - lost
Wed = 1G+0.5+0.25G - can retain from wed backup of Tues
which includes previous changes as it is cummulative

Space and time

Real time , we use only differential if redundancy managed with additional tape and storage backup.
If tape backup of tuesday with differential and lost disk backup
Can we retain from tape

/orabackup - rman - tues -
once done
will have tape backup



Note:
------
rman>backup archivelog all delete input skip inaccessible;

difference delete obsolete and expired

based on retention, the backup files get expired but physically exists
those need to be deleted
as backup policy , retention 7 days if incremental
after 7 days - expired
need to clean up space to resume
use obsolete

Recoveries
----------
Recover - Lost datafile
-----------------------

    users will not be able to write in users datafile (scott/hr-eg)

Make sure - we have full DB backup - last night including - archives.
as we lost - keep offline datafile.
@09 last night
rman>backup database plus archivelog;
@next day at 03PM - lost datafile
$rm users01.dbf
SQL> alter database datafile '/oradata/prod/users01.dbf' offline;

rman target/
RMAN>restore datafile '/oradata/prod/users01.dbf';
rman>recover datafile '/oradata/prod/users01.dbf';
will recover changes from last night 09 till today 03pm from
archives.

SQL> alter database datafile '/oradata/prod/users01.dbf' online;

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

inconsistent Recovery - If no archives.
    Timebased
        using SCN number(v$database)


As you would expect, RMAN allows incomplete recovery to a specified time,
 SCN or sequence number:

$rman target/
$rman>run {
 shutdown abort;
 startup mount;
 set until sequence 21;
 restore database;
 recover database; #media recovery from archiveslogs
 alter database open resetlogs;
}

-----------------------------------
Whole database recovery
-----------------------

If the controlfiles and online redo logs are still present a whole database
 recovery can be achieved by running the following script:
rman target/
rman>
run { shutdown abort
# use abort if this fails
 startup mount;
 restore database;
 recover database;
alter database open;
}

Note: Using run{} block ,we can execute multiple commands in rman.
-------------------------------------
Difference between delete obsolete and delete expired


Delete Obsolete - will delete, where the files physical exists and out of
 retention period.
rman>delete obsolete;
rman>delete obsolete noprompt;

Delete expired - will delete those files are marked as expired and physically
 not exists.
rman>delete expired backup;
---------------------------------------------------
Compressed backup
-----------------
rman>BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;

Validate the db
RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

Skip those archives missing,and free up space on archive location while
backup.
----------------------------------------------------
RMAN>backup archivelog all delete input skip inaccessible;

/archives - 100%--->/orabackup
space resume by delete
if missed,skipping

move -/archives - /orabackup (1-10 -old ls -ltr)
backup - delete - space resumed
/orabackup-/archives (1-10) - free already
crosscheck
backup - delete

13.arc bkp arclog
14.arc
15.arc
16.arc till - next fail. due to missing archives
18.arc skip(17) - inaccessible will continue also delete
those backedup(13,14,15,16,18).
21.arc skip(19,20) - inaccessible
backup completed and resumed space
22.arc
23.arc
missing 17/19







NOTE: info on Rman may be differs in  your environment like production,testing,development or u r host machine.




THANK YOU VIEWING MY BLOG FOR MORE UPDATES VISIT MY BLOG REGULARLY















































Wednesday, July 22, 2020

Oracle Database Cloning Using Rman Utility


Oracle Database Cloning Using Rman Utility
-----------------------------------------------------

Prerequisites 
-------------

1)OEL Oracle enterprise Linux server

2)Oracle installed with out database


Activity Flow
------------- 

1)Take source backup using Rman

2)move pfile,Controlfile,backup pieces, to target server 

3)Start the Instance in Mount Stage and Restore from backup pieces

4)Open the database as source SID

5)Rename the Database


Trigger Backup on source
------------------------

$ RMAN> backup database plus archivelog delete input;
$ RMAN> restore controlfile to '/tmp/prod_control.ctl';


Move files to Target server
----------------------------
parameter file pfile

edit pfile change SID except for DB_NAME parameter keep it source

create directories as per new pfile


$ RMAN> rman target /catalog rman-rc/rman-rc@rca
$ RMAN>backup database plus archivelog delete input;
$ RMAN>list backup of database summary;
$ RMAN>restore controlfile to '/tmp/prod_control.ctl';
$ RMAN>exit

$ cd ORACLE_HOME/dbs
$ ls -lrt
  initproddb.ora
 
i want to copy the initproddb.ora to the target server using scp

$ scp initproddb.ora oracle@192.168.0.100:$ORACLE_HOME/dbs    (it will ask password promt enter the password remote target server and enter it)

initproddb.ora   (you will prompt the 100% complete)

Target server
-------------

$ cd   ORACLE_HOME/dbs

$ ls -lrth

initproddb.ora

open this file in VI editor

replace with 

%s/proddb/testdb/   

save and exit the file  

(source db is proddb and target db is testdb create the directories as per new file)

(after that open the parameter file initproddb.ora in cat command we need to create directories)

$ cat initproddb.ora

$ mkdir -p /u01/app/oracle/admin/testdb/adump

$ mkdir -p /u01/app/oracle/oradata/testdb/

$ mkdir -p /u01/app/oracle/fast_recovery_area/testdb/

$ mkdir -p /u01/app/oracle/fast_recovery_area

scp/tmp/prod_control.ctl ---> target server control location  move files to target server

$ cd /tmp
 $ ls -lrth

source server
----------------

$ scp prod_control.ctl oracle@ 192.168.0.100:/u01/app/oracle/oradata/testdb/control01.ctl
$ scp prod_control.ctl oracle@ 192.168.0.100:/u01/app/oracle/oradata/testdb/control02.ctl

Target Server
-------------

$ ls -lrth

$ /u01/app/oracle/oradata/testdb/control01.ctl
$ /u01/app/oracle/oradata/testdb/control02.ctl

database backup pieces ---> same location as source

$ rman target /catalog rman -rc/rman_rc@rcat

conneceted target database :proddb (DBID=674237234)
connecteed to recovery catalog database

$ RMAN> list backup of database summary;  (it will show like this key ty lv device type and tag)

key --> 2949  ty--->B   LV--->A  Device type---> disk  Tag ---> TAG202012t105306  (tag is the important using tag only we can perform restore and recovery in backup)

$ RMAN> list backup TAG202012t105306;

list of backup piece name :/u01/app/oracle/fast_receovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp



$ scp/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp oracle@192.168.0.100:/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/

Target server
--------------

$ mkdir-p /u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20   (target server directory may not exist create this directory)

archive backup pieces ---> same location as source

$ scp/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/TAG202012t105306.bkp oracle@192.168.0.100:/u01/app/oracle/fast_recovery_area/proddb/backupset/2020-07-20/

Start cloning 
------------------

export environment variables connect to rman

Target Server
-------------

$ env |grep ora
 ORACLE_SID =proddb
ORACLE_HOME= '/u01/app/oracle/product/11.2.0/db_home-1

$ rman target /

connected to target database (not started)

$ RMAN> startup mount;

get the last scn available in the archive log backup

$RMAN> list backup of archivelog all;

last archive log--> 6  next scn---.> 960034

-Rename the DB redolog files so they can be created in new location
--------------------------------------------------------------------

sql> alter database rename file '/u01/app/oracle/oradata/proddb/redo01.log' to '/u01/app/oracle/oradata/testdb/redo01.log';

Target server
-------------

sql> select member from v$logfle;

member
-------

/u01/app/oracle/oradata/proddb/redo03.log
/u01/app/oracle/oradata/proddb/redo02.log
/u01/app/oracle/oradata/proddb/redo01.log

we have to change the datafile proddb to testdb redo03,02,01

Restore the datafiles to new location
----------------------------------------

run {

set newname for datafile1 to '/u01/app/oracle/oradata/testdb/system01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/sysaux01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/undotbs01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/user01.dbf';
set newname for datafile1 to '/u01/app/oracle/oradata/testdb/example01.dbf';

restore datafile from TAG202012t105306;
switch datafile all;
recover database untill scn 960034;
alter database open resetlogs;
}

Renaming Database after cloning
--------------------------------


sql> select name,open_mode from v$database;

name--->proddb  open_mode->read_write 

hostname  dctest.chaitanya.com

 ( we have to rename the proddb to testdb we are in the testserver)

Take control file backup to trace with resetlog options
--------------------------------------------------------

sqlplus '/as sysdba'

sql> alter database backup controlfile to trace as'/tmp/ create_ctrol_file.sql';

sql> database altered

sql> shut immedaite ;

sql>exit

create pfile for new dbid
-------------------------

$cd $ORACLE_HOME/dbs
$ ls -ltr

initproddb.ora

$ mv initproddb.ora inittestdb.ora

$ vi inittestdb.ora        (one parameter db_name =proddb change to testdb   db_name=testdb save and exit vi editor)

$ export ORACLE_SID= testdb 

sqlplus '/as sysdba'

startup instance in nomount stage
---------------------------------
sql>startup nomount;
exit
$ cd/tmp
ls -lrt
create_ctrolfile.sql           (copy the create_ctrolfile.sql to new note pad and paste it)

$ cat create_ctrolfile.sql

Edit the control file in trace location with new sid  
-----------------------------------------------------

create control file set database  "testdb" resetlogs archivelog

remove reuse and set change norestlogs to resetlogs

it look like this when u open file 

maxlogfile
--
---
---
log file
--
--
group1 /u01---
group2 /u01---
group3 /u01---

datafile 
 
------/u01
---
---
---
---

character set WE8MSWIN1252


$cd  $ ORACLE_HOME/dbs  (remove the oldcontrol file)

$ ls -lrt
$ inittestdb.ora
cat inittsetdb.ora
$ rm-rf /u01/app/oracle/oradata/testdb/control01.ctl /u01/app/oracle/oradata/testdb/control02.ctl

Create controlfiles for new instance
------------------------------------

sqlplus '/as sysdba'

sql> select instance_name ,status from v%instance;

instance_name -->testdb   

status--->started

we have created control statement create_ctrol.sql and run 

 it will display controlfile created

sql> alter database open resetlogs

sql>select name,open_mode from v$database;

name---> testdb

open_mode---> read,write

sql> select name from v$ controlfile;

sql>select member from v$ logfile; 


cloning is done

Note: it will differ in your environment it may be u r development or testing or production and also directory structure in linux  mountpoints and IP address but the process is same.  


THANK YOU FOR VIEWING FOR MORE UPDATES VISIT MY BLOG 

http://chaitanyaoracledba.blogspot.com/ 

ITIL Process

ITIL Process Introduction In this Blog i am going to explain  ITIL Process, ITIL stands for Information Technology Infrastructure Library ...