重庆思庄Oracle、Redhat认证学习论坛

标题: ORACLE 12C 基于时间点的表恢复 [打印本页]

作者: 郑全    时间: 2020-1-14 17:24
标题: ORACLE 12C 基于时间点的表恢复
1.准备表
SQL> select count(*) from emp;
  COUNT(*)
----------
       107

确定时间:
SQL> select systimestamp from dual;
SYSTIMESTAMP
---------------------------------------------------------------------------
    14-JAN-20 05.12.30.075890 PM +08:00
--删除表
SQL> truncate table emp;
Table truncated.
SQL> drop table emp purge;
Table dropped.
SQL> desc emp;
ERROR:
ORA-04043: object emp does not exist
2.使用TPITR 基于时间点的恢复


[oracle@dbserver ~]$ echo $NLS_LANG
american_america.al32utf8
[oracle@dbserver ~]$ echo $NLS_DATE_FORMAT
yyyy-mm-dd hh24:mi:ss
[oracle@dbserver ~]$ rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Tue Jan 14 17:14:11 2020
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1544068695)
RMAN>   recover table hr.emp
2>      until time '2020-01-14 17:12:30'
3>      auxiliary destination '/home/oracle'
4>      ;

Starting recover at 2020-01-14 17:16:03
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=262 device type=DISK
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: SID=35 device type=SBT_TAPE
channel ORA_SBT_TAPE_1: Oracle Secure Backup
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='acej'
initialization parameters used for automatic instance:
db_name=ORCL
db_unique_name=acej_pitr_ORCL
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=600M
processes=200
db_create_file_dest=/home/oracle
log_archive_dest_1='location=/home/oracle'
#No auxiliary parameter file used

starting up automatic instance ORCL
Oracle instance started
Total System Global Area     629145600 bytes
Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until  time "2020-01-14 17:12:30";
# 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 2020-01-14 17:16:13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK
allocated channel: ORA_AUX_SBT_TAPE_1
channel ORA_AUX_SBT_TAPE_1: SID=173 device type=SBT_TAPE
channel ORA_AUX_SBT_TAPE_1: Oracle Secure Backup
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/ORCL/autobackup/2020_01_14/o1_mf_s_1029690705_h1v1gkjr_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/autobackup/2020_01_14/o1_mf_s_1029690705_h1v1gkjr_.bkp tag=TAG20200114T171145
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/ORCL/controlfile/o1_mf_h1v1pxvq_.ctl
Finished restore at 2020-01-14 17:16:14
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 "2020-01-14 17:12:30";
# 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  2 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 2 to /home/oracle/ORCL/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 2020-01-14 17:16:19
using channel ORA_AUX_DISK_1
using channel ORA_AUX_SBT_TAPE_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 /home/oracle/ORCL/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /home/oracle/ORCL/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/ORCL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_01_14/o1_mf_nnndf_TAG20200114T171137_h1v1g9bs_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_01_14/o1_mf_nnndf_TAG20200114T171137_h1v1g9bs_.bkp tag=TAG20200114T171137
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 2020-01-14 17:16:26
datafile 1 switched to datafile copy
input datafile copy RECID=59 STAMP=1029690986 file name=/home/oracle/ORCL/datafile/o1_mf_system_h1v1q3fn_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=60 STAMP=1029690986 file name=/home/oracle/ORCL/datafile/o1_mf_undotbs1_h1v1q3fx_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=61 STAMP=1029690986 file name=/home/oracle/ORCL/datafile/o1_mf_sysaux_h1v1q3fv_.dbf
contents of Memory Script:
{
# set requested point in time
set until  time "2020-01-14 17:12:30";
# 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 2020-01-14 17:16:26
using channel ORA_AUX_DISK_1
using channel ORA_AUX_SBT_TAPE_1
starting media recovery
archived log for thread 1 with sequence 6 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_6_h1v1gjcg_.arc
archived log for thread 1 with sequence 7 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_7_h1v1pn9c_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_6_h1v1gjcg_.arc thread=1 sequence=6
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_7_h1v1pn9c_.arc thread=1 sequence=7
media recovery complete, elapsed time: 00:00:00
Finished recover at 2020-01-14 17:16:27
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 =
  ''/home/oracle/ORCL/controlfile/o1_mf_h1v1pxvq_.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     629145600 bytes
Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes
sql statement: alter system set  control_files =   ''/home/oracle/ORCL/controlfile/o1_mf_h1v1pxvq_.ctl'' comment= ''RMAN set'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area     629145600 bytes
Fixed Size                     2927528 bytes
Variable Size                184550488 bytes
Database Buffers             436207616 bytes
Redo Buffers                   5459968 bytes
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until  time "2020-01-14 17:12:30";
# 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 2020-01-14 17:17:11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK
allocated channel: ORA_AUX_SBT_TAPE_1
channel ORA_AUX_SBT_TAPE_1: SID=173 device type=SBT_TAPE
channel ORA_AUX_SBT_TAPE_1: Oracle Secure Backup
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 /home/oracle/ACEJ_PITR_ORCL/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_01_14/o1_mf_nnndf_TAG20200114T171137_h1v1g9bs_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_01_14/o1_mf_nnndf_TAG20200114T171137_h1v1g9bs_.bkp tag=TAG20200114T171137
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2020-01-14 17:17:13
datafile 6 switched to datafile copy
input datafile copy RECID=63 STAMP=1029691033 file name=/home/oracle/ACEJ_PITR_ORCL/datafile/o1_mf_users_h1v1rr83_.dbf
contents of Memory Script:
{
# set requested point in time
set until  time "2020-01-14 17:12:30";
# 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 2020-01-14 17:17:13
using channel ORA_AUX_DISK_1
using channel ORA_AUX_SBT_TAPE_1
starting media recovery
archived log for thread 1 with sequence 6 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_6_h1v1gjcg_.arc
archived log for thread 1 with sequence 7 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_7_h1v1pn9c_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_6_h1v1gjcg_.arc thread=1 sequence=6
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_01_14/o1_mf_1_7_h1v1pn9c_.arc thread=1 sequence=7
media recovery complete, elapsed time: 00:00:00
Finished recover at 2020-01-14 17:17:13
database opened
contents of Memory Script:
{
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle''";
}
executing Memory Script
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle''
Performing export of tables...
   EXPDP> Starting "SYS"."TSPITR_EXP_acej_nEFg":  
   EXPDP> Estimate in progress using BLOCKS method...
   EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   EXPDP> Total estimation using BLOCKS method: 64 KB
   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> ORA-39127: unexpected error from call to export_string :=SYS.DBMS_TRANSFORM_EXIMP.INSTANCE_INFO_EXP('AQ$_ORDERS_QUEUETABLE_S','IX',1,1,'12.01.00.02.00',newblock)
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'
ORA-06512: at "SYS.DBMS_TRANSFORM_EXIMP", line 197
ORA-06512: at line 1
ORA-06512: at "SYS.DBMS_METADATA", line 10261
ORA-39127: unexpected error from call to export_string :=SYS.DBMS_TRANSFORM_EXIMP.INSTANCE_INFO_EXP('AQ$_STREAMS_QUEUE_TABLE_S','IX',1,1,'12.01.00.02.00',newblock)
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'
ORA-06512: at "SYS.DBMS_TRANSFORM_EXIMP", line 197
ORA-06512: at line 1
ORA-06512: at "SYS.DBMS_METADATA", line 10261
   EXPDP> . . exported "HR"."EMP"                                  17.08 KB     107 rows
   EXPDP> Master table "SYS"."TSPITR_EXP_acej_nEFg" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_acej_nEFg is:
   EXPDP>   /home/oracle/tspitr_acej_13491.dmp
   EXPDP> Job "SYS"."TSPITR_EXP_acej_nEFg" completed with 2 error(s) at Tue Jan 14 17:17:37 2020 elapsed 0 00:00:16
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_acej_CFbn" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_acej_CFbn":  
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
   IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
   IMPDP> . . imported "HR"."EMP"                                  17.08 KB     107 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_acej_CFbn" successfully completed at Tue Jan 14 17:18:05 2020 elapsed 0 00:00:21
Import completed

Removing automatic instance
Automatic instance removed
auxiliary instance file /home/oracle/ORCL/datafile/o1_mf_temp_h1v1qcf2_.tmp deleted
auxiliary instance file /home/oracle/ACEJ_PITR_ORCL/onlinelog/o1_mf_3_h1v1rt6f_.log deleted
auxiliary instance file /home/oracle/ACEJ_PITR_ORCL/onlinelog/o1_mf_2_h1v1rt36_.log deleted
auxiliary instance file /home/oracle/ACEJ_PITR_ORCL/onlinelog/o1_mf_1_h1v1rsxy_.log deleted
auxiliary instance file /home/oracle/ACEJ_PITR_ORCL/datafile/o1_mf_users_h1v1rr83_.dbf deleted
auxiliary instance file /home/oracle/ORCL/datafile/o1_mf_sysaux_h1v1q3fv_.dbf deleted
auxiliary instance file /home/oracle/ORCL/datafile/o1_mf_undotbs1_h1v1q3fx_.dbf deleted
auxiliary instance file /home/oracle/ORCL/datafile/o1_mf_system_h1v1q3fn_.dbf deleted
auxiliary instance file /home/oracle/ORCL/controlfile/o1_mf_h1v1pxvq_.ctl deleted
auxiliary instance file tspitr_acej_13491.dmp deleted
Finished recover at 2020-01-14 17:18:07


3.验证
  RMAN> select count(*) from hr.emp;
  COUNT(*)
----------
       107

  导致,表恢复回来。










欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2