tspitr

开启归档模式

14:58:00 SYS@ORA11GR2>shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

14:59:07 SYS@ORA11GR2>startup mount

ORACLE instance started.

Total System Global Area 847630336 bytes

Fixed Size 2257960 bytes

Variable Size 528485336 bytes

Database Buffers 310378496 bytes

Redo Buffers 6508544 bytes

Database mounted.

15:00:01 SYS@ORA11GR2>alter database archivelog;

Database altered

15:16:34 SYS@ORA11GR2>alter database open;

Database altered.

创建表空间t

15:53:34 SYS@ORA11GR2>create tablespace t datafile '/u01/app/oracle/oradata/ORA11GR2/t.dbf' size 10m;

Tablespace created.

创建表t1,t2

15:53:41 SYS@ORA11GR2>conn scott/tiger

Connected.

15:55:01 SCOTT@ORA11GR2>create table t1 (x int) tablespace t;

Table created.

15:55:31 SCOTT@ORA11GR2>create table t2 (x int) tablespace t;

Table created.

数据库热全备

[oracle@ORA11GR2 ~]$ mkdir -p /u01/oracle/backup

[oracle@ORA11GR2 backup]$ rman target /

RMAN> backup as backupset full database format '/u01/oracle/backup/db_%U.rmn' include current controlfile plus archivelog delete all input;

Starting backup at 07-AUG-16

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=148 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=15 RECID=1 STAMP=919267015

channel ORA_DISK_1: starting piece 1 at 07-AUG-16

channel ORA_DISK_1: finished piece 1 at 07-AUG-16

piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/01rclpm7_1_1 tag=TAG20160807T155655 comment=NONE

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

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_917107926.dbf RECID=1 STAMP=919267015

Finished backup at 07-AUG-16

Starting backup at 07-AUG-16

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

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

input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf

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

input datafile file number=00006 name=/u01/app/oracle/oradata/ORA11GR2/t.dbf

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

channel ORA_DISK_1: starting piece 1 at 07-AUG-16

channel ORA_DISK_1: finished piece 1 at 07-AUG-16

piece handle=/u01/oracle/backup/db_02rclpm9_1_1.rmn tag=TAG20160807T155657 comment=NONE

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

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 07-AUG-16

channel ORA_DISK_1: finished piece 1 at 07-AUG-16

piece handle=/u01/oracle/backup/db_03rclpn2_1_1.rmn tag=TAG20160807T155657 comment=NONE

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

Finished backup at 07-AUG-16

Starting backup at 07-AUG-16

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=16 RECID=2 STAMP=919267044

channel ORA_DISK_1: starting piece 1 at 07-AUG-16

channel ORA_DISK_1: finished piece 1 at 07-AUG-16

piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rclpn4_1_1 tag=TAG20160807T155724 comment=NONE

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

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_917107926.dbf RECID=2 STAMP=919267044

Finished backup at 07-AUG-16

插入数据

15:55:41 SCOTT@ORA11GR2>insert into t1 select empno from emp;

14 rows created.

15:58:30 SCOTT@ORA11GR2>insert into t2 select deptno from dept;

4 rows created.

15:58:41 SCOTT@ORA11GR2>commit;

Commit complete.

drop purge t1表

15:59:50 SCOTT@ORA11GR2>drop table t1 purge;

Table dropped.

16:00:00 SCOTT@ORA11GR2>insert into t2 select empno from emp;

14 rows created.

16:00:47 SCOTT@ORA11GR2>commit;

Commit complete.

16:00:51 SCOTT@ORA11GR2>select count(*) from t2;

COUNT(*)

----------

18

导出t2表

[oracle@ORA11GR2 dbs]$ mkdir -p /u01/oracle/t2

16:01:01 SCOTT@ORA11GR2>conn / as sysdba

Connected.

16:01:52 SYS@ORA11GR2>create or replace directory dp as '/u01/oracle/t2';

Directory created.

16:01:56 SYS@ORA11GR2>grant read,write on directory dp to scott;

Grant succeeded.

[oracle@ORA11GR2 t2]$ expdp scott/tiger directory=dp dumpfile=t2.dmp tables=t2;

Export: Release 11.2.0.4.0 - Production on Sun Aug 7 16:03:05 2016

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=dp dumpfile=t2.dmp tables=t2

Estimate in progress using BLOCKS method...

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported "SCOTT"."T2" 5.148 KB 18 rows

Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:

/u01/oracle/t2/t2.dmp

Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Sun Aug 7 16:03:13 2016 elapsed 0 00:00:06

[oracle@ORA11GR2 t2]$ ls

export.log t2.dmp

用rman恢复t表空间的表

RMAN> recover tablespace t until time "to_date('2016-08-07 15:59:02','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/u01/oracle/backup';

Starting recover at 07-AUG-16

using channel ORA_DISK_1

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='FulC'

initialization parameters used for automatic instance:

db_name=ORA11GR2

db_unique_name=FulC_tspitr_ORA11GR2

compatible=11.2.0.4.0

db_block_size=8192

db_files=200

sga_target=1G

processes=80

db_create_file_dest=/u01/oracle/backup

log_archive_dest_1='location=/u01/oracle/backup'

#No auxiliary parameter file used

starting up automatic instance ORA11GR2

Oracle instance started

Total System Global Area 1068937216 bytes

Fixed Size 2260088 bytes

Variable Size 281019272 bytes

Database Buffers 780140544 bytes

Redo Buffers 5517312 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('2016-08-07 15:59:02','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 07-AUG-16

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=81 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/oracle/backup/db_03rclpn2_1_1.rmn

channel ORA_AUX_DISK_1: piece handle=/u01/oracle/backup/db_03rclpn2_1_1.rmn tag=TAG20160807T155657

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/oracle/backup/ORA11GR2/controlfile/o1_mf_ctftxn79_.ctl

Finished restore at 07-AUG-16

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('2016-08-07 15:59:02','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 '|| 'T' ||' 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

"/u01/app/oracle/oradata/ORA11GR2/t.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;

switch clone datafile all;

}

executing Memory Script

executing command: SET until clause

sql statement: alter tablespace T offline immediate

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /u01/oracle/backup/ORA11GR2/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 07-AUG-16

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/oracle/backup/ORA11GR2/datafile/o1_mf_system_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/oracle/backup/ORA11GR2/datafile/o1_mf_undotbs1_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/oracle/backup/ORA11GR2/datafile/o1_mf_sysaux_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/ORA11GR2/t.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u01/oracle/backup/db_02rclpm9_1_1.rmn

channel ORA_AUX_DISK_1: piece handle=/u01/oracle/backup/db_02rclpm9_1_1.rmn tag=TAG20160807T155657

channel ORA_AUX_DISK_1: restored backup piece 1

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

Finished restore at 07-AUG-16

datafile 1 switched to datafile copy

input datafile copy RECID=5 STAMP=919267529 file name=/u01/oracle/backup/ORA11GR2/datafile/o1_mf_system_ctftxt7m_.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=6 STAMP=919267529 file name=/u01/oracle/backup/ORA11GR2/datafile/o1_mf_undotbs1_ctftxt7t_.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=7 STAMP=919267529 file name=/u01/oracle/backup/ORA11GR2/datafile/o1_mf_sysaux_ctftxt7p_.dbf

contents of Memory Script:

{

# set requested point in time

set until time "to_date('2016-08-07 15:59:02','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";

# recover and open resetlogs

recover clone database tablespace "T", "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

Starting recover at 07-AUG-16

using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 17 is already on disk as file /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_917107926.dbf

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=16

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rclpn4_1_1

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/04rclpn4_1_1 tag=TAG20160807T155724

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/oracle/backup/1_16_917107926.dbf thread=1 sequence=16

channel clone_default: deleting archived log(s)

archived log file name=/u01/oracle/backup/1_16_917107926.dbf RECID=2 STAMP=919267530

archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_17_917107926.dbf thread=1 sequence=17

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

Finished recover at 07-AUG-16

database opened

contents of Memory Script:

{

# make read only the tablespace that will be exported

sql clone 'alter tablespace T read only';

# create directory for datapump import

sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/u01/oracle/backup''";

# create directory for datapump export

sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/u01/oracle/backup''";

}

executing Memory Script

sql statement: alter tablespace T read only

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

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

Performing export of metadata...

EXPDP> Starting "SYS"."TSPITR_EXP_FulC":

EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK

EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE

EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK

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

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

EXPDP> Dump file set for SYS.TSPITR_EXP_FulC is:

EXPDP> /u01/oracle/backup/tspitr_FulC_54087.dmp

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

EXPDP> Datafiles required for transportable tablespace T:

EXPDP> /u01/app/oracle/oradata/ORA11GR2/t.dbf

EXPDP> Job "SYS"."TSPITR_EXP_FulC" successfully completed at Sun Aug 7 16:06:26 2016 elapsed 0 00:00:47

Export completed

contents of Memory Script:

{

# shutdown clone before import

shutdown clone immediate

# drop target tablespaces before importing them back

sql 'drop tablespace T including contents keep datafiles cascade constraints';

}

executing Memory Script

database closed

database dismounted

Oracle instance shut down

sql statement: drop tablespace T including contents keep datafiles cascade constraints

Performing import of metadata...

IMPDP> Master table "SYS"."TSPITR_IMP_FulC" successfully loaded/unloaded

IMPDP> Starting "SYS"."TSPITR_IMP_FulC":

IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK

IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE

IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK

IMPDP> Job "SYS"."TSPITR_IMP_FulC" successfully completed at Sun Aug 7 16:06:45 2016 elapsed 0 00:00:03

Import completed

contents of Memory Script:

{

# make read write and offline the imported tablespaces

sql 'alter tablespace T read write';

sql 'alter tablespace T offline';

# enable autobackups after TSPITR is finished

sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';

}

executing Memory Script

sql statement: alter tablespace T read write

sql statement: alter tablespace T offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance

Automatic instance removed

auxiliary instance file /u01/oracle/backup/ORA11GR2/datafile/o1_mf_temp_ctftydwp_.tmp deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/onlinelog/o1_mf_3_ctftydbc_.log deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/onlinelog/o1_mf_2_ctftycvc_.log deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/onlinelog/o1_mf_1_ctftych9_.log deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/datafile/o1_mf_sysaux_ctftxt7p_.dbf deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/datafile/o1_mf_undotbs1_ctftxt7t_.dbf deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/datafile/o1_mf_system_ctftxt7m_.dbf deleted

auxiliary instance file /u01/oracle/backup/ORA11GR2/controlfile/o1_mf_ctftxn79_.ctl deleted

Finished recover at 07-AUG-16

将t表空间online

16:07:54 SYS@ORA11GR2>alter tablespace t online;

Tablespace altered.

查询t1表

16:08:10 SYS@ORA11GR2>conn scott/tiger

Connected.

16:08:41 SCOTT@ORA11GR2>select * from t1;

X

----------

7369

7499

7521

7566

7654

7698

7782

7788

7839

7844

7876

X

----------

7900

7902

7934

14 rows selected.

16:08:45 SCOTT@ORA11GR2>select count(*) from t2;

COUNT(*)

----------

4

将t2表删除,导入最新t2表

16:09:45 SCOTT@ORA11GR2>drop table t2 purge;

Table dropped.

16:10:15 SCOTT@ORA11GR2>exit

[oracle@ORA11GR2 ~]$ impdp scott/tiger directory=dp dumpfile=t2.dmp

Import: Release 11.2.0.4.0 - Production on Sun Aug 7 16:11:41 2016

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "SCOTT"."SYS_IMPORT_FULL_01": scott/******** directory=dp dumpfile=t2.dmp

Processing object type TABLE_EXPORT/TABLE/TABLE

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

. . imported "SCOTT"."T2" 5.148 KB 18 rows

Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at Sun Aug 7 16:11:44 2016 elapsed 0 00:00:02

16:12:17 SCOTT@ORA11GR2>select count(*) from t2;

COUNT(*)

----------

18

发布了47 篇原创文章 · 获赞 5 · 访问量 6925

猜你喜欢

转载自blog.csdn.net/whb234174124/article/details/84848165