Wednesday, 10 February 2021

Table recovery using RMAN Backup


Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production


SQL> connect sita/sita

Connected.

SQL> create table emp(id number);


Table created.


SQL> begin

for i in 1 .. 100000 loop

insert into emp values(i);

end loop;

end;

/  2    3    4    5    6


PL/SQL procedure successfully completed.


SQL> /


PL/SQL procedure successfully completed.


SQL> select count(*) from emp;


  COUNT(*)

----------

    200000


SQL>

SQL>

SQL> commit;


Commit complete.


SQL> archive log list;

ORA-01031: insufficient privileges

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[oracle@oracle ~]$ rman target /


Recovery Manager: Release 12.2.0.1.0 - Production on Wed Feb 10 16:05:01 2021


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


connected to target database: DEMO (DBID=3807952967)


RMAN> backup database plus archivelog;



Starting backup at 10-FEB-21

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=72 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=14 RECID=1 STAMP=1064159388

input archived log thread=1 sequence=15 RECID=2 STAMP=1064159407

input archived log thread=1 sequence=16 RECID=3 STAMP=1064160323

channel ORA_DISK_1: starting piece 1 at 10-FEB-21

channel ORA_DISK_1: finished piece 1 at 10-FEB-21

piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_annnn_TAG20210210T160525_j27fqfbx_.bkp tag=TAG20210210T160525 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 10-FEB-21


Starting backup at 10-FEB-21

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/demo/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/demo/sysaux01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/demo/users01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/demo/undotbs01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/demo/usertbs01.dbf

input datafile file number=00007 name=/u01/app/oracle/oradata/demo/hmld01.dbf

input datafile file number=00006 name=/u01/app/oracle/oradata/demo/lmauto01.dbf

channel ORA_DISK_1: starting piece 1 at 10-FEB-21

channel ORA_DISK_1: finished piece 1 at 10-FEB-21

piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_nnndf_TAG20210210T160528_j27fqkpc_.bkp tag=TAG20210210T160528 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15

Finished backup at 10-FEB-21


Starting backup at 10-FEB-21

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=17 RECID=4 STAMP=1064160344

channel ORA_DISK_1: starting piece 1 at 10-FEB-21

channel ORA_DISK_1: finished piece 1 at 10-FEB-21

piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_annnn_TAG20210210T160544_j27fr10o_.bkp tag=TAG20210210T160544 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 10-FEB-21


Starting Control File Autobackup at 10-FEB-21

piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/autobackup/2021_02_10/o1_mf_n_1064160346_j27fr2nf_.bkp comment=NONE

Finished Control File Autobackup at 10-FEB-21


RMAN> exit



Recovery Manager complete.

[oracle@oracle ~]$ sqlplus "/as sysdba"


SQL*Plus: Release 12.2.0.1.0 Production on Wed Feb 10 16:05:56 2021


Copyright (c) 1982, 2016, Oracle.  All rights reserved.



Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production


SQL> connect sita/sita

Connected.

SQL> SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW" FROM DUAL;


NOW

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

02-10-2021 16:06:20


SQL> drop table emp;


Table dropped.


SQL> commit;


Commit complete.






 [oracle@oracle ~]$ rman target /


Recovery Manager: Release 12.2.0.1.0 - Production on Wed Feb 10 16:07:05 2021


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


connected to target database: DEMO (DBID=3807952967)


RMAN> recover table sita.emp until time "to_date('2021-02-10 16:05:35','yyyy-mm-dd:hh24:mi:ss')" auxiliary destination '/u01/fra/';


Starting recover at 10-FEB-21

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=61 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='erwk'


initialization parameters used for automatic instance:

db_name=DEMO

db_unique_name=erwk_pitr_DEMO

compatible=12.2.0

db_block_size=8192

db_files=200

diagnostic_dest=/u01/app/oracle

_system_trig_enabled=FALSE

sga_target=1004M

processes=200

db_create_file_dest=/u01/fra/

log_archive_dest_1='location=/u01/fra/'

#No auxiliary parameter file used



starting up automatic instance DEMO


Oracle instance started


Total System Global Area    1052770304 bytes


Fixed Size                     8628688 bytes

Variable Size                276825648 bytes

Database Buffers             763363328 bytes

Redo Buffers                   3952640 bytes

Automatic instance created


contents of Memory Script:

{

# set requested point in time

set until  time "to_date('2021-02-10 16:05:35','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 10-FEB-21

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=37 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/demo/DEMO/autobackup/2021_02_10/o1_mf_n_1064159409_j27dts9t_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/autobackup/2021_02_10/o1_mf_n_1064159409_j27dts9t_.bkp tag=TAG20210210T155009

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/fra/DEMO/controlfile/o1_mf_j27fx598_.ctl

Finished restore at 10-FEB-21


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('2021-02-10 16:05:35','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  3 to new;

set newname for clone datafile  2 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, 3, 2;


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/fra/DEMO/datafile/o1_mf_tempts1_%u_.tmp in control file


Starting restore at 10-FEB-21

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/fra/DEMO/datafile/o1_mf_system_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/fra/DEMO/datafile/o1_mf_undotbs1_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/fra/DEMO/datafile/o1_mf_sysaux_%u_.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_nnndf_TAG20210210T160528_j27fqkpc_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_nnndf_TAG20210210T160528_j27fqkpc_.bkp tag=TAG20210210T160528

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:27

Finished restore at 10-FEB-21


datafile 1 switched to datafile copy

input datafile copy RECID=4 STAMP=1064160547 file name=/u01/fra/DEMO/datafile/o1_mf_system_j27fxfbp_.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=5 STAMP=1064160547 file name=/u01/fra/DEMO/datafile/o1_mf_undotbs1_j27fxfbz_.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=6 STAMP=1064160547 file name=/u01/fra/DEMO/datafile/o1_mf_sysaux_j27fxfbv_.dbf


contents of Memory Script:

{

# set requested point in time

set until  time "to_date('2021-02-10 16:05:35','yyyy-mm-dd:hh24:mi:ss')";

# online the datafiles restored or switched

sql clone "alter database datafile  1 online";

sql clone "alter database datafile  3 online";

sql clone "alter database datafile  2 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  3 online


sql statement: alter database datafile  2 online


Starting recover at 10-FEB-21

using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 16 is already on disk as file /u01/archive/1_16_1063882631.arc

archived log for thread 1 with sequence 17 is already on disk as file /u01/archive/1_17_1063882631.arc

archived log file name=/u01/archive/1_16_1063882631.arc thread=1 sequence=16

archived log file name=/u01/archive/1_17_1063882631.arc thread=1 sequence=17

media recovery complete, elapsed time: 00:00:02

Finished recover at 10-FEB-21


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/fra/DEMO/controlfile/o1_mf_j27fx598_.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    1052770304 bytes


Fixed Size                     8628688 bytes

Variable Size                276825648 bytes

Database Buffers             763363328 bytes

Redo Buffers                   3952640 bytes


sql statement: alter system set  control_files =   ''/u01/fra/DEMO/controlfile/o1_mf_j27fx598_.ctl'' comment= ''RMAN set'' scope=spfile


Oracle instance shut down


connected to auxiliary database (not started)

Oracle instance started


Total System Global Area    1052770304 bytes


Fixed Size                     8628688 bytes

Variable Size                276825648 bytes

Database Buffers             763363328 bytes

Redo Buffers                   3952640 bytes


sql statement: alter database mount clone database


contents of Memory Script:

{

# set requested point in time

set until  time "to_date('2021-02-10 16:05:35','yyyy-mm-dd:hh24:mi:ss')";

# set destinations for recovery set and auxiliary set datafiles

set newname for datafile  4 to new;

# restore the tablespaces in the recovery set and the auxiliary set

restore clone datafile  4;


switch clone datafile all;

}

executing Memory Script


executing command: SET until clause


executing command: SET NEWNAME


Starting restore at 10-FEB-21

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 00004 to /u01/fra/ERWK_PITR_DEMO/datafile/o1_mf_users01_%u_.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_nnndf_TAG20210210T160528_j27fqkpc_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/demo/DEMO/backupset/2021_02_10/o1_mf_nnndf_TAG20210210T160528_j27fqkpc_.bkp tag=TAG20210210T160528

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07

Finished restore at 10-FEB-21


datafile 4 switched to datafile copy

input datafile copy RECID=8 STAMP=1064160641 file name=/u01/fra/ERWK_PITR_DEMO/datafile/o1_mf_users01_j27g116z_.dbf


contents of Memory Script:

{

# set requested point in time

set until  time "to_date('2021-02-10 16:05:35','yyyy-mm-dd:hh24:mi:ss')";

# online the datafiles restored or switched

sql clone "alter database datafile  4 online";

# recover and open resetlogs

recover clone database tablespace  "USERS01", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;

alter clone database open resetlogs;

}

executing Memory Script


executing command: SET until clause


sql statement: alter database datafile  4 online


Starting recover at 10-FEB-21

using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 17 is already on disk as file /u01/archive/1_17_1063882631.arc

archived log file name=/u01/archive/1_17_1063882631.arc thread=1 sequence=17

media recovery complete, elapsed time: 00:00:00

Finished recover at 10-FEB-21


database opened


contents of Memory Script:

{

# create directory for datapump import

sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/u01/fra/''";

# create directory for datapump export

sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/u01/fra/''";

}

executing Memory Script


sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/fra/''


sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/fra/''


Performing export of tables...

   EXPDP> Starting "SYS"."TSPITR_EXP_erwk_wofm":

   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 "SITA"."EMP"                                1.700 MB  200000 rows

   EXPDP> Master table "SYS"."TSPITR_EXP_erwk_wofm" successfully loaded/unloaded

   EXPDP> ******************************************************************************

   EXPDP> Dump file set for SYS.TSPITR_EXP_erwk_wofm is:

   EXPDP>   /u01/fra/tspitr_erwk_19724.dmp

   EXPDP> Job "SYS"."TSPITR_EXP_erwk_wofm" successfully completed at Wed Feb 10 16:12:33 2021 elapsed 0 00:01:22

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_erwk_Cxwf" successfully loaded/unloaded

   IMPDP> Starting "SYS"."TSPITR_IMP_erwk_Cxwf":

   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE

   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

   IMPDP> . . imported "SITA"."EMP"                                1.700 MB  200000 rows

   IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

   IMPDP> Job "SYS"."TSPITR_IMP_erwk_Cxwf" successfully completed at Wed Feb 10 16:12:59 2021 elapsed 0 00:00:12

Import completed



Removing automatic instance

Automatic instance removed

auxiliary instance file /u01/fra/DEMO/datafile/o1_mf_tempts1_j27fymdd_.tmp deleted

auxiliary instance file /u01/fra/ERWK_PITR_DEMO/onlinelog/o1_mf_3_j27g1k6p_.log deleted

auxiliary instance file /u01/fra/ERWK_PITR_DEMO/onlinelog/o1_mf_2_j27g1j7m_.log deleted

auxiliary instance file /u01/fra/ERWK_PITR_DEMO/onlinelog/o1_mf_1_j27g1cqs_.log deleted

auxiliary instance file /u01/fra/ERWK_PITR_DEMO/datafile/o1_mf_users01_j27g116z_.dbf deleted

auxiliary instance file /u01/fra/DEMO/datafile/o1_mf_sysaux_j27fxfbv_.dbf deleted

auxiliary instance file /u01/fra/DEMO/datafile/o1_mf_undotbs1_j27fxfbz_.dbf deleted

auxiliary instance file /u01/fra/DEMO/datafile/o1_mf_system_j27fxfbp_.dbf deleted

auxiliary instance file /u01/fra/DEMO/controlfile/o1_mf_j27fx598_.ctl deleted

auxiliary instance file tspitr_erwk_19724.dmp deleted

Finished recover at 10-FEB-21


RMAN> exit


No comments:

Post a Comment

Featured post

duplicate db from standy to other server

 Duplicate Testuat   $ export ORACLE_SID=Testuat3 $ sqlplus '/as sysdba' Testuat3 SQL> alter system set cluster_database=FALSE sc...