Tuesday, 13 October 2015

(PITTR) Point in Time Tablespace recovery in PDB

(PITTR) Point in Time Tablespace recovery in PDB



Eg.
--

SQL> conn manzoor/ahamed@hr_seccdb
Connected.

SQL> select count(*) from emp;

  COUNT(*)
----------
      3000

SQL>
SQL>
SQL> select current_scn from V$database;

CURRENT_SCN
-----------
    3741311

SQL> delete from emp;

3000 rows deleted.

SQL> commit;

Commit complete.


--- User deleted the table without where clause. We need to go back to the scn
3741311 for that particular tablespace.



RMAN> run
 {
recover tablespace hrdepts:MANZOOR
until scn 3741311
auxiliary destination='/oracle/auxiliary_dest';
 }
2> 3> 4> 5> 6>
Starting recover at 25-AUG-15
using channel ORA_DISK_1
using channel ORA_DISK_2
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='gCov'

initialization parameters used for automatic instance:
db_name=SEC_CDB
db_unique_name=gCov_pitr_hrdepts_SEC_CDB
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oraInventory
_system_trig_enabled=FALSE
sga_target=628M
processes=200
db_create_file_dest=/oracle/auxiliary_dest
log_archive_dest_1='location=/oracle/auxiliary_dest'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance SEC_CDB

Oracle instance started

Total System Global Area     658505728 bytes

Fixed Size                     2927864 bytes
Variable Size                188744456 bytes
Database Buffers             461373440 bytes
Redo Buffers                   5459968 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

contents of Memory Script:
{
# set requested point in time
set until  scn 3741311;
# 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';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 25-AUG-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=22 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=23 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/app/oraInventory/fast_recovery_area/SEC_CDB/autobackup/2015_08_25/o1_mf_s_888665139_bxqr1nj4_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/autobackup/2015_08_25/o1_mf_s_888665139_bxqr1nj4_.bkp tag=TAG20150825T112539
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/oracle/auxiliary_dest/SEC_CDB/controlfile/o1_mf_bxqsww4y_.ctl
Finished restore at 25-AUG-15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until  scn 3741311;
# 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;
set newname for datafile  12 to
 "/oracle/product/oradata/sec_cdb/hrdept/manzoor01.dbf";
# 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, 12;

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

executing command: SET NEWNAME

renamed tempfile 1 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 25-AUG-15
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2

skipping datafile 12; already restored to file /oracle/product/oradata/sec_cdb/hrdept/manzoor01.dbf
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 00003 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/bkp_seccdb/bkp_cold_1hqfe1gp_1_1_20150824
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00001 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_2: restoring datafile 00004 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /oracle/bkp_seccdb/bkp_cold_1gqfe1go_1_1_20150824
channel ORA_AUX_DISK_1: piece handle=/oracle/bkp_seccdb/bkp_cold_1hqfe1gp_1_1_20150824 tag=TAG20150824T182943
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:46
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 00009 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/bkp_seccdb/bkp_cold_1iqfe1la_1_1_20150824
channel ORA_AUX_DISK_2: piece handle=/oracle/bkp_seccdb/bkp_cold_1gqfe1go_1_1_20150824 tag=TAG20150824T182943
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:05:02
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00008 to /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /oracle/bkp_seccdb/bkp_cold_1kqfe1ql_1_1_20150824
channel ORA_AUX_DISK_1: piece handle=/oracle/bkp_seccdb/bkp_cold_1iqfe1la_1_1_20150824 tag=TAG20150824T182943
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:03:31
channel ORA_AUX_DISK_2: piece handle=/oracle/bkp_seccdb/bkp_cold_1kqfe1ql_1_1_20150824 tag=TAG20150824T182943
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:01:15
Finished restore at 25-AUG-15

datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=888667425 file name=/oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_bxqsx7sv_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=888667425 file name=/oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_undotbs1_bxqsx82r_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=888667426 file name=/oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_bxqsx7qf_.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=11 STAMP=888667426 file name=/oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_bxqt6omn_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=12 STAMP=888667426 file name=/oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_bxqt2ft0_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 3741311;
# 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 'HRDEPTS' "alter database datafile
 8 online";
sql clone 'HRDEPTS' "alter database datafile
 9 online";
sql clone 'HRDEPTS' "alter database datafile
 12 online";
# recover and open resetlogs
recover clone database tablespace  "HRDEPTS":"MANZOOR", "SYSTEM", "UNDOTBS1", "SYSAUX", "HRDEPTS":"SYSTEM", "HRDEPTS":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
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

sql statement: alter database datafile  12 online

Starting recover at 25-AUG-15
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
channel ORA_AUX_DISK_1: starting incremental datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00008: /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_bxqt6omn_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/bkp_seccdb/pdb_inc_0_1rqffq3r_1_1_20150825.bkp
channel ORA_AUX_DISK_2: starting incremental datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
destination for restore of datafile 00009: /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_bxqt2ft0_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /oracle/bkp_seccdb/pdb_inc_0_1qqffq3r_1_1_20150825.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/bkp_seccdb/pdb_inc_0_1rqffq3r_1_1_20150825.bkp tag=TAG20150825T103538
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_2: piece handle=/oracle/bkp_seccdb/pdb_inc_0_1qqffq3r_1_1_20150825.bkp tag=TAG20150825T103538
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:01

starting media recovery

archived log for thread 1 with sequence 56 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_24/o1_mf_1_56_bxoyczw7_.arc
archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_1_bxqd78ff_.arc
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_2_bxqdc248_.arc
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_3_bxqdc2z5_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_4_bxqdc694_.arc
archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_1_bxqkcj1m_.arc
archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_2_bxqlfhnt_.arc
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_3_bxqoz2wm_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_4_bxqpl34g_.arc
archived log for thread 1 with sequence 5 is already on disk as file /u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_5_bxqs5nrs_.arc
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_1_bxqd78ff_.arc thread=1 sequence=1
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_2_bxqdc248_.arc thread=1 sequence=2
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_3_bxqdc2z5_.arc thread=1 sequence=3
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_4_bxqdc694_.arc thread=1 sequence=4
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_1_bxqkcj1m_.arc thread=1 sequence=1
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_2_bxqlfhnt_.arc thread=1 sequence=2
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_3_bxqoz2wm_.arc thread=1 sequence=3
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_4_bxqpl34g_.arc thread=1 sequence=4
archived log file name=/u01/app/oraInventory/fast_recovery_area/SEC_CDB/archivelog/2015_08_25/o1_mf_1_5_bxqs5nrs_.arc thread=1 sequence=5
media recovery complete, elapsed time: 00:00:19
Finished recover at 25-AUG-15

database opened

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

sql statement: alter pluggable database  HRDEPTS open

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'HRDEPTS' 'alter tablespace
 MANZOOR read only';
# create directory for datapump import
sql 'HRDEPTS' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/oracle/auxiliary_dest''";
# create directory for datapump export
sql clone 'HRDEPTS' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/oracle/auxiliary_dest''";
}
executing Memory Script

sql statement: alter tablespace  MANZOOR read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/auxiliary_dest''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/auxiliary_dest''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_gCov_pzwh":
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_gCov_pzwh" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_gCov_pzwh is:
   EXPDP>   /oracle/auxiliary_dest/tspitr_gCov_15845.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace MANZOOR:
   EXPDP>   /oracle/product/oradata/sec_cdb/hrdept/manzoor01.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_gCov_pzwh" successfully completed at Tue Aug 25 12:09:37 2015 elapsed 0 00:03:13
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
# drop target tablespaces before importing them back
sql 'HRDEPTS' 'drop tablespace
 MANZOOR including contents keep datafiles cascade constraints';
}
executing Memory Script

Oracle instance shut down

sql statement: drop tablespace  MANZOOR including contents keep datafiles cascade constraints

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_gCov_CugD" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_gCov_CugD":
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_gCov_CugD" successfully completed at Tue Aug 25 12:11:14 2015 elapsed 0 00:00:23
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'HRDEPTS' 'alter tablespace
 MANZOOR read write';
sql 'HRDEPTS' 'alter tablespace
 MANZOOR offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace  MANZOOR read write

sql statement: alter tablespace  MANZOOR offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_temp_bxqtbgsy_.tmp deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_temp_bxqtb4ob_.tmp deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/onlinelog/o1_mf_3_bxqtb0jp_.log deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/onlinelog/o1_mf_2_bxqt9y9k_.log deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/onlinelog/o1_mf_1_bxqt9wt0_.log deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_bxqt2ft0_.dbf deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_bxqt6omn_.dbf deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_sysaux_bxqsx7qf_.dbf deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_undotbs1_bxqsx82r_.dbf deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/datafile/o1_mf_system_bxqsx7sv_.dbf deleted
auxiliary instance file /oracle/auxiliary_dest/SEC_CDB/controlfile/o1_mf_bxqsww4y_.ctl deleted
auxiliary instance file tspitr_gCov_15845.dmp deleted
Finished recover at 25-AUG-15

RMAN> sql 'HRDEPTS' 'alter tablespace manzoor online';

sql statement: alter tablespace manzoor online



SQL> alter session set container=hrdepts;

Session altered.

SQL> select count(*) from manzoor.emp;

  COUNT(*)
----------
      3000




From the above we could see that.

1) An new auxiliary cdb instance is created.
2) CDB datafiles are stored in the auxiliary destination.
3) PDB tablespace manzoor is restored in the actual location.
4) Recover is done until the specified scn.
5) TTS export and import done.
6) Tablespace is made online.

No comments:

Post a Comment