Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

Table Recovery using RMAN in oracle 12C

$
0
0
Step 1:

Login as sysdba:
Sqlplus ‘/as sysdba’
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing  options

The Table is created on 23rd Jan 2018
Here we taken every day 9pm database full backup.



SQL> select count(*) from sam.kk;

COUNT(*)
--------
100000

Step 2:
 
Check the Current Date and Time:
-----------------------------------------
SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW" FROM DUAL;

    NOW
-------------------
01-24-2018 20:12:50

Step 3:



DROP A TABLE:
-------------
SQL> drop table sam.kk purge;
Table dropped.

Note :
In this Scenario We can Easily Recover the dropped table using RMAN.


Table owner name : sam
Table name            : kk

Step 4:

RMAN STEPS:
-------------------

oracle@irfan# rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Mon Jan 24 20:15:39 2018

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

connected to target database: IRFAN (DBID=3751496384)


RMAN>recover table sam.kk until time "to_date('2018-01-22 23:12:50','yyyy-mm-dd:hh24:mi:ss')" auxiliary destination '/u01/bkp';

Starting recover at 23-JAN-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
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='FCmz'

initialization parameters used for automatic instance:
db_name=DOYEN
db_unique_name=FCmz_pitr_DOYEN
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle/product/12.1.0
_system_trig_enabled=FALSE
sga_target=796M
processes=200
db_create_file_dest=/u01/bkp
log_archive_dest_1='location=/u01/bkp'
#No auxiliary parameter file used
starting up automatic instance DOYEN
Oracle instance started
Total System Global Area     834666496 bytes
Fixed Size                     2929888 bytes
Variable Size                226495264 bytes
Database Buffers             599785472 bytes
Redo Buffers                   5455872 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2018-01-23 23:12:50','yyyy-mm-dd: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 23-JAN-18
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/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/autobackup/2018_01_23/o1_mf_s_966204964_f6gspdjd_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/autobackup/2018_01_23/o1_mf_s_966204964_f6gspdjd_.bkp tag=TAG20180123T221604
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/bkp/DOYEN/controlfile/o1_mf_f6gx9hrp_.ctl
Finished restore at 23-JAN-18
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('2018-01-23 23:12:50','yyyy-mm-dd: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/bkp/DOYEN/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 23-JAN-18
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/bkp/DOYEN/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/bkp/DOYEN/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/bkp/DOYEN/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/backupset/2018_01_23/o1_mf_nnndf_TAG20180123T221517_f6gsnxws_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/backupset/2018_01_23/o1_mf_nnndf_TAG20180123T221517_f6gsnxws_.bkp tag=TAG20180123T221517
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 23-JAN-18
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=966208688 file name=/u01/bkp/DOYEN/datafile/o1_mf_system_f6gx9ons_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=966208688 file name=/u01/bkp/DOYEN/datafile/o1_mf_undotbs1_f6gx9oo3_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=966208688 file name=/u01/bkp/DOYEN/datafile/o1_mf_sysaux_f6gx9onz_.dbf
contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2018-01-23 23:12:50','yyyy-mm-dd: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 23-JAN-18
using channel ORA_AUX_DISK_1
starting media recovery

archived log for thread 1 with sequence 46 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_46_f6gspc03_.arc
archived log for thread 1 with sequence 47 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_47_f6gt54nh_.arc
archived log for thread 1 with sequence 48 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_48_f6gt5svq_.arc
archived log for thread 1 with sequence 49 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_49_f6gwfnwg_.arc
archived log for thread 1 with sequence 50 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_50_f6gwqt4p_.arc
archived log for thread 1 with sequence 51 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_51_f6gwrgj0_.arc
archived log for thread 1 with sequence 52 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_52_f6gwvz1d_.arc
archived log for thread 1 with sequence 53 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_53_f6gx3ohv_.arc
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_46_f6gspc03_.arc thread=1 sequence=46
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_47_f6gt54nh_.arc thread=1 sequence=47
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_48_f6gt5svq_.arc thread=1 sequence=48
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_49_f6gwfnwg_.arc thread=1 sequence=49
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_50_f6gwqt4p_.arc thread=1 sequence=50
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_51_f6gwrgj0_.arc thread=1 sequence=51
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_52_f6gwvz1d_.arc thread=1 sequence=52
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_53_f6gx3ohv_.arc thread=1 sequence=53
media recovery complete, elapsed time: 00:00:13
Finished recover at 23-JAN-18

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/bkp/DOYEN/controlfile/o1_mf_f6gx9hrp_.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     834666496 bytes
Fixed Size                     2929888 bytes
Variable Size                230689568 bytes
Database Buffers             595591168 bytes
Redo Buffers                   5455872 bytes
sql statement: alter system set  control_files =   ''/u01/bkp/DOYEN/controlfile/o1_mf_f6gx9hrp_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area     834666496 bytes
Fixed Size                     2929888 bytes
Variable Size                230689568 bytes
Database Buffers             595591168 bytes
Redo Buffers                   5455872 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2018-01-23 23:12:50','yyyy-mm-dd:hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  6 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  6;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
Starting restore at 23-JAN-18
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: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/bkp/FCMZ_PITR_DOYEN/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/backupset/2018_01_23/o1_mf_nnndf_TAG20180123T221517_f6gsnxws_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/backupset/2018_01_23/o1_mf_nnndf_TAG20180123T221517_f6gsnxws_.bkp tag=TAG20180123T221517
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 23-JAN-18
datafile 6 switched to datafile copy
input datafile copy RECID=8 STAMP=966208757 file name=/u01/bkp/FCMZ_PITR_DOYEN/datafile/o1_mf_users_f6gxdw9n_.dbf
contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2018-01-23 23:12:50','yyyy-mm-dd:hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile  6 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  6 online
Starting recover at 23-JAN-18
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 46 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_46_f6gspc03_.arc
archived log for thread 1 with sequence 47 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_47_f6gt54nh_.arc
archived log for thread 1 with sequence 48 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_48_f6gt5svq_.arc
archived log for thread 1 with sequence 49 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_49_f6gwfnwg_.arc
archived log for thread 1 with sequence 50 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_50_f6gwqt4p_.arc
archived log for thread 1 with sequence 51 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_51_f6gwrgj0_.arc
archived log for thread 1 with sequence 52 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_52_f6gwvz1d_.arc
archived log for thread 1 with sequence 53 is already on disk as file /u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_53_f6gx3ohv_.arc
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_46_f6gspc03_.arc thread=1 sequence=46
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_47_f6gt54nh_.arc thread=1 sequence=47
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_48_f6gt5svq_.arc thread=1 sequence=48
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_49_f6gwfnwg_.arc thread=1 sequence=49
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_50_f6gwqt4p_.arc thread=1 sequence=50
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_51_f6gwrgj0_.arc thread=1 sequence=51
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_52_f6gwvz1d_.arc thread=1 sequence=52
archived log file name=/u01/app/oracle/product/12.1.0/fast_recovery_area/DOYEN/archivelog/2018_01_23/o1_mf_1_53_f6gx3ohv_.arc thread=1 sequence=53
media recovery complete, elapsed time: 00:00:03
Finished recover at 23-JAN-18
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/bkp''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/bkp''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/bkp''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/bkp''
Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_FCmz_hjsC":
EXPDP> Estimate in progress using BLOCKS method...
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Total estimation using BLOCKS method: 2 MB
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 "SAM"."KK"                                  873.1 KB  100000 rows
EXPDP> Master table "SYS"."TSPITR_EXP_FCmz_hjsC" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_FCmz_hjsC is:
EXPDP>   /u01/bkp/tspitr_FCmz_81372.dmp
EXPDP> Job "SYS"."TSPITR_EXP_FCmz_hjsC" successfully completed at Tue Jan 23 23:20:08 2018 elapsed 0 00:00:25
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_FCmz_tjei" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_FCmz_tjei":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "SAM"."KK"                                  873.1 KB  100000 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_FCmz_tjei" successfully completed at Tue Jan 23 23:20:15 2018 elapsed 0 00:00:03
Import completed
Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/bkp/DOYEN/datafile/o1_mf_temp_f6gxc7ws_.tmp deleted
auxiliary instance file /u01/bkp/FCMZ_PITR_DOYEN/onlinelog/o1_mf_3_f6gxf37o_.log deleted
auxiliary instance file /u01/bkp/FCMZ_PITR_DOYEN/onlinelog/o1_mf_2_f6gxf232_.log deleted
auxiliary instance file /u01/bkp/FCMZ_PITR_DOYEN/onlinelog/o1_mf_1_f6gxf0m1_.log deleted
auxiliary instance file /u01/bkp/FCMZ_PITR_DOYEN/datafile/o1_mf_users_f6gxdw9n_.dbf deleted
auxiliary instance file /u01/bkp/DOYEN/datafile/o1_mf_sysaux_f6gx9onz_.dbf deleted
auxiliary instance file /u01/bkp/DOYEN/datafile/o1_mf_undotbs1_f6gx9oo3_.dbf deleted
auxiliary instance file /u01/bkp/DOYEN/datafile/o1_mf_system_f6gx9ons_.dbf deleted
auxiliary instance file /u01/bkp/DOYEN/controlfile/o1_mf_f6gx9hrp_.ctl deleted
auxiliary instance file tspitr_FCmz_81372.dmp deleted
Finished recover at 23-JAN-18







Check the Table :
---------------------
SQL> select count(*) from san.kk;
COUNT(*)
----------
100000

Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>