Saturday, 5 October 2013

RMAN Table recovery in 12c

Pre-12c restoring a table was a long and difficult task. But Oracle 12c introduced new feature to restore a single table or a single partition of a partitioned table from an RMAN backup via the RECOVER TABLE command.


Here is what RMAN RECOVER TABLE command does:


It creates an auxiliary instance to recover the tables to a specific point in time. This contains a few system related data files like SYSTEM, SYSAUX, UNDO  and  data files belonging to the tablespace containing the tables we are looking to restore.

In this example it restores SYSTEM,SYSAUX,UNDO tablespaces for CDB and SYSTEM and SYSAUX and tablespace for PDB

Then it creates a Data Pump export dump file which contains the recovered table or partitions of tables.

It then imports the data into the target database using Data Pump Import.

Finally it removes the temporary auxiliary instance.

Test case:

RMAN> recover table "TEST".testtab of pluggable database ggat_b until time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')" auxiliary destination '/usr/orasys/tmp' datapump destination '/usr/orasys/tmp' dump file 'test_dump';

Starting recover at 07-07-2013 00:57:29
current log archived
using channel ORA_DISK_1
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='jxaF'

initialization parameters used for automatic instance:
db_name=GGAT
db_unique_name=jxaF_pitr_ggat_b_GGAT
compatible=12.1.0.0.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
diagnostic_dest=/home/oracle/obase
db_create_file_dest=/usr/orasys/tmp
log_archive_dest_1='location=/usr/orasys/tmp'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance GGAT

Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2296576 bytes
Variable Size                281019648 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5480448 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')";
# 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 07-07-2013 01:04:17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 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 /u01/fast_recovery_area/GGAT/autobackup/2013_07_07/o1_mf_s_820111472_8xkwkmht_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fast_recovery_area/GGAT/autobackup/2013_07_07/o1_mf_s_820111472_8xkwkmht_.bkp tag=TAG20130707T004432
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:17
output file name=/usr/orasys/tmp/GGAT/controlfile/o1_mf_8xkxpzd7_.ctl
Finished restore at 07-07-2013 01:04:44

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  time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  4 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  8 to new;
set newname for clone datafile  9 to new;
set newname for clone tempfile  1 to new;
set newname for clone tempfile  3 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3, 8, 9;
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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /usr/orasys/tmp/GGAT/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /usr/orasys/tmp/GGAT/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 07-07-2013 01:05:33
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 /usr/orasys/tmp/GGAT/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /usr/orasys/tmp/GGAT/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/fast_recovery_area/GGAT/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T000740_8xktdkd0_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fast_recovery_area/GGAT/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T000740_8xktdkd0_.bkp tag=TAG20130707T000740
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:05:35
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 00008 to /usr/orasys/tmp/GGAT/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/fast_recovery_area/GGAT/E0244CFA2D3524FEE0433D01A8C05266/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T004146_8xkwdck8_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fast_recovery_area/GGAT/E0244CFA2D3524FEE0433D01A8C05266/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T004146_8xkwdck8_.bkp tag=TAG20130707T004146
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:35
Finished restore at 07-07-2013 01:12:44

datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=820113165 file name=/usr/orasys/tmp/GGAT/datafile/o1_mf_system_8xkxryld_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=820113165 file name=/usr/orasys/tmp/GGAT/datafile/o1_mf_undotbs1_8xkxryr4_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=820113165 file name=/usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_8xkxryqz_.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=11 STAMP=820113165 file name=/usr/orasys/tmp/GGAT/datafile/o1_mf_system_8xky3fv4_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=12 STAMP=820113165 file name=/usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_8xky3fql_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  4 online";
sql clone "alter database datafile  3 online";
sql clone 'GGAT_B' "alter database datafile
 8 online";
sql clone 'GGAT_B' "alter database datafile
 9 online";
# recover and open database read only
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX", "GGAT_B":"SYSTEM", "GGAT_B":"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  4 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  8 online

sql statement: alter database datafile  9 online

Starting recover at 07-07-2013 01:12:46
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 24 is already on disk as file /u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_24_8xktjtgd_.arc
archived log for thread 1 with sequence 25 is already on disk as file /u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_25_8xkttyqj_.arc
archived log for thread 1 with sequence 26 is already on disk as file /u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_26_8xkx9v9y_.arc
archived log file name=/u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_24_8xktjtgd_.arc thread=1 sequence=24
archived log file name=/u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_25_8xkttyqj_.arc thread=1 sequence=25
archived log file name=/u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_26_8xkx9v9y_.arc thread=1 sequence=26
media recovery complete, elapsed time: 00:00:24
Finished recover at 07-07-2013 01:13:15

sql statement: alter database open read only

contents of Memory Script:
{
sql clone 'alter pluggable database  GGAT_B open read only';
}
executing Memory Script

sql statement: alter pluggable database  GGAT_B 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 =
  ''/usr/orasys/tmp/GGAT/controlfile/o1_mf_8xkxpzd7_.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                     2296576 bytes
Variable Size                285213952 bytes
Database Buffers             775946240 bytes
Redo Buffers                   5480448 bytes

sql statement: alter system set  control_files =   ''/usr/orasys/tmp/GGAT/controlfile/o1_mf_8xkxpzd7_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2296576 bytes
Variable Size                285213952 bytes
Database Buffers             775946240 bytes
Redo Buffers                   5480448 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  10 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  10;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 07-07-2013 01:20:35
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=11 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 00010 to /usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/fast_recovery_area/GGAT/E0244CFA2D3524FEE0433D01A8C05266/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T004146_8xkwdck8_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/fast_recovery_area/GGAT/E0244CFA2D3524FEE0433D01A8C05266/backupset/2013_07_07/o1_mf_nnndf_TAG20130707T004146_8xkwdck8_.bkp tag=TAG20130707T004146
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 07-07-2013 01:20:43

datafile 10 switched to datafile copy
input datafile copy RECID=14 STAMP=820113643 file name=/usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/datafile/o1_mf_users_8xkyo8rq_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('07-07-2013 00:50:00', 'dd-mm-yyyy hh24:mi:ss')";
# online the datafiles restored or switched
sql clone 'GGAT_B' "alter database datafile
 10 online";
# recover and open resetlogs
recover clone database tablespace  "GGAT_B":"USERS", "SYSTEM", "UNDOTBS1", "SYSAUX", "GGAT_B":"SYSTEM", "GGAT_B":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  10 online

Starting recover at 07-07-2013 01:20:44
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 26 is already on disk as file /u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_26_8xkx9v9y_.arc
archived log file name=/u01/fast_recovery_area/GGAT/archivelog/2013_07_07/o1_mf_1_26_8xkx9v9y_.arc thread=1 sequence=26
media recovery complete, elapsed time: 00:00:01
Finished recover at 07-07-2013 01:20:50

database opened

contents of Memory Script:
{
sql clone 'alter pluggable database  GGAT_B open';
}
executing Memory Script

sql statement: alter pluggable database  GGAT_B open

contents of Memory Script:
{
# create directory for datapump import
sql 'GGAT_B' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/usr/orasys/tmp''";
# create directory for datapump export
sql clone 'GGAT_B' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/usr/orasys/tmp''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/usr/orasys/tmp''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/usr/orasys/tmp''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_jxaF_CBnt": 
   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 "TEST"."TESTTAB"                            5.039 KB       2 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_jxaF_CBnt" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_jxaF_CBnt is:
   EXPDP>   /usr/orasys/tmp/test_dump.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_jxaF_CBnt" successfully completed at Sun Jul 7 01:26:52 2013 elapsed 0 00:02:27
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_jxaF_Fjhj" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_jxaF_Fjhj": 
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "TEST"."TESTTAB"                            5.039 KB       2 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_jxaF_Fjhj" successfully completed at Sun Jul 7 01:29:14 2013 elapsed 0 00:00:54
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_temp_8xky88ho_.tmp deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_temp_8xky7gjk_.tmp deleted
auxiliary instance file /usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/onlinelog/o1_mf_3_8xkyord7_.log deleted
auxiliary instance file /usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/onlinelog/o1_mf_2_8xkyoomq_.log deleted
auxiliary instance file /usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/onlinelog/o1_mf_1_8xkyolpm_.log deleted
auxiliary instance file /usr/orasys/tmp/JXAF_PITR_GGAT_B_GGAT/datafile/o1_mf_users_8xkyo8rq_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_8xky3fql_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_system_8xky3fv4_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_sysaux_8xkxryqz_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_undotbs1_8xkxryr4_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/datafile/o1_mf_system_8xkxryld_.dbf deleted
auxiliary instance file /usr/orasys/tmp/GGAT/controlfile/o1_mf_8xkxpzd7_.ctl deleted
auxiliary instance file /usr/orasys/tmp/test_dump.dmp deleted

Finished recover at 07-07-2013 01:29:35

RMAN>