Objective is to recover a table using the database and archive log backup with the help of timestamp and backup destination.
Here, As an example we have an database user “pop”. Under the user pop there is a table named “teams”.
Step 1: Connect as user pop and view the table TEAMS
SQL> conn pop/pop
Connected.
SQL> select count(*) from teams;
COUNT(*)
———-
620
Step 2: Take the time for recovery purpose.
SQL> select to_char(sysdate,’dd-mm-yyyy hh24:mi:ss’) “now” from dual;
now
——————-
23-01-2023 23:52:25
Step 3: Make sure archivelog is enabled or else enable archivelog.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
Step 4: Take a full backup of database and archivelog.
[oracle@vijay ~]$ rman target /Recovery Manager: Release 12.2.0.1.0 – Production on Mon Jan 23 23:19:38 2023
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: LUKE (DBID=3178251041)
RMAN> backup database plus archivelog;
Starting backup at 23-JAN-23
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=58 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=1 STAMP=1126912802
channel ORA_DISK_1: starting piece 1 at 23-JAN-23
channel ORA_DISK_1: finished piece 1 at 23-JAN-23
piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_annnn_TAG20230123T232004_kwxl6f13_.bkp tag=TAG20230123T232004 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 23-JAN-23
Starting backup at 23-JAN-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/LUKE/datafile/o1_mf_system_kwonqn0b_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/LUKE/datafile/o1_mf_sysaux_kwonsp0w_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/LUKE/datafile/o1_mf_undotbs1_kwontt1r_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/LUKE/datafile/o1_mf_users_kwontx8x_.dbf
channel ORA_DISK_1: starting piece 1 at 23-JAN-23
channel ORA_DISK_1: finished piece 1 at 23-JAN-23
piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_nnndf_TAG20230123T232008_kwxl6khw_.bkp tag=TAG20230123T232008 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 23-JAN-23
Starting backup at 23-JAN-23
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=2 STAMP=1126912864
channel ORA_DISK_1: starting piece 1 at 23-JAN-23
channel ORA_DISK_1: finished piece 1 at 23-JAN-23
piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_annnn_TAG20230123T232105_kwxl89dg_.bkp tag=TAG20230123T232105 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 23-JAN-23
Starting Control File and SPFILE Autobackup at 23-JAN-23
piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/2023_01_23/o1_mf_s_1126912866_kwxl8d3b_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 23-JAN-23
Step 5: Connect as pop user and drop table teams.
SQL> conn pop/pop
Connected.
SQL> drop table teams;
Table dropped.
SQL> select count(*) from teams;
select count(*) from teams
*
ERROR at line 1:
ORA-00942: table or view does not exist
Step 6: Connect Rman utility recover table pop.teams using timestamp and specifying auxiliary destination.
[oracle@vijay ~]$ rman target /Recovery Manager: Release 12.2.0.1.0 – Production on Tue Jan 24 00:10:45 2023
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: LUKE (DBID=3178251041)
RMAN>recover table pop.teams until time “to_date(’23-01-2023 23:52:25′,’dd-mm-yyyy hh24:mi:ss’)” auxiliary destination ‘/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup’;
Starting recover at 24-JAN-23
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=’FrBl’
initialization parameters used for automatic instance:
db_name=LUKE
db_unique_name=FrBl_pitr_LUKE
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=2304M
processes=200
db_create_file_dest=/u01/app/oracle/fast_recovery_area/luke/LUKE
log_archive_dest_1=’location=/u01/app/oracle/fast_recovery_area/luke/LUKE’
#No auxiliary parameter file used
starting up automatic instance LUKE
Oracle instance started
Total System Global Area 2415919104 bytes
Fixed Size 8623544 bytes
Variable Size 536873544 bytes
Database Buffers 1862270976 bytes
Redo Buffers 8151040 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time “to_date(’23-01-2023 23:06:51′,’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 24-JAN-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 device type=DISK
Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/24/2023 00:02:21
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found – aborting restore
RMAN-06024: no backup or copy of the control file found to restore
Starting recover at 24-JAN-23
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=’Bywj’
initialization parameters used for automatic instance:
db_name=LUKE
db_unique_name=Bywj_pitr_LUKE
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=2304M
processes=200
db_create_file_dest=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup
log_archive_dest_1=’location=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup’
#No auxiliary parameter file used
starting up automatic instance LUKE
Oracle instance started
Total System Global Area 2415919104 bytes
Fixed Size 8623544 bytes
Variable Size 536873544 bytes
Database Buffers 1862270976 bytes
Redo Buffers 8151040 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until time “to_date(’23-01-2023 23:52:25′,’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 24-JAN-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 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/oracle/fast_recovery_area/luke/LUKE/autobackup/2023_01_23/o1_mf_s_1126912866_kwxl8d3b_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/2023_01_23/o1_mf_s_1126912866_kwxl8d3b_.bkp tag=TAG20230123T232106
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/controlfile/o1_mf_kwxnp4yy_.ctl
Finished restore at 24-JAN-23
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(’23-01-2023 23:52:25′,’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 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, 4, 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 /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 24-JAN-23
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/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_nnndf_TAG20230123T232008_kwxl6khw_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_nnndf_TAG20230123T232008_kwxl6khw_.bkp tag=TAG20230123T232008
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 24-JAN-23
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=1126915410 file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_system_kwxnpdpk_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1126915410 file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_undotbs1_kwxnpdqc_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1126915410 file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_sysaux_kwxnpdq0_.dbf
contents of Memory Script:
{
# set requested point in time
set until time “to_date(’23-01-2023 23:52:25′,’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”;
# 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 4 online
sql statement: alter database datafile 3 online
Starting recover at 24-JAN-23
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_3_kwxl88vp_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_4_kwxn41hh_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_3_kwxl88vp_.arc thread=1 sequence=3
archived log file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_4_kwxn41hh_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:04
Finished recover at 24-JAN-23
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 =
”/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/controlfile/o1_mf_kwxnp4yy_.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 2415919104 bytes
Fixed Size 8623544 bytes
Variable Size 536873544 bytes
Database Buffers 1862270976 bytes
Redo Buffers 8151040 bytes
sql statement: alter system set control_files = ”/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/controlfile/o1_mf_kwxnp4yy_.ctl” comment= ”RMAN set” scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 2415919104 bytes
Fixed Size 8623544 bytes
Variable Size 536873544 bytes
Database Buffers 1862270976 bytes
Redo Buffers 8151040 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until time “to_date(’23-01-2023 23:52:25′,’dd-mm-yyyy hh24:mi:ss’)”;
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 7 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 7;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 24-JAN-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 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 00007 to /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_nnndf_TAG20230123T232008_kwxl6khw_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/luke/LUKE/backupset/2023_01_23/o1_mf_nnndf_TAG20230123T232008_kwxl6khw_.bkp tag=TAG20230123T232008
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 24-JAN-23
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=1126915483 file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/datafile/o1_mf_users_kwxnt29q_.dbf
contents of Memory Script:
{
# set requested point in time
set until time “to_date(’23-01-2023 23:52:25′,’dd-mm-yyyy hh24:mi:ss’)”;
# online the datafiles restored or switched
sql clone “alter database datafile 7 online”;
# recover and open resetlogs
recover clone database tablespace “USERS”, “SYSTEM”, “UNDOTBS1”, “SYSAUX” delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 7 online
Starting recover at 24-JAN-23
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_3_kwxl88vp_.arc
archived log for thread 1 with sequence 4 is already on disk as file /u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_4_kwxn41hh_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_3_kwxl88vp_.arc thread=1 sequence=3
archived log file name=/u01/app/oracle/fast_recovery_area/luke/LUKE/archivelog/2023_01_23/o1_mf_1_4_kwxn41hh_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:00
Finished recover at 24-JAN-23
database opened
contents of Memory Script:
{
# create directory for datapump import
sql “create or replace directory TSPITR_DIROBJ_DPDIR as ”
/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup””;
# create directory for datapump export
sql clone “create or replace directory TSPITR_DIROBJ_DPDIR as ”
/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup””;
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup”
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ”/u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup”
Performing export of tables…
EXPDP> Starting “SYS”.”TSPITR_EXP_Bywj_iawy”:
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> . . exported “POP”.”TEAMS” 18.36 KB 620 rows
EXPDP> Master table “SYS”.”TSPITR_EXP_Bywj_iawy” successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_Bywj_iawy is:
EXPDP> /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/tspitr_Bywj_51357.dmp
EXPDP> Job “SYS”.”TSPITR_EXP_Bywj_iawy” successfully completed at Tue Jan 24 00:06:20 2023 elapsed 0 00:00:51
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_Bywj_Errd” successfully loaded/unloaded
IMPDP> Starting “SYS”.”TSPITR_IMP_Bywj_Errd”:
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported “POP”.”TEAMS” 18.36 KB 620 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_Bywj_Errd” successfully completed at Tue Jan 24 00:07:04 2023 elapsed 0 00:00:31
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_temp_kwxnr1rs_.tmp deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/onlinelog/o1_mf_3_kwxnt9yz_.log deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/onlinelog/o1_mf_2_kwxnt569_.log deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/onlinelog/o1_mf_1_kwxnt54f_.log deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/BYWJ_PITR_LUKE/datafile/o1_mf_users_kwxnt29q_.dbf deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_sysaux_kwxnpdq0_.dbf deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_undotbs1_kwxnpdqc_.dbf deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/datafile/o1_mf_system_kwxnpdpk_.dbf deleted
auxiliary instance file /u01/app/oracle/fast_recovery_area/luke/LUKE/autobackup/LUKE/controlfile/o1_mf_kwxnp4yy_.ctl deleted
auxiliary instance file tspitr_Bywj_51357.dmp deleted
Finished recover at 24-JAN-23
….…….
Step 7: Table teams has been recovered.
[oracle@vijay ~]$ sqlplus / as sysdbaSQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 24 00:13:01 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 – 64bit Production
SQL> conn pop/pop
Connected.
SQL> select count(*) from teams;
COUNT(*)
———-
620