RMAN: Dropped Table Recovery

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
In this post I am going to demonstrate the table recovery using RMAN. There are chances to drop tables accidentally by developer. In this cases DBA asked to recovery the dropped table from the backup.
Make sure you mention the table name in capital letter with in quote. In this demo I used 'TEST'.'SALARYGRADE'. 

RMAN command
run
{
RECOVER TABLE 'TEST'.'SALARYGRADE'
until time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh:mi:ss')" 
AUXILIARY DESTINATION '/u02/oradata/CDB/auxilary/'  ;
}

Demo Taking the backup of the database. You can use the latest backup before the table drop.
[oracle@TESTBOX ~]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Wed Jul 15 00:40:19 2020
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CDB (DBID=2318676857)

RMAN> backup database plus archivelog;


Starting backup at 15-JUL-20
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=459 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=21 RECID=1 STAMP=1045788048
channel ORA_DISK_1: starting piece 1 at 15-JUL-20
channel ORA_DISK_1: finished piece 1 at 15-JUL-20
piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/4ev5atci_1_1 tag=TAG20200715T004050 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-JUL-20

Starting backup at 15-JUL-20
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=00005 name=/u02/oradata/CDB/user_data01.dbf
input datafile file number=00001 name=/u02/oradata/CDB/system01.dbf
input datafile file number=00003 name=/u02/oradata/CDB/sysaux01.dbf
input datafile file number=00004 name=/u02/oradata/CDB/undotbs01.dbf
input datafile file number=00007 name=/u02/oradata/CDB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 15-JUL-20
channel ORA_DISK_1: finished piece 1 at 15-JUL-20
piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/4fv5atck_1_1 tag=TAG20200715T004051 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 15-JUL-20

Starting backup at 15-JUL-20
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=22 RECID=2 STAMP=1045788067
channel ORA_DISK_1: starting piece 1 at 15-JUL-20
channel ORA_DISK_1: finished piece 1 at 15-JUL-20
piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/4gv5atd4_1_1 tag=TAG20200715T004107 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-JUL-20

Starting Control File and SPFILE Autobackup at 15-JUL-20
piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/c-2318676857-20200715-00 comment=NONE
Finished Control File and SPFILE Autobackup at 15-JUL-20

Drop the table salarygrade from the test user

SQL> select to_char(sysdate,'dd/mm/yyyy hh:mi:ss') from dual;

TO_CHAR(SYSDATE,'DD
-------------------
15/07/2020 03:31:29

SQL> drop table test.salarygrade;

Table dropped.

Recovery of the table using RMAN.


RMAN> 

RMAN> run
{
RECOVER TABLE 'TEST'.'SALARYGRADE'
until time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh:mi:ss')" 
AUXILIARY DESTINATION '/u02/oradata/CDB/auxilary/'  ;
} 

Starting recover at 15-JUL-20
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='iiFb'

initialization parameters used for automatic instance:
db_name=CDB
db_unique_name=iiFb_pitr_CDB
compatible=19.0.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=800M
processes=200
db_create_file_dest=/u02/oradata/CDB/auxilary/
log_archive_dest_1='location=/u02/oradata/CDB/auxilary/'
#No auxiliary parameter file used


starting up automatic instance CDB

Oracle instance started

Total System Global Area     838858176 bytes

Fixed Size                     8902080 bytes
Variable Size                226492416 bytes
Database Buffers             599785472 bytes
Redo Buffers                   3678208 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh: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 15-JUL-20
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/product/19.0.0/dbhome_1/dbs/c-2318676857-20200715-04
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/c-2318676857-20200715-04 tag=TAG20200715T030752
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u02/oradata/CDB/auxilary/CDB/controlfile/o1_mf_hjxdhfn3_.ctl
Finished restore at 15-JUL-20

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('15-07-2020 03:25:00','dd-mm-yyyy hh: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 /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 15-JUL-20
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 /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/19.0.0/dbhome_1/dbs/4vv5b5vn_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/4vv5b5vn_1_1 tag=TAG20200715T030734
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 15-JUL-20

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=1045798597 file name=/u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_system_hjxdhpdv_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1045798597 file name=/u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_undotbs1_hjxdhpf5_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1045798597 file name=/u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_sysaux_hjxdhpf3_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh: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 15-JUL-20
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 54 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_54_1020567933.dbf
archived log for thread 1 with sequence 55 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_55_1020567933.dbf
archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_54_1020567933.dbf thread=1 sequence=54
archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_55_1020567933.dbf thread=1 sequence=55
media recovery complete, elapsed time: 00:00:00
Finished recover at 15-JUL-20

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 = 
  ''/u02/oradata/CDB/auxilary/CDB/controlfile/o1_mf_hjxdhfn3_.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     838858176 bytes

Fixed Size                     8902080 bytes
Variable Size                226492416 bytes
Database Buffers             599785472 bytes
Redo Buffers                   3678208 bytes

sql statement: alter system set  control_files =   ''/u02/oradata/CDB/auxilary/CDB/controlfile/o1_mf_hjxdhfn3_.ctl'' comment= ''RMAN set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     838858176 bytes

Fixed Size                     8902080 bytes
Variable Size                226492416 bytes
Database Buffers             599785472 bytes
Redo Buffers                   3678208 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh: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 15-JUL-20
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 /u02/oradata/CDB/auxilary/IIFB_PITR_CDB/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/19.0.0/dbhome_1/dbs/4vv5b5vn_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/4vv5b5vn_1_1 tag=TAG20200715T030734
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 15-JUL-20

datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=1045798675 file name=/u02/oradata/CDB/auxilary/IIFB_PITR_CDB/datafile/o1_mf_users_hjxdllo7_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('15-07-2020 03:25:00','dd-mm-yyyy hh: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 15-JUL-20
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 54 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_54_1020567933.dbf
archived log for thread 1 with sequence 55 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_55_1020567933.dbf
archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_54_1020567933.dbf thread=1 sequence=54
archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch/1_55_1020567933.dbf thread=1 sequence=55
media recovery complete, elapsed time: 00:00:00
Finished recover at 15-JUL-20

database opened

contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u02/oradata/CDB/auxilary/''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u02/oradata/CDB/auxilary/''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u02/oradata/CDB/auxilary/''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u02/oradata/CDB/auxilary/''

Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_iiFb_hafw":  
   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 "TEST"."SALARYGRADE"                        6.101 KB       5 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_iiFb_hafw" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_iiFb_hafw is:
   EXPDP>   /u02/oradata/CDB/auxilary/tspitr_iiFb_90778.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_iiFb_hafw" successfully completed at Wed Jul 15 03:39:25 2020 elapsed 0 00:01:04
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_iiFb_hvhD" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_iiFb_hvhD":  
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "TEST"."SALARYGRADE"                        6.101 KB       5 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_iiFb_hvhD" successfully completed at Wed Jul 15 03:40:41 2020 elapsed 0 00:01:01
Import completed


Removing automatic instance
Automatic instance removed
auxiliary instance file /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_temp_hjxdj9d2_.tmp deleted
auxiliary instance file /u02/oradata/CDB/auxilary/IIFB_PITR_CDB/onlinelog/o1_mf_3_hjxdls1v_.log deleted
auxiliary instance file /u02/oradata/CDB/auxilary/IIFB_PITR_CDB/onlinelog/o1_mf_2_hjxdlphl_.log deleted
auxiliary instance file /u02/oradata/CDB/auxilary/IIFB_PITR_CDB/onlinelog/o1_mf_1_hjxdlpd8_.log deleted
auxiliary instance file /u02/oradata/CDB/auxilary/IIFB_PITR_CDB/datafile/o1_mf_users_hjxdllo7_.dbf deleted
auxiliary instance file /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_sysaux_hjxdhpf3_.dbf deleted
auxiliary instance file /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_undotbs1_hjxdhpf5_.dbf deleted
auxiliary instance file /u02/oradata/CDB/auxilary/CDB/datafile/o1_mf_system_hjxdhpdv_.dbf deleted
auxiliary instance file /u02/oradata/CDB/auxilary/CDB/controlfile/o1_mf_hjxdhfn3_.ctl deleted
auxiliary instance file tspitr_iiFb_90778.dmp deleted
Finished recover at 15-JUL-20

RMAN>

After recovery


SQL> select count(*) from test.salarygrade;

  COUNT(*)
----------
	 5

_____________________________________________________________________________________________________________________

0 comments:

Post a comment

 

acehints.com Copyright 2011-20 All Rights Reserved | Site Map | Contact | Disclaimer