--创建表空间 CREATE TABLESPACE "DATACNT_TEST" LOGGING DATAFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DATACNT_TEST.ora'SIZE 50M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
-- create table
create table ttest (i_id integer, c_name varchar2(10)) tablespacedatacnt_test; create index itest on ttest(i_id) tablespace DATACNT_TEST;
insert into ttest(i_id,c_name) values (1, '1'); insert into ttest(i_id,c_name) values (2, '2'); insert into ttest(i_id,c_name) values (3, '3'); insert into ttest(i_id,c_name) values (4, '4'); insert into ttest(i_id,c_name) values (5, '5'); insert into ttest(i_id,c_name) values (6, '6'); insert into ttest(i_id,c_name) values (7, '7'); insert into ttest(i_id,c_name) values (8, '8'); insert into ttest(i_id,c_name) values (8, '9'); insert into ttest(i_id,c_name) values (10, '10'); insert into ttest(i_id,c_name) values (11, '11');
select * from ttest;
--check SELECT * FROM SYS.TS_PITR_CHECK WHERE ( TS1_NAME IN ('DATACNT_TEST') AND TS2_NAME NOT IN ('DATACNT_TEST') ) OR ( TS1_NAME NOT IN ('DATACNT_TEST') AND TS2_NAME IN ('DATACNT_TEST') );
--记住时间点
select sysdate from dual;
--执行rman备份 run{ allocate channel d1 type disk; backup tag ts_test format 'C:\temp\TS_t%t_s%s.bkp' tablespace DATACNT_TEST,UNDOTBS1,SYSTEM; backup current controlfile; release channel d1; }
--模拟操作 修改ttest的表
delete from ttest where c_name like '%1%'; commit;
RMAN> run { 2> recover tablespace DATACNT_TEST until time"to_date('2010-3-18 13:31:48','yyyy-mm-dd hh24:mi:ss')" auxiliarydestination 'C:\auxiliary'; 3> }
内存脚本的内容: { # set the until clause set until time "to_date('2010-3-18 13:31:48','yyyy-mm-ddhh24:mi:ss')"; # restore the controlfile restore clone controlfile; # mount the controlfile sql clone 'alter database mount clone database'; # archive current online log for tspitr to a resent untiltime sql 'alter system archive log current'; # avoid unnecessary autobackups for structural changes duringTSPITR sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;'; } 正在执行内存脚本
sql 语句: begin dbms_backup_restore.AutoBackupFlag(FALSE); end; 释放的通道: ORA_DISK_1 释放的通道: ORA_AUX_DISK_1
内存脚本的内容: { # generated tablespace point-in-time recovery script # set the until clause set until time "to_date('2010-3-18 13:31:48','yyyy-mm-ddhh24:mi:ss')"; plsql <<<-- tspitr_2 declare sqlstatement varchar2(512); offline_not_needed exception; pragma exception_init(offline_not_needed, -01539); begin sqlstatement := 'alter tablespace '|| 'DATACNT_TEST' ||' offlinefor recover' ; krmicd.writeMsg(6162, sqlstatement); krmicd.execSql(sqlstatement); exception when offline_not_needed then null; end; >>>; # set an omf destination filename for restore set newname for clone datafile 1 to new; # set an omf destination filename for restore set newname for clone datafile 2 to new; # set an omf destination tempfile set newname for clone tempfile 1 to new; # set a destination filename for restore set newname for datafile 20 to "C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DATACNT_TEST.ORA"; # rename all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set plus the auxilliarytablespaces restore clone datafile 1, 2, 20; switch clone datafile all; #online the datafiles restored or flipped sql clone "alter database datafile 1 online"; #online the datafiles restored or flipped sql clone "alter database datafile 2 online"; #online the datafiles restored or flipped sql clone "alter database datafile 20 online"; # make the controlfile point at the restored datafiles, thenrecover them recover clone database tablespace "DATACNT_TEST", "SYSTEM","UNDOTBS1" delete a rchivelog; alter clone database open resetlogs; # PLUG HERE the creation of a temporary tablespace if export failsdue to lack # of temporary space. # For example in Unix these two lines would do that: #sql clone "create tablespace aux_tspitr_tmp # datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K"; } 正在执行内存脚本
正在执行命令: SET until clause
sql 语句: alter tablespace DATACNT_TEST offline for recover
内存脚本的内容: { # export the tablespaces in the recovery set host 'exp userid=\"/@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=oracle)(ARGV0 =oracleyaxj)(ARGS=^'(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))^')(ENVS=^' ORACLE_SID=yaxj^'))(CONNECT_DATA=(SID=yaxj))) as sysdba\"point_in_time_recover= y tablespaces= DATACNT_TEST file= tspitr_a.dmp'; # shutdown clone before import shutdown clone immediate # import the tablespaces in the recovery set host 'imp userid =\"/@ as sysdba\" point_in_time_recover=yfile= tspitr_a.dmp'; # online/offline the tablespace imported sql "alter tablespace DATACNT_TEST online"; sql "alter tablespace DATACNT_TEST offline"; # enable autobackups in case user does open resetlogs from RMANafter TSPITR sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;'; } 正在执行内存脚本
Export: Release 10.2.0.1.0 - Production on 星期四 3月 18 13:39:342010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 -Production With the Partitioning, OLAP and Data Mining options 已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集 注: 将不导出表数据 (行)