Recover dropped table
using RMAN Tablespace point in time recovery:
1. Copy the backup on the other server where you want
to do cloning:-
[oracle@localhost
backup]$ sqlplus
SQL*Plus:
Release 11.2.0.1.0 Production on Wed Aug 6 16:35:40 2014
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Enter
user-name: rudra
Enter
password:
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------
------- ----------
DEPT TABLE
DEPT1 TABLE
EMP TABLE
EMP1 TABLE
LOC TABLE
SQL> drop
table dept purge;
Table dropped.
[oracle@localhost
~]$ cd /u01/backup/
[oracle@localhost
backup]$ ls
07pf9bgl_1_1
08pf9bgt_1_1 09pf9biv_1_1 c-820201958-20140806-03
[oracle@localhost
backup]$ scp * oracle@192.168.204.131:/u01/asm
Address
192.168.204.131 maps to localhost.localdomain, but this does not map back to
the address - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.204.131's
password:
07pf9bgl_1_1 100% 59MB
19.6MB/s 00:03
08pf9bgt_1_1 100%
1023MB 4.2MB/s 04:02
09pf9biv_1_1 100% 22KB
21.5KB/s 00:00
c-820201958-20140806-03 100% 9600KB 9.4MB/s
00:00
2. Create the parameter file and passwrd
file on the server where you want to do cloning:-
[oracle@localhost
~]$ vi /u01/asm/newtspr.ora
--required
entry in the pfile:
db_name=newtspr
db_file_name_convert='/u01/app/oracle/oradata/tspr/','/u01/tspr/'
log_file_name_convert='/u01/app/oracle/oradata/tspr/','/u01/tspr/'
control_files='/u01/tspr/control01.ctl'
SQL>
startup nomount pfile='/u01/asm/newtspr.ora'
ORACLE
instance started.
Total System
Global Area 146472960 bytes
Fixed
Size 1335080 bytes
Variable
Size 92274904 bytes
Database
Buffers 50331648 bytes
Redo
Buffers 2531328 bytes
SQL> exit
Disconnected
from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost
~]$ rman auxiliary /
Recovery
Manager: Release 11.2.0.1.0 - Production on Wed Aug 6 18:33:54 2014
Copyright
(c) 1982, 2009, Oracle and/or its affiliates.
All rights reserved.
connected to
auxiliary database: NEWTSPR (not mounted)
RMAN>
duplicate database to newtspr backup location '/u01/asm' nofilenamecheck;
Starting
Duplicate Db at 06-AUG-14
contents of
Memory Script:
{
sql clone "create spfile from
memory";
}
executing
Memory Script
sql
statement: create spfile from memory
contents of
Memory Script:
{
shutdown clone immediate;
startup clone nomount;
}
executing
Memory Script
Oracle
instance shut down
connected to
auxiliary database (not started)
Oracle
instance started
Total System
Global Area 146472960 bytes
Fixed
Size 1335080 bytes
Variable
Size 92274904 bytes
Database
Buffers 50331648 bytes
Redo
Buffers 2531328 bytes
contents of
Memory Script:
{
sql
clone "alter system set db_name =
''TSPR'' comment=
''Modified by RMAN duplicate''
scope=spfile";
sql clone "alter system set db_unique_name =
''NEWTSPR'' comment=
''Modified by RMAN duplicate''
scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile from '/u01/asm/c-820201958-20140806-03';
alter clone database mount;
}
executing
Memory Script
sql
statement: alter system set db_name
= ''TSPR'' comment= ''Modified by
RMAN duplicate''
scope=spfile
sql
statement: alter system set
db_unique_name = ''NEWTSPR''
comment= ''Modifi
ed by RMAN
duplicate'' scope=spfile
Oracle
instance shut down
Oracle
instance started
Total System
Global Area 146472960 bytes
Fixed
Size 1335080 bytes
Variable
Size 92274904 bytes
Database
Buffers 50331648 bytes
Redo
Buffers 2531328 bytes
Starting
restore at 06-AUG-14
allocated
channel: ORA_AUX_DISK_1
channel
ORA_AUX_DISK_1: SID=18 device type=DISK
channel
ORA_AUX_DISK_1: restoring control file
channel
ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file
name=/u01/tspr/control01.ctl
Finished
restore at 06-AUG-14
database
mounted
released
channel: ORA_AUX_DISK_1
allocated
channel: ORA_AUX_DISK_1
channel
ORA_AUX_DISK_1: SID=18 device type=DISK
contents of
Memory Script:
{
set until scn 815147;
set newname for datafile 1 to
"/u01/tspr/system01.dbf";
set newname for datafile 2 to
"/u01/tspr/sysaux01.dbf";
set newname for datafile 3 to
"/u01/tspr/undotbs01.dbf";
set newname for datafile 4 to
"/u01/tspr/users01.dbf";
set newname for datafile 5 to
"/u01/tspr/example01.dbf";
set newname for datafile 6 to
"/u01/tspr/tbs.dbf";
restore
clone database;
}
executing
Memory Script
executing
command: SET until clause
executing
command: SET NEWNAME
executing
command: SET NEWNAME
executing
command: SET NEWNAME
executing
command: SET NEWNAME
executing
command: SET NEWNAME
executing
command: SET NEWNAME
Starting
restore at 06-AUG-14
using
channel ORA_AUX_DISK_1
channel
ORA_AUX_DISK_1: starting datafile backup set restore
channel
ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel
ORA_AUX_DISK_1: restoring datafile 00001 to /u01/tspr/system01.dbf
channel
ORA_AUX_DISK_1: restoring datafile 00002 to /u01/tspr/sysaux01.dbf
channel
ORA_AUX_DISK_1: restoring datafile 00003 to /u01/tspr/undotbs01.dbf
channel
ORA_AUX_DISK_1: restoring datafile 00004 to /u01/tspr/users01.dbf
channel
ORA_AUX_DISK_1: restoring datafile 00005 to /u01/tspr/example01.dbf
channel
ORA_AUX_DISK_1: restoring datafile 00006 to /u01/tspr/tbs.dbf
channel
ORA_AUX_DISK_1: reading from backup piece /u01/asm/08pf9bgt_1_1
channel
ORA_AUX_DISK_1: piece handle=/u01/asm/08pf9bgt_1_1 tag=TAG20140806T15091
7
channel
ORA_AUX_DISK_1: restored backup piece 1
channel
ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:36
Finished
restore at 06-AUG-14
contents of
Memory Script:
{
switch clone datafile all;
}
executing
Memory Script
datafile 1
switched to datafile copy
input
datafile copy RECID=7 STAMP=854908554 file name=/u01/tspr/system01.dbf
datafile 2
switched to datafile copy
input
datafile copy RECID=8 STAMP=854908554 file name=/u01/tspr/sysaux01.dbf
datafile 3
switched to datafile copy
input
datafile copy RECID=9 STAMP=854908554 file name=/u01/tspr/undotbs01.dbf
datafile 4
switched to datafile copy
input
datafile copy RECID=10 STAMP=854908554 file name=/u01/tspr/users01.dbf
datafile 5
switched to datafile copy
input
datafile copy RECID=11 STAMP=854908554 file name=/u01/tspr/example01.dbf
datafile 6
switched to datafile copy
input
datafile copy RECID=12 STAMP=854908554 file name=/u01/tspr/tbs.dbf
contents of
Memory Script:
{
set until scn 815147;
recover
clone database
delete archivelog;
}
executing
Memory Script
executing
command: SET until clause
Starting
recover at 06-AUG-14
using
channel ORA_AUX_DISK_1
starting
media recovery
channel
ORA_AUX_DISK_1: starting archived log restore to default destination
channel
ORA_AUX_DISK_1: restoring archived log
archived log
thread=1 sequence=13
channel
ORA_AUX_DISK_1: reading from backup piece /u01/asm/09pf9biv_1_1
channel
ORA_AUX_DISK_1: piece handle=/u01/asm/09pf9biv_1_1 tag=TAG20140806T15102
3
channel
ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1:
restore complete, elapsed time: 00:00:01
archived log
file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_854885226.dbf
thread=1 sequence=13
channel
clone_default: deleting archived log(s)
archived log
file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_854885226.dbf
RECID=1 STAMP=854908555
media
recovery complete, elapsed time: 00:00:00
Finished
recover at 06-AUG-14
contents of
Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''NEWTSPR'' comment=
''Reset to original value by RMAN''
scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing
Memory Script
database
dismounted
Oracle
instance shut down
connected to
auxiliary database (not started)
Oracle
instance started
Total System
Global Area 146472960 bytes
Fixed
Size 1335080 bytes
Variable
Size 92274904 bytes
Database
Buffers 50331648 bytes
Redo
Buffers 2531328 bytes
sql
statement: alter system set db_name
= ''NEWTSPR'' comment= ''Reset to
original value by RMAN'' scope=spfile
sql
statement: alter system reset
db_unique_name scope=spfile
Oracle
instance shut down
connected to
auxiliary database (not started)
Oracle
instance started
Total System
Global Area 146472960 bytes
Fixed
Size 1335080 bytes
Variable
Size 92274904 bytes
Database
Buffers 50331648 bytes
Redo
Buffers 2531328 bytes
sql
statement: CREATE CONTROLFILE REUSE SET DATABASE "NEWTSPR" RESETLOGS
ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP
1 ( '/u01/tspr/redo01.log' ) SIZE 50 M
REUSE,
GROUP
2 ( '/u01/tspr/redo02.log' ) SIZE 50 M
REUSE,
GROUP
3 ( '/u01/tspr/redo03.log' ) SIZE 50 M
REUSE
DATAFILE
'/u01/tspr/system01.dbf'
CHARACTER SET WE8MSWIN1252
contents of
Memory Script:
{
set newname for tempfile 1 to
"/u01/tspr/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/tspr/sysaux01.dbf",
"/u01/tspr/undotbs01.dbf",
"/u01/tspr/users01.dbf",
"/u01/tspr/example01.dbf",
"/u01/tspr/tbs.dbf";
switch clone datafile all;
}
executing
Memory Script
executing
command: SET NEWNAME
renamed
tempfile 1 to /u01/tspr/temp01.dbf in control file
cataloged
datafile copy
datafile
copy file name=/u01/tspr/sysaux01.dbf RECID=1 STAMP=854908565
cataloged
datafile copy
datafile
copy file name=/u01/tspr/undotbs01.dbf RECID=2 STAMP=854908565
cataloged
datafile copy
datafile
copy file name=/u01/tspr/users01.dbf RECID=3 STAMP=854908565
cataloged
datafile copy
datafile
copy file name=/u01/tspr/example01.dbf RECID=4 STAMP=854908565
cataloged
datafile copy
datafile
copy file name=/u01/tspr/tbs.dbf RECID=5 STAMP=854908565
datafile 2
switched to datafile copy
input
datafile copy RECID=1 STAMP=854908565 file name=/u01/tspr/sysaux01.dbf
datafile 3
switched to datafile copy
input
datafile copy RECID=2 STAMP=854908565 file name=/u01/tspr/undotbs01.dbf
datafile 4
switched to datafile copy
input
datafile copy RECID=3 STAMP=854908565 file name=/u01/tspr/users01.dbf
datafile 5
switched to datafile copy
input
datafile copy RECID=4 STAMP=854908565 file name=/u01/tspr/example01.dbf
datafile 6
switched to datafile copy
input
datafile copy RECID=5 STAMP=854908565 file name=/u01/tspr/tbs.dbf
contents of
Memory Script:
{
Alter clone database open resetlogs;
}
executing
Memory Script
database
opened
Finished
Duplicate Db at 06-AUG-14
RMAN>
[oracle@localhost
~]$ sqlplus
SQL*Plus:
Release 11.2.0.1.0 Production on Wed Aug 6 18:47:25 2014
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Enter user-name:
sys as sysdba
Enter
password:
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create or replace directory abc as
'/u01/asm';
Directory
created.
SQL>
grant read, write on directory abc to public;
Grant
succeeded.
SQL> conn
Enter
user-name: rudra
Enter
password:
Connected.
SQL>
select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------
------- ----------
DEPT TABLE
EMP TABLE
EMP1 TABLE
LOC TABLE
SQL> exit
Disconnected
from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost
~]$ expdp rudra/rudra directory=abc dumpfile=dpt.dmp logfile=dpt.log
tables=dept
Export:
Release 11.2.0.1.0 - Production on Wed Aug 6 18:50:43 2014
Copyright
(c) 1982, 2009, Oracle and/or its affiliates.
All rights reserved.
Connected
to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-01157: cannot identify/lock
data file 201 - see DBWR trace file
ORA-01110: data file 201:
'/u01/tspr/temp01.dbf'
ORA-06512: at
"SYS.DBMS_LOB", line 664
ORA-06512: at
"SYS.DBMS_DATAPUMP", line 3901
ORA-06512: at line 1
Note:- Need to create the tempfile because rman does not
take the tempfile backup.
[oracle@localhost
~]$ sqlplus
SQL*Plus:
Release 11.2.0.1.0 Production on Wed Aug 6 18:52:45 2014
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Enter
user-name: sys as sysdba
Enter
password:
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
EXAMPLE
TBS
7 rows
selected.
SQL>
alter tablespace temp add tempfile '/u01/tspr/temp02.dbf' size 20m;
Tablespace
altered.
SQL>
alter tablespace temp drop tempfile
'/u01/tspr/temp01.dbf';
Tablespace
altered.
[oracle@localhost
~]$ expdp rudra/rudra directory=abc dumpfile=dpt.dmp logfile=dpt.log
tables=dept
Export:
Release 11.2.0.1.0 - Production on Wed Aug 6 18:54:14 2014
Copyright
(c) 1982, 2009, Oracle and/or its affiliates.
All rights reserved.
Connected
to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
Starting
"RUDRA"."SYS_EXPORT_TABLE_01": rudra/******** directory=abc dumpfile=dpt.dmp
logfile=dpt.log tables=dept
Estimate in
progress using BLOCKS method...
Processing
object type TABLE_EXPORT/TABLE/TABLE_DATA
Total
estimation using BLOCKS method: 64 KB
Processing
object type TABLE_EXPORT/TABLE/TABLE
Processing
object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported
"RUDRA"."DEPT" 5.437 KB 4 rows
Master table
"RUDRA"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file
set for RUDRA.SYS_EXPORT_TABLE_01 is:
/u01/asm/dpt.dmp
Job
"RUDRA"."SYS_EXPORT_TABLE_01" successfully completed at
18:54:28
Copy the dumpfile to the database server :-
[oracle@localhost
~]$ cd /u01/asm/
[oracle@localhost
asm]$ ls
dpt.dmp
dpt.log
[oracle@localhost
asm]$ scp * oracle@192.168.204.129:/u01/tspr
The
authenticity of host '192.168.204.129 (192.168.204.129)' can't be established.
RSA key
fingerprint is cb:57:be:e9:4f:f9:d1:1b:b2:95:8f:ac:f2:d1:05:12.
Are you sure
you want to continue connecting (yes/no)? yes
Warning:
Permanently added '192.168.204.129' (RSA) to the list of known hosts.
Address
192.168.204.129 maps to localhost.localdomain, but this does not map back to
the address - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.204.129's
password:
dpt.dmp 100% 92KB
92.0KB/s 00:00
dpt.log 100% 1058 1.0KB/s
00:00
On the main database server :-
[oracle@localhost
backup]$ cd /u01/tspr/
[oracle@localhost
tspr]$ ls
dpt.dmp dpt.log
[oracle@localhost
tspr]$ sqlplus
SQL*Plus:
Release 11.2.0.1.0 Production on Wed Aug 6 20:43:31 2014
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Enter
user-name: sys as sysdba
Enter
password:
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
create or replace directory abc as '/u01/tspr/';
Directory
created.
SQL>
grant read,write on directory abc to public;
Grant
succeeded.
SQL> conn
Enter
user-name: rudra
Enter
password:
Connected.
SQL>
select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------
------- ----------
DEPT1 TABLE
EMP TABLE
EMP1 TABLE
LOC TABLE
NEERAJ TABLE
SQL>exit
[oracle@localhost
tspr]$ impdp rudra/rudra directory=abc dumpfile=dpt.dmp logfile=dpt_imp.log
tables=dept
Import:
Release 11.2.0.1.0 - Production on Wed Aug 6 20:49:38 2014
Copyright
(c) 1982, 2009, Oracle and/or its affiliates.
All rights reserved.
Connected
to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
Master table
"RUDRA"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting
"RUDRA"."SYS_IMPORT_TABLE_01": rudra/******** directory=abc dumpfile=dpt.dmp
logfile=dpt_imp.log tables=dept
Processing
object type TABLE_EXPORT/TABLE/TABLE
Processing
object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported
"RUDRA"."DEPT" 5.437 KB 4 rows
Processing
object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job
"RUDRA"."SYS_IMPORT_TABLE_01" successfully completed at
20:49:43
[oracle@localhost
tspr]$ sqlplus
SQL*Plus:
Release 11.2.0.1.0 Production on Wed Aug 6 20:50:27 2014
Copyright
(c) 1982, 2009, Oracle. All rights
reserved.
Enter
user-name: rudra
Enter
password:
Connected
to:
Oracle
Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the
Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------
------- ----------
DEPT TABLE
DEPT1 TABLE
EMP TABLE
EMP1 TABLE
LOC TABLE
NEERAJ TABLE
6 rows
selected.
SQL>
select * from dept;
ID
DEPTID
----------
----------
1 10
1 10
2 20
2 20
SQL>
Note:- Since we just restored this table from old backup so we would have to re-populated this table anew to reflect all the changes.
Please share your suggestion and comment on this.
all the best.... :)