???????????????????
-- ???????
SQL> select * from v$version where rownum<2;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL> select 'Leshami' Author??'http://blog.csdn.net/leshami' Blog??
2  '645746311' QQ from dual;
AUTHOR  BLOG                         QQ
------- ---------------------------- ---------
Leshami http://blog.csdn.net/leshami 645746311
--???????鵵??
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
--????2?????????TSPITR?????
SQL> create tablespace tbs_tspitr1 datafile '/app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf' size 20m;
SQL> create tablespace tbs_tspitr2 datafile '/app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf' size 20m;
--????????????????
SQL> create user usr_tbspitr identified by usr_tbspitr;
SQL> grant dba to usr_tbspitr;
SQL> conn usr_tbspitr/usr_tbspitr
--???????????????????????tbs_tspitr1????
SQL> create table tb_emp tablespace tbs_tspitr1 as select * from scott.emp;
--??????????????tbs_tspitr2??
SQL> create unique index pk_tb_emp on tb_emp(empno) tablespace tbs_tspitr2;
SQL> alter table tb_emp add primary key(empno) using index pk_tb_emp;
SQL> select count(*) from tb_emp;
COUNT(*)
----------
14
--?????????????????????????
$ mkdir /tmp/tempbak
$ rman target /
RMAN> configure controlfile autobackup on;
RMAN> backup database format '/tmp/tempbak/db_%d_full_%U' plus archivelog;
SQL> set time on;
--???turncate??tb_emp
14:17:05 SQL> truncate table tb_emp;
SQL> set time off;
--?????tbs_tspitr2??????????????tb_dept
SQL> create table tb_dept tablespace tbs_tspitr2 as select * from scott.dept;
SQL> select count(*) from tb_dept;
COUNT(*)
----------
4
--???????
SQL> create unique index pk_tb_dept on tb_dept(deptno) tablespace tbs_tspitr2;
--??????????
SQL> alter table tb_dept add primary key(deptno) using index pk_tb_dept;
--???tb_emp??????
SQL> alter table tb_emp add constraint fk_tb_dept foreign key(deptno)
2 >  references tb_dept(deptno);
$ mkdir -pv /tmp/aux
RMAN> recover tablespace tbs_tspitr1
until time "to_date( '2017-04-19 14:17:05'?? 'yyyy-mm-dd hh24:mi:ss')"
auxiliary destination '/tmp/aux';
--???Υ???????????
Running TRANSPORT_SET_CHECK on recovery set tablespaces
The following errors need to be fixed before peforming this command
Violation: ORA-39906: Constraint FK_TB_DEPT between table USR_TBSPITR.TB_DEPT
in tablespace TBS_TSPITR2 and table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.
Violation: ORA-39908: Index USR_TBSPITR.PK_TB_EMP in tablespace TBS_TSPITR2 enforces
primary constraints  of table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.
--???????DBMS_TTS????????
SQL> conn / as sysdba
SQL> BEGIN
2     DBMS_TTS.TRANSPORT_SET_CHECK('TBS_TSPITR1'?? TRUE??TRUE);
3  END;
4  /
PL/SQL procedure successfully completed.
--???????????????RMAN???????
SQL> SELECT * FROM  TRANSPORT_SET_VIOLATIONS;
VIOLATIONS
--------------------------------------------------------------------------------
ORA-39906: Constraint FK_TB_DEPT between table USR_TBSPITR.TB_DEPT in tablespace
TBS_TSPITR2 and table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.
ORA-39908: Index USR_TBSPITR.PK_TB_EMP in tablespace TBS_TSPITR2 enforces primary
constraints  of table USR_TBSPITR.TB_EMP in tablespace TBS_TSPITR1.
--???潫TBS_TSPITR2????????????????????
SQL> BEGIN
2     DBMS_TTS.TRANSPORT_SET_CHECK('TBS_TSPITR1??TBS_TSPITR2'?? TRUE??TRUE);
3  END;
4  /
PL/SQL procedure successfully completed.
--??????????????????????2?????????????????????????
SQL> SELECT * FROM  TRANSPORT_SET_VIOLATIONS;
no rows selected
--??????tbs_tspitr2???????????У???????rman
RMAN> recover tablespace tbs_tspitr1??tbs_tspitr2
2> until time "to_date( '2017-04-19 14:17:05'?? 'yyyy-mm-dd hh24:mi:ss')"
3> auxiliary destination '/tmp/aux';
Starting recover at 19-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=162 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='bjmm'  --?????????????????
--??????????????????????
initialization parameters used for automatic instance:
db_name=ORA11G
db_unique_name=bjmm_tspitr_ORA11G
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/tmp/aux
log_archive_dest_1='location=/tmp/aux'
#No auxiliary parameter file used
--??????????
starting up automatic instance ORA11G
Oracle instance started
Total System Global Area     292278272 bytes
Fixed Size                     2227744 bytes
Variable Size                100663776 bytes
Database Buffers             184549376 bytes
Redo Buffers                   4837376 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully
--??н????????????????
contents of Memory Script:
{
# set requested point in time
set until  time "to_date( '2017-04-19 14:17:05'?? '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';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script
executing command: SET until clause
Starting restore at 19-APR-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=42 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 /app/oracle/ora11g/fast_recovery_area
/ORA11G/autobackup/2017_04_19/o1_mf_s_941724971_dhg05dw1_.bkp
channel ORA_AUX_DISK_1: piece handle=/app/oracle/ora11g/fast_recovery_area/ORA11G/autobackup
/2017_04_19/o1_mf_s_941724971_dhg05dw1_.bkp tag=TAG20170419T141611
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete?? elapsed time: 00:00:01
output file name=/tmp/aux/ORA11G/controlfile/o1_mf_dhg48bwc_.ctl
Finished restore at 19-APR-17
sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
--???ò?????????????????????????
contents of Memory Script:
{
# set requested point in time
set until  time "to_date( '2017-04-19 14:17:05'?? 'yyyy-mm-dd hh24:mi:ss')";
plsql <<<-- tspitr_2
declare
sqlstatement       varchar2(512);
offline_not_needed exception;
pragma exception_init(offline_not_needed?? -01539);
begin
sqlstatement := 'alter tablespace '||  'TBS_TSPITR1' ||' offline immediate';
krmicd.writeMsg(6162?? sqlstatement);
krmicd.execSql(sqlstatement);
exception
when offline_not_needed then
null;
end; >>>;
plsql <<<-- tspitr_2
declare
sqlstatement       varchar2(512);
offline_not_needed exception;
pragma exception_init(offline_not_needed?? -01539);
begin
sqlstatement := 'alter tablespace '||  'TBS_TSPITR2' ||' offline immediate';
krmicd.writeMsg(6162?? sqlstatement);
krmicd.execSql(sqlstatement);
exception
when offline_not_needed then
null;
end; >>>;
# 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;
set newname for datafile  6 to
"/app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf";
set newname for datafile  7 to
"/app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1?? 3?? 2?? 6?? 7;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
sql statement: alter tablespace TBS_TSPITR1 offline immediate
sql statement: alter tablespace TBS_TSPITR2 offline immediate
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /tmp/aux/ORA11G/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 19-APR-17
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 /tmp/aux/ORA11G/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /tmp/aux/ORA11G/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /tmp/aux/ORA11G/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf
channel ORA_AUX_DISK_1: reading from backup piece /tmp/tempbak/db_ORA11G_full_02s2358q_1_1
channel ORA_AUX_DISK_1: piece handle=/tmp/tempbak/db_ORA11G_full_02s2358q_1_1 tag=TAG20170419T141554
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete?? elapsed time: 00:00:15
Finished restore at 19-APR-17
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_system_dhg48m17_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_undotbs1_dhg48m2y_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=941729186 file name=/tmp/aux/ORA11G/datafile/o1_mf_sysaux_dhg48m25_.dbf
--???????????????????????????????????????resetlogs??????????
contents of Memory Script:
{
# set requested point in time
set until  time "to_date( '2017-04-19 14:17:05'?? '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";
sql clone "alter database datafile  6 online";
sql clone "alter database datafile  7 online";
# recover and open resetlogs
recover clone database tablespace  "TBS_TSPITR1"?? "TBS_TSPITR2"?? "SYSTEM"??
"UNDOTBS1"?? "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
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
sql statement: alter database datafile  6 online
sql statement: alter database datafile  7 online
Starting recover at 19-APR-17
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 8 is already on disk as file
/app/oracle/ora11g/fast_recovery_area/ORA11G/archivelog/2017_04_19/o1_mf_1_8_dhg05b87_.arc
archived log for thread 1 with sequence 9 is already on disk as file
/app/oracle/ora11g/fast_recovery_area/ORA11G/archivelog/2017_04_19/o1_mf_1_9_dhg48kow_.arc
archived log file name=/app/oracle/ora11g/fast_recovery_area/ORA11G
/archivelog/2017_04_19/o1_mf_1_8_dhg05b87_.arc thread=1 sequence=8
archived log file name=/app/oracle/ora11g/fast_recovery_area/ORA11G
/archivelog/2017_04_19/o1_mf_1_9_dhg48kow_.arc thread=1 sequence=9
media recovery complete?? elapsed time: 00:00:01
Finished recover at 19-APR-17
database opened
contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  TBS_TSPITR1 read only';
sql clone 'alter tablespace  TBS_TSPITR2 read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/tmp/aux''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/tmp/aux''";
}
executing Memory Script
sql statement: alter tablespace  TBS_TSPITR1 read only
sql statement: alter tablespace  TBS_TSPITR2 read only
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/aux''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/aux''
--???????洴??????????????????dump???
Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_bjmm":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
EXPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_bjmm" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_bjmm is:
EXPDP>   /tmp/aux/tspitr_bjmm_39061.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace TBS_TSPITR1:
EXPDP>   /app/oracle/ora11g/oradata/ora11g/tbs_tspitr1.dbf
EXPDP> Datafiles required for transportable tablespace TBS_TSPITR2:
EXPDP>   /app/oracle/ora11g/oradata/ora11g/tbs_tspitr2.dbf
EXPDP> Job "SYS"."TSPITR_EXP_bjmm" successfully completed at 15:26:53
Export completed
--????????????????
contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace  TBS_TSPITR1 including contents keep datafiles';
sql 'drop tablespace  TBS_TSPITR2 including contents keep datafiles';
}
executing Memory Script
database closed
database dismounted
Oracle instance shut down
sql statement: drop tablespace  TBS_TSPITR1 including contents keep datafiles
sql statement: drop tablespace  TBS_TSPITR2 including contents keep datafiles
--???????
Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_bjmm" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_bjmm":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
IMPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_bjmm" successfully completed at 15:27:15
Import completed
--???????????????????
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace  TBS_TSPITR1 read write';
sql 'alter tablespace  TBS_TSPITR1 offline';
sql 'alter tablespace  TBS_TSPITR2 read write';
sql 'alter tablespace  TBS_TSPITR2 offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
sql statement: alter tablespace  TBS_TSPITR1 read write
sql statement: alter tablespace  TBS_TSPITR1 offline
sql statement: alter tablespace  TBS_TSPITR2 read write
sql statement: alter tablespace  TBS_TSPITR2 offline
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
--????????????????????????????????
Removing automatic instance
Automatic instance removed
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_temp_dhg499bd_.tmp deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_3_dhg497cw_.log deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_2_dhg496fz_.log deleted
auxiliary instance file /tmp/aux/ORA11G/onlinelog/o1_mf_1_dhg495d4_.log deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_sysaux_dhg48m25_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_undotbs1_dhg48m2y_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/datafile/o1_mf_system_dhg48m17_.dbf deleted
auxiliary instance file /tmp/aux/ORA11G/controlfile/o1_mf_dhg48bwc_.ctl deleted
Finished recover at 19-APR-17
--??????????????????
RMAN> backup tablespace tbs_tspitr1??tbs_tspitr2 format '/tmp/tempbak/tbs_%d_%U';
-- RMAN????????????????????????bjmm pmon????
$ ps -ef|grep pmon
oracle   16911     1  0 15:25 ?        00:00:00 ora_pmon_bjmm
oracle   22747     1  0 09:03 ?        00:00:03 ora_pmon_ora11g
--??????????2???????????
$ ls -hltr /tmp/aux
total 8.0K
drwxr-x---. 5 oracle oinstall 4.0K Apr 19 15:26 ORA11G
-rw-r-----. 1 oracle oinstall 4.0K Apr 19 15:26 tspitr_bjmm_39061.dmp
--???????????
SQL> select tablespace_name??status from dba_tablespaces where tablespace_name like '%TSPI%';
TABLESPACE_NAME                STATUS
------------------------------ ---------
TBS_TSPITR1                    OFFLINE
TBS_TSPITR2                    OFFLINE
--????????
SQL> alter tablespace TBS_TSPITR1 online;
SQL> alter tablespace TBS_TSPITR2 online;
SQL> conn usr_tbspitr/usr_tbspitr
--????????truncate???tb_emp?????
SQL> select count(*) from tb_emp;
COUNT(*)
----------
14
--??????????????????????TBS_TSPITR2???????
SQL> select count(*) from tb_dept;
select count(*) from tb_dept
*
ERROR at line 1:
ORA-00942: table or view does not exist
?????????2016??????????????н????????????????