You are on page 1of 12

===================================================================================

========

Recovery tablespace using Point in time recovery

-----------------------------------------------------------------------------------
--------
Check backup is taken or not if not take full backup:

rman target /

run {
allocate channel c1 type disk;
backup as backupset format '/u02/rman_bkp/df_%d_%s_%p'
incremental level 0 database;
backup as backupset format '/u02/rman_bkp/ar_%d_%s_%p'
archivelog all delete input;
}

-----------------------------------------------------------------------------------
----------

IF SCOTT SCHEMA IS NOT PRESENT THEN FOLLOW THIS STEPS

-----------------------------------------------------------------------------------
-------------

Go to sqldeveloper:
-------------------------
select * from all_users;

It will show no scott schema

Go to sqlplus:
------------------
sqlplus / as sysdba

SQL> @?/rdbms/admin/utlsampl.sql

sqlplus / as sysdba

SELECT username, account_status FROM dba_users WHERE username = 'SCOTT';

connect scott/tiger

col tname format a20;


select * from tab ;

Go to sqldeveloper:
-------------------------
select * from all_users;

It will show scott schema now.


-----------------------------------------------------------------------------------
------------------
Point in Time recovery
-----------------------------------------------------------------------------------
-----------

[oracle@oracle Desktop]$ date


Mon Oct 12 22:16:53 +06 2020

sqlplus / as sysdba

connect scott/tiger
Connected.

col tname format a20;


select * from tab ;

drop table bonus purge;

truncate table emp;

Go to sqldeveloper:
-------------------------

connect as sysdba
----------------------

select * from dba_users where username='SCOTT';

USERNAME USER_ID PASSWORD ACCOUNT_STATUS LOCK_DATE EXPIRY_DATE DEFAULT_TABLESPACE


TEMPORARY_TABLESPACE LOCAL_TEMP_TABLESPACE CREATED PROFILE
INITIAL_RSRC_CONSUMER_GROUP EXTERNAL_NAME PASSWORD_VERSIONS EDITIONS_ENABLED
AUTHENTICATION_TYPE PROXY_ONLY_CONNECT COMMON LAST_LOGIN
ORACLE_MAINTAINED INHERITED DEFAULT_COLLATION
IMPLICIT ALL_SHARD
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------------------------

SCOTT 108 OPEN 10-APR-21 USERS TEMP TEMP


12-OCT-20 DEFAULT DEFAULT_CONSUMER_GROUP 11G 12C
N PASSWORD N NO 12-OCT-20
10.13.11.000000000 PM ASIA/DHAKA N NO
USING_NLS_COMP NO NO

BEGIN
DBMS_TTS.TRANSPORT_SET_CHECK('USERS',TRUE,TRUE);
END;
/

SELECT * FROM TRANSPORT_SET_VIOLATIONS;

OUTPUT:

NO VIOLATION <--------that means there is no other object which is related to


another table

cd /u01/app/oracle
mkdir recovery
/u01/app/oracle/recovery

rman target /

RECOVER TABLESPACE users


until time "to_date('2021-05-12 10:00:35','YYYY-MM-DD HH24:MI:SS')"
AUXILIARY DESTINATION '/u02/recovery';

--------------------
----------------------
----------------------

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/12/2020 22:57:55
RMAN-03015: error occurred in stored script Memory Script
RMAN-03009: failure of sql command on default channel at 10/12/2020 22:57:54
RMAN-11003: failure during parse/execution of SQL statement: drop tablespace USERS
including contents keep datafiles cascade constraints
ORA-12919: Can not drop the default permanent tablespace

RMAN>

----------------Here problem is scott is in USERS tablespace and it is default


tablespace
changing default space will solve this
problem---------------------------------------------------------------

sqlplus / as sysdba

select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS OFFLINE
TSRMAN ONLINE

alter database default tablespace tsrman;

[oracle@oracle Desktop]$ cd /u01/app/oracle/recovery

[oracle@oracle recovery]$ rm -rf *

rman target /

RMAN> RECOVER TABLESPACE users


until time "to_date('2020-10-12 22:16:53','YYYY-MM-DD HH24:MI:SS')"
AUXILIARY DESTINATION '/u01/app/oracle/recovery';

sqlplus / as sysdba

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS OFFLINE
TSRMAN ONLINE

---------------------------It is necessary take backup --------------------------

rman target /

run {
allocate channel c1 type disk;
backup as backupset format '/u01/app/oracle/rman_bkp/df_%d_%s_%p'
tablespace users;
}

alter tablespace users online;

sqlplus / as sysdba

conn scott/tiger

col tname format a20;


select * from tab;

TNAME TABTYPE CLUSTERID


-------------------- ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE

SQL>
===================================================================================
=======================

Recovery Table TO A NEW TABLE using Point in Time Recovery


-----------------------------------------------------------------------------------
--------------------------

[oracle@oracle rman_bkp]$ date


Tue Oct 13 00:20:34 +06 2020
[oracle@oracle rman_bkp]$

Go to SQLDEVELOPER SCOTT USER:


------------------------------

select * from tab;

select * from emp;

delete from emp where empno=7900;

[oracle@oracle rman_bkp]$ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Oct 13 00:27:15 2020

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

connected to target database: ORCL (DBID=1579011246)

RMAN> RECOVER TABLE SCOTT.EMP


2> until time "to_date('2020-10-13 00:20:34','YYYY-MM-DD HH24:MI:SS')"
3> AUXILIARY DESTINATION '/u01/app/oracle/recovery'
4> DATAPUMP DESTINATION '/u01/app/oracle/dumpfiles'
5> DUMP FILE 'emp_dept_exp_dump.dump'
6> REMAP TABLE 'SCOTT'.'EMP':'EMP1';

Starting recover at 13-OCT-20


using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=69 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='dosl'

initialization parameters used for automatic instance:


db_name=ORCL
db_unique_name=dosl_pitr_ORCL
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1104M
processes=200
db_create_file_dest=/u01/app/oracle/recovery
log_archive_dest_1='location=/u01/app/oracle/recovery'
#No auxiliary parameter file used

starting up automatic instance ORCL

Oracle instance started

Total System Global Area 1157627904 bytes

Fixed Size 8619936 bytes


Variable Size 318769248 bytes
Database Buffers 822083584 bytes
Redo Buffers 8155136 bytes
Automatic instance created

contents of Memory Script:


{
# set requested point in time
set until time "to_date('2020-10-13 00:20:34','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 13-OCT-20


allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=35 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/rman_bkp/c-
1579011246-20201013-01
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/rman_bkp/c-1579011246-
20201013-01 tag=TAG20201013T001923
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/recovery/ORCL/controlfile/o1_mf_hr984djb_.ctl
Finished restore at 13-OCT-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('2020-10-13 00:20:34','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/app/oracle/recovery/ORCL/datafile/o1_mf_temp_%u_.tmp in


control file

Starting restore at 13-OCT-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
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece
/u01/app/oracle/rman_bkp/df_ORCL_36_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/rman_bkp/df_ORCL_36_1
tag=TAG20201013T001758
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:09:06
Finished restore at 13-OCT-20

datafile 1 switched to datafile copy


input datafile copy RECID=4 STAMP=1053650769 file
name=/u01/app/oracle/recovery/ORCL/datafile/o1_mf_system_hr984sbd_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1053650770 file
name=/u01/app/oracle/recovery/ORCL/datafile/o1_mf_undotbs1_hr984sdj_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=1053650771 file
name=/u01/app/oracle/recovery/ORCL/datafile/o1_mf_sysaux_hr984sd6_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2020-10-13 00:20:34','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 13-OCT-20


using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file


/u01/app/oracle/fast_recovery_area/orcl/ORCL/archivelog/2020_10_13/o1_mf_1_8_hr982v
st_.arc
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_AUX_DISK_1: reading from backup piece
/u01/app/oracle/rman_bkp/ar_ORCL_38_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/rman_bkp/ar_ORCL_38_1
tag=TAG20201013T001907
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
archived log file name=/u01/app/oracle/recovery/1_7_1053471734.dbf thread=1
sequence=7
archived log file
name=/u01/app/oracle/fast_recovery_area/orcl/ORCL/archivelog/2020_10_13/o1_mf_1_8_h
r982vst_.arc thread=1 sequence=8
media recovery complete, elapsed time: 00:00:02
Finished recover at 13-OCT-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 =
''/u01/app/oracle/recovery/ORCL/controlfile/o1_mf_hr984djb_.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 1157627904 bytes

Fixed Size 8619936 bytes


Variable Size 318769248 bytes
Database Buffers 822083584 bytes
Redo Buffers 8155136 bytes

sql statement: alter system set control_files =


''/u01/app/oracle/recovery/ORCL/controlfile/o1_mf_hr984djb_.ctl'' comment= ''RMAN
set'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)


Oracle instance started

Total System Global Area 1157627904 bytes

Fixed Size 8619936 bytes


Variable Size 318769248 bytes
Database Buffers 822083584 bytes
Redo Buffers 8155136 bytes

sql statement: alter database mount clone database

contents of Memory Script:


{
# set requested point in time
set until time "to_date('2020-10-13 00:20:34','YYYY-MM-DD 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 13-OCT-20


allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=36 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/recovery/DOSL_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece
/u01/app/oracle/rman_bkp/df_ORCL_36_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/rman_bkp/df_ORCL_36_1
tag=TAG20201013T001758
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 13-OCT-20

datafile 7 switched to datafile copy


input datafile copy RECID=8 STAMP=1053650968 file
name=/u01/app/oracle/recovery/DOSL_PITR_ORCL/datafile/o1_mf_users_hr999pq9_.dbf

contents of Memory Script:


{
# set requested point in time
set until time "to_date('2020-10-13 00:20:34','YYYY-MM-DD 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 13-OCT-20


using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file


/u01/app/oracle/fast_recovery_area/orcl/ORCL/archivelog/2020_10_13/o1_mf_1_8_hr982v
st_.arc
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_AUX_DISK_1: reading from backup piece
/u01/app/oracle/rman_bkp/ar_ORCL_38_1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/rman_bkp/ar_ORCL_38_1
tag=TAG20201013T001907
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/recovery/1_7_1053471734.dbf thread=1
sequence=7
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/recovery/1_7_1053471734.dbf RECID=31
STAMP=1053650972
archived log file
name=/u01/app/oracle/fast_recovery_area/orcl/ORCL/archivelog/2020_10_13/o1_mf_1_8_h
r982vst_.arc thread=1 sequence=8
media recovery complete, elapsed time: 00:00:00
Finished recover at 13-OCT-20

database opened

contents of Memory Script:


{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/app/oracle/dumpfiles''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/app/oracle/dumpfiles''";
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as


''/u01/app/oracle/dumpfiles''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as


''/u01/app/oracle/dumpfiles''

Performing export of tables...


EXPDP> Starting "SYS"."TSPITR_EXP_dosl_ogvs":
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/TABLE
EXPDP> . . exported "SCOTT"."EMP" 8.773 KB 14
rows
EXPDP> Master table "SYS"."TSPITR_EXP_dosl_ogvs" successfully loaded/unloaded
EXPDP>
******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_dosl_ogvs is:
EXPDP> /u01/app/oracle/dumpfiles/emp_dept_exp_dump.dump
EXPDP> Job "SYS"."TSPITR_EXP_dosl_ogvs" successfully completed at Tue Oct 13
00:53:44 2020 elapsed 0 00:02:38
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_dosl_ntEn" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_dosl_ntEn":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "SCOTT"."EMP1" 8.773 KB 14
rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Job "SYS"."TSPITR_IMP_dosl_ntEn" successfully completed at Tue Oct 13
00:54:42 2020 elapsed 0 00:00:18
Import completed

Removing automatic instance


Automatic instance removed
auxiliary instance file
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_temp_hr994lh0_.tmp deleted
auxiliary instance file
/u01/app/oracle/recovery/DOSL_PITR_ORCL/onlinelog/o1_mf_3_hr99bb7c_.log deleted
auxiliary instance file
/u01/app/oracle/recovery/DOSL_PITR_ORCL/onlinelog/o1_mf_2_hr99b79v_.log deleted
auxiliary instance file
/u01/app/oracle/recovery/DOSL_PITR_ORCL/onlinelog/o1_mf_1_hr999ysq_.log deleted
auxiliary instance file
/u01/app/oracle/recovery/DOSL_PITR_ORCL/datafile/o1_mf_users_hr999pq9_.dbf deleted
auxiliary instance file
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_sysaux_hr984sd6_.dbf deleted
auxiliary instance file
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_undotbs1_hr984sdj_.dbf deleted
auxiliary instance file
/u01/app/oracle/recovery/ORCL/datafile/o1_mf_system_hr984sbd_.dbf deleted
auxiliary instance file
/u01/app/oracle/recovery/ORCL/controlfile/o1_mf_hr984djb_.ctl deleted
auxiliary instance file emp_dept_exp_dump.dump deleted
Finished recover at 13-OCT-20

RMAN>

Go to SQLDEVELOPER:

select * from tab;


select * from emp;
select * from emp1 where empno=7900;

You might also like