One of the new feature in Oracle 12c is the possibility to restore a table with RMAN utility. Pre ORACLE 12c you will do a Tablespace Point In Time Recovery (TPITR) to create a auxiliary database and then export your table from there. In 12c the steps are the same, but you will need a single command for the operation. RMAN will create the auxiliary database and will do the export and import jobs for you. The Prerequisites for this operation are very simple. You need a 12c database in archivelog mode which is read write open.
This Feature is usefull for example:
• If you have purged your table (no Flashback drop)
• No undo data available
• After a structural DDL change
• If only small table is needed for restore
• Works also for Pluggable Databases
High Level Steps:
• RMAN uses backups that were previously created to recover tables and table partitions to a specified point in time. You must simply define a recover command with the following parameter:
– Names of tables or table partitions to be recovered
– Point in time to which the tables or table partitions need to be recovered
– Whether the recovered tables or table partitions must be imported into the target database
• RMAN use the input to recover the table.
• RMAN use the best backup you have.
• RMAN creates an auxiliary instance.
• RMAN recovers your tables or table partitions, up to the specified point in time, into this auxiliary instance.
• RMAN creates a Data Pump export dump file that contains the recovered objects.
• RMAN imports the recovered objects into the target database.
You can use different Point in Time recovery options like SCN, Time or sequence number. You are also able to use a transform parameter for the import like REMAP TABLE or REMAP TABLESPACE.
Step by Step Demo
==============
1.1. Check the database status
Database should be in Archive log mode to perform this activity.
1.2. Create Table and populate data
create table vj.test_table (id number(8),name varchar2(50),now date) tablespace vijay;
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
insert into vj.test_table values (1,'Vijay',sysdate);
insert into vj.test_table values (2,'Alex',sysdate);
insert into vj.test_table values (3,'Rahul',sysdate);
commit;
1.3. Verify populated data in Schema
1.4. Backup the data
1.5. Drop the table and record the SCN
1.6. Create Temporary Work Directory
mkdir D:\app\hcl\product\12.1.0\oradata\DB12C\restore_table
1.8. Verify Table data
Table is Back :)
RMAN Activity Log
=================
……….
diagnostic_dest=D:\APP\HCL
db_create_file_dest=D:\app\hcl\product\12.1.0\restore_db
log_archive_dest_1='location=D:\app\hcl\product\12.1.0\restore_db'
#No auxiliary parameter file used
starting up automatic instance DB12C
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2410864 bytes
Variable Size 293602960 bytes
Database Buffers 767557632 bytes
Redo Buffers 5365760 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until scn 2279609;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET until clause
Starting restore at 14-OCT-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=79 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NCSNF_TAG20131014T173609_95QQMOB3_.BKP
channel ORA_AUX_DISK_1: piece handle=D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NCSNF_TAG20131014T173609_95QQMOB3_.BKP tag=TAG20131014T173
609
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\CONTROLFILE\O1_MF_95QRFCWN_.CTL
Finished restore at 14-OCT-13
sql statement: alter database mount clone database
sql statement: alter system archive log current
contents of Memory Script:
{
# set requested point in time
set until scn 2279609;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 5 to new;
set newname for clone datafile 3 to new;
set newname for clone tempfile 1 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 5, 3;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_TEMP_%U_.TMP in control file
Starting restore at 14-OCT-13
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 D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSTEM_%U_.DBF
channel ORA_AUX_DISK_1: restoring datafile 00005 to D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_UNDOTBS1_%U_.DBF
channel ORA_AUX_DISK_1: restoring datafile 00003 to D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSAUX_%U_.DBF
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NNNDF_TAG20131014T173609_95QQKM4N_.BKP
channel ORA_AUX_DISK_1: piece handle=D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NNNDF_TAG20131014T173609_95QQKM4N_.BKP tag=TAG20131014T173
609
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
Finished restore at 14-OCT-13
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=828813133 file name=D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSTEM_95QRFN0W_.DBF
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=828813133 file name=D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_UNDOTBS1_95QRFN3B_.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=828813133 file name=D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSAUX_95QRFN49_.DBF
contents of Memory Script:
{
# set requested point in time
set until scn 2279609;
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 5 online";
sql clone "alter database datafile 3 online";
# recover and open database read only
recover clone database tablespace "SYSTEM", "UNDOTBS1", "SYSAUX";
sql clone 'alter database open read only';
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 5 online
sql statement: alter database datafile 3 online
Starting recover at 14-OCT-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 8 is already on disk as file D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\ARCHIVELOG\2013_10_14\O1_MF_1_8_95QQXW20_.ARC
archived log file name=D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\ARCHIVELOG\2013_10_14\O1_MF_1_8_95QQXW20_.ARC thread=1 sequence=8
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-OCT-13
sql statement: alter database open read only
contents of Memory Script:
{
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\CONTROLFILE\O1_MF_95QRFCWN_.CTL'' comment=
''RMAN set'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
# mount database
sql clone 'alter database mount clone database';
}
executing Memory Script
sql statement: create spfile from memory
database closed
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2410864 bytes
Variable Size 297797264 bytes
Database Buffers 763363328 bytes
Redo Buffers 5365760 bytes
sql statement: alter system set control_files = ''D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\CONTROLFILE\O1_MF_95QRFCWN_.CTL'' comment= ''RMAN set'' scope=spfi
le
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2410864 bytes
Variable Size 297797264 bytes
Database Buffers 763363328 bytes
Redo Buffers 5365760 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until scn 2279609;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 2 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 2;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 14-OCT-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=78 device type=DISK
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 00002 to D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\DATAFILE\O1_MF_VIJAY_%U_.DBF
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NNNDF_TAG20131014T173609_95QQKM4N_.BKP
channel ORA_AUX_DISK_1: piece handle=D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\BACKUPSET\2013_10_14\O1_MF_NNNDF_TAG20131014T173609_95QQKM4N_.BKP tag=TAG20131014T173
609
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 14-OCT-13
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=828813303 file name=D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\DATAFILE\O1_MF_VIJAY_95QRNRMQ_.DBF
contents of Memory Script:
{
# set requested point in time
set until scn 2279609;
# online the datafiles restored or switched
sql clone "alter database datafile 2 online";
# recover and open resetlogs
recover clone database tablespace "VIJAY", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 2 online
Starting recover at 14-OCT-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 8 is already on disk as file D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\ARCHIVELOG\2013_10_14\O1_MF_1_8_95QQXW20_.ARC
archived log file name=D:\APP\HCL\PRODUCT\12.1.0\ORADATA\DB12C\ARCHIVELOG\2013_10_14\O1_MF_1_8_95QQXW20_.ARC thread=1 sequence=8
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-OCT-13
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
D:\app\hcl\product\12.1.0\restore_db''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
D:\app\hcl\product\12.1.0\restore_db''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''D:\app\hcl\product\12.1.0\restore_db''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''D:\app\hcl\product\12.1.0\restore_db''
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_aEEv_nqbo":
EXPDP> Estimate in progress using BLOCKS method...
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Total estimation using BLOCKS method: 64 KB
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> . . exported "VJ"."TEST_TABLE" 6.273 KB 18 rows
EXPDP> Master table "SYS"."TSPITR_EXP_aEEv_nqbo" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_aEEv_nqbo is:
EXPDP> D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\TSPITR_AEEV_98633.DMP
EXPDP> Job "SYS"."TSPITR_EXP_aEEv_nqbo" successfully completed at Mon Oct 14 17:56:30 2013 elapsed 0 00:00:24
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script
Oracle instance shut down
Performing import of tables...
IMPDP> Master table "SYS"."TSPITR_IMP_aEEv_mggp" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_aEEv_mggp":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "VJ"."TEST_TABLE" 6.273 KB 18 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
IMPDP> Job "SYS"."TSPITR_IMP_aEEv_mggp" successfully completed at Mon Oct 14 17:57:13 2013 elapsed 0 00:00:25
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_TEMP_95QRHXN5_.TMP deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\ONLINELOG\O1_MF_3_95QROLTP_.LOG deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\ONLINELOG\O1_MF_2_95QROJW8_.LOG deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\ONLINELOG\O1_MF_1_95QROGYS_.LOG deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\AEEV_PITR_DB12C\DATAFILE\O1_MF_VIJAY_95QRNRMQ_.DBF deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSAUX_95QRFN49_.DBF deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_UNDOTBS1_95QRFN3B_.DBF deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\DATAFILE\O1_MF_SYSTEM_95QRFN0W_.DBF deleted
auxiliary instance file D:\APP\HCL\PRODUCT\12.1.0\RESTORE_DB\DB12C\CONTROLFILE\O1_MF_95QRFCWN_.CTL deleted
auxiliary instance file tspitr_aEEv_98633.dmp deleted
Finished recover at 14-OCT-13
RMAN>
Table is Back . Verified in Section 1.8
No comments:
Post a Comment