用户管理的表空间按时间点恢复(TSPITR)是使用传输表空间来快速恢复一个或多个表空间到之前某个时间点。在以下情况下使用用户管理的表空间按时间点恢复很有用:
1.当错误执行drop tablespace操作
2.错误的作业或DML语句只对数据库的一部分产生影响
3.在一个物理数据库中有多个方案使用不同的表空间当一个方案要恢复到与其它方案不相同的时间点
4.当表空间在一个大数据库中(VLDB)表空间按时间点恢复要比使用备份还原和恢复整个数据库更有效
一种快速跨数据库传输表空间的方法是从源数据库卸载并且目标数据库中附加表空间。数据库可以跨平台,例如,Solaris和Windows 2000。卸载和附加是通过导出和导入工具来完成的。但并不是实际导出和导入表数据,只是简单的导出和导入内部元数据。
表空间按时间点恢复(TSPITR)的方法
在Oracle9i之前,可以有两种方法来执行用户管理的表空间按时间点恢复:
.传统用户管理的表空间按时间点恢复要求你创建一个克隆数据库。
.使用传输表空间执行用户管理的表空间按时间点恢复
在Oracle10g中,表空间按时间点恢复应该使用传输表空间来完成。传输表空间与传统的方法相比更简单易用。
TSPITR(表空间按时间点恢复)是通过从主数据库中删除要被恢复的表空间,还原一个副本数据库叫作辅助数据库并将其恢复到目标时间点,然后从辅助数据库中将相关的表空间传输到主数据库中.为了便于使用,强烈建议你将辅助数据库和主数据库放在不同的主机上。也还可以在相同主机上执行TSPITR
执行用户管理的表空间按时间点恢复的基本过程如下:
1.将需要执行表空间按时间点恢复的表空间脱机
2.对辅助数据库进行前期设置
3.创建辅助数据库并将其恢复到目标时间点
4.从主数据库中删除要执行表空间按时间点恢复的表空间
5.使用传输表侬间将传输表空间集从辅助数据库传输到主数据库
用户管理的表空间按时间点恢复的准备工作的基本步骤
1.回顾表空间按时间点恢复的要求
在执行TSPITR之前要满足以下条件:
.确保对恢复和辅助集表空间的所有数据文件创建了备份。数据文件备份要在恢复目标时间之前创建
.确保有控制文件备份辅助数据库可以使用。控制文件备份必须满足这些条件:
–控制文件必须是在恢复目标时间之间进行备份的
–控制文件必须使用下面的语句进行备份
alter database backup controlfile to ‘cf_name’;
.确保组成恢复集的所有文件都在辅助数据库的恢复集中,否则在传输表空间的导出步骤阶段会失败。
.在辅助主机上给辅助数据库分配足够的磁盘空间
.提供足够的物理内存启动辅助实例
.如果要被恢复的表空间已经被重命名,确保TSPITR的目标SCN在表空间重命名之后。如果恢复目标时间在重命名之前可以执行数据库按时间点恢复。
2.识别恢复和辅助集表空间的所有数据文件
在你创建辅助数据库之前,连接到主数据库并获得关于主数据库的以下所有信息:
.恢复集表空间所有数据文件的文件名
.system表空间的数据文件名
.undo表空间或包含回滚段表空间的数据文件名
.控制文件名
执行下面的语句可以查询所有数据文件和控制文件名
SQL> SELECT NAME FROM V$DATAFILE 2 UNION ALL 3 SELECT NAME FROM V$CONTROLFILE; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/test/system01.dbf /u01/app/oracle/oradata/test/undotbs01.dbf /u01/app/oracle/oradata/test/sysaux01.dbf /u01/app/oracle/oradata/test/users01.dbf /u01/app/oracle/oradata/test/example01.dbf /u01/app/oracle/oradata/test/tspitr01.dbf /u01/app/oracle/oradata/test/test01.dbf /u01/app/oracle/oradata/test/jy01.dbf /u01/app/oracle/oradata/test/control01.ctl /u01/app/oracle/oradata/test/control02.ctl /u01/app/oracle/oradata/test/control03.ctl
为了判断system和恢复集表空间的数据文件名可以执行类似于下面的语句:
SQL> SELECT t.NAME AS "reco_tbs", d.NAME AS "dbf_name" 2 FROM V$DATAFILE d, V$TABLESPACE t 3 WHERE t.TS# = d.TS# 4 AND t.NAME IN ('SYSTEM', 'TSPITR', 'TEST'); reco_tbs dbf_name ------------------------------ -------------------------------------------------------------------------------- SYSTEM /u01/app/oracle/oradata/test/system01.dbf TSPITR /u01/app/oracle/oradata/test/tspitr01.dbf TEST /u01/app/oracle/oradata/test/test01.dbf
如果数据库运行在手动管理undo模式下,那么执行下面的查询就可显示包含回滚段的表空间的数据文件名
SQL> SELECT DISTINCT r.TABLESPACE_NAME AS "rbs_tbs", d.FILE_NAME AS "dbf_name" 2 FROM DBA_ROLLBACK_SEGS r, DBA_DATA_FILES d 3 WHERE r.TABLESPACE_NAME=d.TABLESPACE_NAME; rbs_tbs dbf_name ------------------------------ -------------------------------------------------------------------------------- SYSTEM /u01/app/oracle/oradata/test/system01.dbf UNDOTBS1 /u01/app/oracle/oradata/test/undotbs01.dbf
如果数据库运行在自动管理undo模式下,那么执行下面的查询就可以显示undo表空间的数据文件名
SQL> SELECT DISTINCT u.TABLESPACE_NAME AS "undo_tbs", d.FILE_NAME AS "dbf_name" 2 FROM DBA_UNDO_EXTENTS u, DBA_DATA_FILES d 3 WHERE u.TABLESPACE_NAME=d.TABLESPACE_NAME; undo_tbs dbf_name ------------------------------ -------------------------------------------------------------------------------- UNDOTBS1 /u01/app/oracle/oradata/test/undotbs01.dbf
3.判断那些对象将会丢失
当对表空间执行TSPITR时,任何在恢复目标时间之后创建的对象都将会丢失。为了判断那些对象将会丢失,查询主数据库中的ts_pitr_objects_to_be_dropped视图。该视图中的owner列,显示的了将会删除的对象的所有者。name列,显示的是当执行TSPITR后丢失对象的对象名。create_time列,显示的是对象创建的时间戳。tablespace_name列,显示的是对象所存储的表空间。
SQL> SELECT OWNER, NAME, TABLESPACE_NAME, 2 TO_CHAR(CREATION_TIME, 'YYYY-MM-DD:HH24:MI:SS') 3 FROM SYS.TS_PITR_OBJECTS_TO_BE_DROPPED 4 WHERE TABLESPACE_NAME IN ('TSPITR','TEST') 5 AND CREATION_TIME > TO_DATE('2015-04-07 12:00:00','YYYY-MM-DD:HH24:MI:SS') 6 ORDER BY TABLESPACE_NAME, CREATION_TIME; no rows selected
4.选择连接辅助实例的方法
要必须能够连接到辅助实例。可以使用Oracle Net或操作系统审计方法
5.为辅助实例创建密码文件
创建密码文件使用orapwd命令,如果不使用密码文件可以跳过这一步
6.为辅助实例创建初始化参数文件
创建一个新的初始化参数文件而不是复制一个再修改。通过对以下参数设置较低的内存来节省内存开销:
.db_cache_size
.shared_pool_size
.large_pool_size
辅助数据库可以与主数据库在相同主机上或者在不同的主机上。因为辅助数据库的数据文件名与主数据库的数据文件名相同,你必须更新辅助控制文件来指定辅助数据库的数据文件。如果辅助数据库与主数据库在同一台主机上,或者辅助数据库与主数据库在不同的主机上但使用不同的路径名,那么必须重命名控制文件,数据文件和联机重做日志文件。如果辅助数据库与主数据库在不同的主机上且使用相同的目录路径,那么只需要重命名联机重做日志文件。通过查看主数据库的联机重做日志文件名所以可以确保在创建辅助数据库时使用唯一的联机重做日志文件名。
SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- /u01/app/oracle/oradata/test/redo02.log /u01/app/oracle/oradata/test/redo03.log /u01/app/oracle/oradata/test/redo01.log
辅助实例初始化参数
db_name:辅助数据库名。该值与主数据库相同
control_files:辅助数据库控制文件。如果辅助数据库与主数据库在相同主机上,确保控制文件名与主数据库的控制文件名不一样。
db_unique_name:就算辅助数据库的值与主数据库相同也允许启动辅助数据库。将它设置成唯一值,例如db_unique_name=aux。这个参数只有辅助数据库与主数据库在相同主机上才需要设置。
db_file_name_convert:使用模式来转换辅助数据库的数据文件名。这个参数只有在与主数据库相同的主要上还原辅助数据库时或者在不同的主机上使用不同的目录路径时才需要。
log_file_name_convert:使用模式来转换辅助数据库的联机重做日志文件名。这个参数是强制性的。
log_archive_dest_1:指定恢复所需要的归档重做日志的缺省目录。这个参数指定辅助主机上的目录。
log_archive_format:指定归档重做日志文件格式。应该使用与主数据库相同的参数值。
在相同主机上通过还原和恢复辅助数据库执行用户管理的TSPITR
下面的例子假设在主数据库test所在主机oracle11g上还原辅助数据库。在这种情况下,主数据库的所有文件都存储在目录/u01/app/oracle/oradata/test目录中,并且想还原辅助数据库到/u02/auxiliary目录中。所以需要设置db_file_name_convert和log_file_name_convert来转换文件名。下面的例子将对数据库test中的表空间tspitr,test执行按时间点恢复,其执行步骤如下:
1.先对主数据库test使用操作系统命令进行备份
[oracle@oracle11g test]$ ls -lrt total 1450748 -rw-r----- 1 oracle oinstall 52436992 Apr 7 15:43 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52436992 Apr 8 09:39 temp01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 08:57 users01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 08:57 tspitr01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 08:57 test01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo03.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo02.log -rw-r----- 1 oracle oinstall 52436992 Apr 9 08:57 jy01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 08:57 example01.dbf -rw-r----- 1 oracle oinstall 293609472 Apr 9 16:02 sysaux01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 16:12 undotbs01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 16:12 system01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:20 redo01.log -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control03.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control01.ctl [oracle@oracle11g test]$ cp *.dbf /u02/backup/ SQL> alter database backup controlfile to '/u02/control.ctl'; Database altered
要注意的是控制文件不能使用操作系统命令cp来创建否则会出现如下错误:
SQL> alter database mount clone database; alter database mount clone database * ERROR at line 1: ORA-01696: control file is not a clone control file [oracle@oracle11g test]$ ls -lrt /u02/backup/ total 1450744 -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:22 control01.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:22 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:22 control03.ctl -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:22 example01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:22 jy01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:22 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo01.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo02.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo03.log -rw-r----- 1 oracle oinstall 293609472 Apr 9 16:23 sysaux01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:23 test01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:23 temp01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 16:23 system01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:23 tspitr01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 16:24 undotbs01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:24 users01.dbf
2.将辅助集和恢复集文件的备份还原到新目录中/u02/auxiliary
[oracle@oracle11g test]$ cp /u02/control.ctl /u02/auxiliary/control01.ctl [oracle@oracle11g test]$ cp /u02/control.ctl /u02/auxiliary/control02.ctl [oracle@oracle11g test]$ cp /u02/control.ctl /u02/auxiliary/control03.ctl [oracle@oracle11g test]$ cp /u02/backup/system01.dbf /u02/auxiliary/ [oracle@oracle11g test]$ cp /u02/backup/sysaux01.dbf /u02/auxiliary/ [oracle@oracle11g test]$ cp /u02/backup/undotbs01.dbf /u02/auxiliary/ [oracle@oracle11g test]$ cp /u02/backup/tspitr01.dbf /u02/auxiliary/ [oracle@oracle11g test]$ cp /u02/backup/test01.dbf /u02/auxiliary/ [oracle@oracle11g test]$ ls -lrt /u02/auxiliary/ total 1077500 -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:29 control03.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:29 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:29 control01.ctl -rw-r----- 1 oracle oinstall 492838912 Apr 9 16:30 system01.dbf -rw-r----- 1 oracle oinstall 293609472 Apr 9 16:31 sysaux01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 16:33 undotbs01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:33 tspitr01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:34 test01.dbf
3.创建参数文件
[oracle@oracle11g auxiliary]$ vi initauxiliary.ora db_name=test db_unique_name=auxiliary sga_max_size=160M sga_target=160M pga_aggregate_target=16M db_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/auxiliary/') log_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/auxiliary/') control_files=('/u02/auxiliary/control01.ctl','/u02/auxiliary/control02.ctl','/u02/auxiliary/control03.ctl') log_archive_dest_1='location=/u02' log_archive_format='%t_%s_%r.dbf' compatible=10.2.0.5.0
4.使用创建的参数文件 将辅助数据库启动到nomount状态
[oracle@oracle11g auxiliary]$ export ORACLE_SID=auxiliary [oracle@oracle11g auxiliary]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 16:46:51 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to an idle instance. SQL> startup nomount pfile='/u02/auxiliary/initauxiliary.ora' ORACLE instance started. Total System Global Area 167772160 bytes Fixed Size 1272624 bytes Variable Size 58721488 bytes Database Buffers 104857600 bytes Redo Buffers 2920448 bytes
5.指定clone关键字来mount辅助数据库
SQL> alter database mount clone database; Database altered.
6.手动重命名所有辅助数据文件只有没有使用db_file_name_convert和log_file_name_convert参数时才需要执行。在这里使用了这两个参数来重命名所有的数据文件和联机重做日志文件。
7.执行以下脚本来确辅助数据库的所有数据文件名命名是否正确
SQL> SELECT NAME FROM V$DATAFILE 2 UNION ALL 3 SELECT MEMBER FROM V$LOGFILE 4 UNION ALL 5 SELECT NAME FROM V$CONTROLFILE; NAME -------------------------------------------------------------------------------- /u02/auxiliary/system01.dbf /u02/auxiliary/undotbs01.dbf /u02/auxiliary/sysaux01.dbf /u02/auxiliary/users01.dbf /u02/auxiliary/example01.dbf /u02/auxiliary/tspitr01.dbf /u02/auxiliary/test01.dbf /u02/auxiliary/jy01.dbf /u02/auxiliary/redo02.log /u02/auxiliary/redo03.log /u02/auxiliary/redo01.log /u02/auxiliary/control01.ctl /u02/auxiliary/control02.ctl /u02/auxiliary/control03.ctl 14 rows selected.
如果不正确在步骤6中手动重命名数据文件
8.将辅助集和恢复集表空间的数据文件设置为联机状态。
SQL> alter database datafile '/u02/auxiliary/system01.dbf' online; Database altered. SQL> alter database datafile '/u02/auxiliary/undotbs01.dbf' online; Database altered. SQL> alter database datafile '/u02/auxiliary/sysaux01.dbf' online; Database altered. SQL> alter database datafile '/u02/auxiliary/tspitr01.dbf' online; Database altered. SQL> alter database datafile '/u02/auxiliary/test01.dbf' online; Database altered.
9.使用using backup controlfile选项将辅助数据库恢复到指定的恢复目标时间点。
SQL> recover database until cancel using backup controlfile; ORA-00279: change 1718118 generated at 04/09/2015 08:57:02 needed for thread 1 ORA-00289: suggestion : /u02/1_13_876413942.dbf ORA-00280: change 1718118 for thread 1 is in sequence #13 Specify log: {=suggested | filename | AUTO | CANCEL} /u01/app/oracle/oradata/test/redo01.log Log applied. Media recovery complete.
10.以resetlogs选项来打开辅助数据库
SQL> alter database open resetlogs; Database altered.
下面就是执行传输表空间的操作
11.使用管理权限连接辅助数据库
[oracle@oracle11g auxiliary]$ export ORACLE_SID=auxiliary [oracle@oracle11g auxiliary]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 20:12:27 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
12.执行alter tablespace … read only语句将执行完按时间点恢复的表空间tspitr,test设置为只读状态
SQL> alter tablespace tspitr read only; Tablespace altered. SQL> alter tablespace test read only; Tablespace altered.
13.对表空间tspitr,test执行自包含检查
SQL> exec sys.dbms_tts.transport_set_check('tspitr,test',true,true); PL/SQL procedure successfully completed. SQL> select * from sys.transport_set_violations; no rows selected
14.使用Oracle导出工具生成传输表空间集的元数据
[oracle@oracle11g ~]$ export ORACLE_SID=auxiliary [oracle@oracle11g u02]$ exp \'sys/jy as sysdba\' transport_tablespace=y tablespaces=tspitr,test tts_full_check=y file=/u02/transport_tablespace.dmp log=/u02/transport_tablespace.log Export: Release 10.2.0.5.0 - Production on Thu Apr 9 20:29:58 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set Note: table data (rows) will not be exported About to export transportable tablespace metadata... For tablespace TSPITR ... . exporting cluster definitions . exporting table definitions . . exporting table TSPITR For tablespace TEST ... . exporting cluster definitions . exporting table definitions . . exporting table TEST . exporting referential integrity constraints . exporting triggers . end transportable tablespace metadata export Export terminated successfully without warnings.
下面将表空间tspitr,test附加到主数据库中
15.连接到主数据库
[oracle@oracle11g ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 21:07:39 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
16.从主数据库中将表空间tspitr,test删除
SQL> drop tablespace tspitr including contents and datafiles; Tablespace dropped. SQL> drop tablespace test including contents and datafiles; Tablespace dropped.
17.将辅助数据库中的恢复集表空间的数据文件复制到主数据库目录/u01/app/oracle/oradata/test中
[oracle@oracle11g auxiliary]$ cp test01.dbf /u01/app/oracle/oradata/test/ [oracle@oracle11g auxiliary]$ cp tspitr01.dbf /u01/app/oracle/oradata/test/ [oracle@oracle11g auxiliary]$ ls -lrt /u01/app/oracle/oradata/test/ total 1450748 -rw-r----- 1 oracle oinstall 52436992 Apr 7 15:43 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo03.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo02.log -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:59 users01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:59 jy01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:59 example01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 17:18 temp01.dbf -rw-r----- 1 oracle oinstall 293609472 Apr 9 21:02 sysaux01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 21:11 undotbs01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 21:11 system01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 21:11 redo01.log -rw-r----- 1 oracle oinstall 10493952 Apr 9 21:11 test01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 21:12 tspitr01.dbf -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:12 control03.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:12 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:12 control01.ctl
18.将传输表空间集中的表空间test,tspitr附加到主数据库test中
[oracle@oracle11g auxiliary]$ export ORACLE_SID=test [oracle@oracle11g auxiliary]$ imp \'sys/zzh_2046 as sysdba\' transport_tablespace=y file=/u02/transport_tablespace.dmp log=/u02/transport_tablespace_dr.log datafiles='/u01/app/oracle/oradata/test/tspitr01.dbf','/u01/app/oracle/oradata/test/test01.dbf' Import: Release 10.2.0.5.0 - Production on Thu Apr 9 21:17:04 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export file created by EXPORT:V10.02.01 via conventional path About to import transportable tablespace(s) metadata... import done in ZHS16GBK character set and AL16UTF16 NCHAR character set . importing SYS's objects into SYS . importing SYS's objects into SYS . importing TSPITR's objects into TSPITR . . importing table "TSPITR" . importing TEST's objects into TEST . . importing table "TEST" . importing SYS's objects into SYS Import terminated successfully without warnings. SQL> SELECT NAME FROM V$DATAFILE 2 UNION ALL 3 SELECT MEMBER FROM V$LOGFILE 4 UNION ALL 5 SELECT NAME FROM V$CONTROLFILE; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/test/system01.dbf /u01/app/oracle/oradata/test/undotbs01.dbf /u01/app/oracle/oradata/test/sysaux01.dbf /u01/app/oracle/oradata/test/users01.dbf /u01/app/oracle/oradata/test/example01.dbf /u01/app/oracle/oradata/test/tspitr01.dbf /u01/app/oracle/oradata/test/test01.dbf /u01/app/oracle/oradata/test/jy01.dbf /u01/app/oracle/oradata/test/redo02.log /u01/app/oracle/oradata/test/redo03.log /u01/app/oracle/oradata/test/redo01.log NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/test/control01.ctl /u01/app/oracle/oradata/test/control02.ctl /u01/app/oracle/oradata/test/control03.ctl 14 rows selected. SQL> select count(*) from tspitr.tspitr; COUNT(*) ---------- 50707 SQL> select count(*) from test.test; COUNT(*) ---------- 50683
19.将辅助数据库中的表空间tspitr,test设置为读写模式
SQL> alter tablespace tspitr read write; Tablespace altered. SQL> alter tablespace test read write; Tablespace altered.
20.使用操作系统工具对恢复的表空间进行备份或者RMAN对整个主数据库进行备份这里不再赘述
在不同的主机使用不同的目录路径还原辅助数据执行用户管理的TSPITR
下面的例子假设在主机jingyong1上创建辅助数据库aux,主数据库test在主机oracle11g上,这里仍然使用db_file_name_covert和log_file_name_convert参数进行数据文件和联机重做日志文件的转换.
1.先对主数据库test使用操作系统命令进行备份
[oracle@oracle11g test]$ ls -lrt total 1450748 -rw-r----- 1 oracle oinstall 52436992 Apr 7 15:43 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52436992 Apr 8 09:39 temp01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 08:57 users01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 08:57 tspitr01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 08:57 test01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo03.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo02.log -rw-r----- 1 oracle oinstall 52436992 Apr 9 08:57 jy01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 08:57 example01.dbf -rw-r----- 1 oracle oinstall 293609472 Apr 9 16:02 sysaux01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 16:12 undotbs01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 16:12 system01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:20 redo01.log -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control03.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 16:21 control01.ctl [oracle@oracle11g test]$ cp *.dbf /u02/backup/ SQL> alter database backup controlfile to '/u02/control.ctl'; Database altered
要注意的是控制文件不能使用操作系统命令cp来创建否则会出现如下错误:
SQL> alter database mount clone database; alter database mount clone database * ERROR at line 1: ORA-01696: control file is not a clone control file [oracle@oracle11g test]$ ls -lrt /u02/backup/ -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:22 example01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:22 jy01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:22 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo01.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo02.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 16:22 redo03.log -rw-r----- 1 oracle oinstall 293609472 Apr 9 16:23 sysaux01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:23 test01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:23 temp01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 16:23 system01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:23 tspitr01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 16:24 undotbs01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:24 users01.dbf
2.将辅助集和恢复集文件的备份和需要的归档重做日志和联机重做日志文件还原到新目录/u02/aux,/u02/archive中
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/backup/*.dbf /u02/aux oracle@192.168.56.2's password: sysaux01.dbf 100% 280MB 7.4MB/s 00:38 system01.dbf 100% 470MB 7.2MB/s 01:05 test01.dbf 100% 10MB 5.0MB/s 00:02 tspitr01.dbf 100% 100MB 7.7MB/s 00:13 undotbs01.dbf 100% 170MB 5.0MB/s 00:34 [oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/control.ctl /u02/aux oracle@192.168.56.2's password: control.ctl 100% 7216KB 7.1MB/s 00:00 [oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/1_11_876413942.dbf /u02/archive oracle@192.168.56.2's password: 1_11_876413942.dbf 100% 5751KB 5.6MB/s 00:01 [oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/1_12_876413942.dbf /u02/archive oracle@192.168.56.2's password: 1_12_876413942.dbf 100% 15MB 14.9MB/s 00:01 [oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u01/app/oracle/oradata/test/*.log /u02/aux oracle@192.168.56.2's password: redo01.log 100% 50MB 8.3MB/s 00:06 redo02.log 100% 50MB 12.5MB/s 00:04 redo03.log 100% 50MB 10.0MB/s 00:05 [oracle@jingyong1 aux]$ ls -lrt total 1216824 -rw-r----- 1 oracle oinstall 293609472 Apr 9 20:43 sysaux01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 20:44 system01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 20:44 test01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 20:44 tspitr01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 20:45 undotbs01.dbf -rw-r----- 1 oracle oinstall 7389184 Apr 9 20:46 control.ctl -rw-r----- 1 oracle oinstall 52429312 Apr 9 20:47 redo01.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 20:47 redo02.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 20:47 redo03.log [oracle@jingyong1 aux]$ ls -lrt /u02/archive/ total 21076 -rw-r----- 1 oracle oinstall 5888512 Apr 9 20:46 1_11_876413942.dbf -rw-r----- 1 oracle oinstall 15657472 Apr 9 20:47 1_12_876413942.dbf
3.创建参数文件
[oracle@jingyong1 aux]$ vi initaux.ora db_name=test db_unique_name=aux sga_max_size=160M sga_target=160M pga_aggregate_target=16M db_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/aux/') log_file_name_convert=('/u01/app/oracle/oradata/test/','/u02/aux/') control_files='/u02/aux/control.ctl' log_archive_dest_1='location=/u02/archive' log_archive_format='%t_%s_%r.dbf' compatible=10.2.0.5.0
4.使用创建的参数文件 将辅助数据库启动到nomount状态
[oracle@jingyong1 ~]$ export ORACLE_SID=aux [oracle@jingyong1 ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 20:56:16 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to an idle instance. SQL> startup nomount pfile='/u02/aux/initaux.ora' ORACLE instance started. Total System Global Area 167772160 bytes Fixed Size 1272624 bytes Variable Size 58721488 bytes Database Buffers 104857600 bytes Redo Buffers 2920448 bytes
5.指定clone关键字来mount辅助数据库
SQL> alter database mount clone database; Database altered.
6.手动重命名所有辅助数据文件只有没有使用db_file_name_convert和log_file_name_convert参数时才需要执行。在这里使用了这两个参数来重命名所有的数据文件和联机重做日志文件。
7.执行以下脚本来确辅助数据库的所有数据文件名命名是否正确
SQL> SELECT NAME FROM V$DATAFILE 2 UNION ALL 3 SELECT MEMBER FROM V$LOGFILE 4 UNION ALL 5 SELECT NAME FROM V$CONTROLFILE; NAME -------------------------------------------------------------------------------- /u02/aux/system01.dbf /u02/aux/undotbs01.dbf /u02/aux/sysaux01.dbf /u02/aux/users01.dbf /u02/aux/example01.dbf /u02/aux/tspitr01.dbf /u02/aux/test01.dbf /u02/aux/jy01.dbf /u02/aux/redo02.log /u02/aux/redo03.log /u02/aux/redo01.log /u02/aux/control.ctl 12 rows selected.
如果不正确在步骤6中手动重命名数据文件
8.将辅助集和恢复集表空间的数据文件设置为联机状态。
SQL> alter database datafile '/u02/aux/system01.dbf' online; Database altered. SQL> alter database datafile '/u02/aux/undotbs01.dbf' online; Database altered. SQL> alter database datafile '/u02/aux/sysaux01.dbf' online; Database altered. SQL> alter database datafile '/u02/aux/tspitr01.dbf' online; Database altered. SQL> alter database datafile '/u02/aux/test01.dbf' online; Database altered.
9.使用using backup controlfile选项将辅助数据库恢复到指定的恢复目标时间点
SQL> recover database until cancel using backup controlfile; ORA-00279: change 1718118 generated at 04/09/2015 08:57:02 needed for thread 1 ORA-00289: suggestion : /u02/archive/1_13_876413942.dbf ORA-00280: change 1718118 for thread 1 is in sequence #13 Specify log: {=suggested | filename | AUTO | CANCEL} /u02/aux/redo01.log Log applied. Media recovery complete.
10.以resetlogs选项来打开辅助数据库
SQL> alter database open resetlogs; Database altered.
下面就是执行传输表空间的操作
11.使用管理权限连接辅助数据库
[oracle@jingyong1 ~]$ export ORACLE_SID=aux [oracle@jingyong1 ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 21:03:23 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
12.执行alter tablespace … read only语句将执行完按时间点恢复的表空间tspitr,test设置为只读状态
SQL> alter tablespace tspitr read only; Tablespace altered. SQL> alter tablespace test read only; Tablespace altered.
13.对表空间tspitr,test执行自包含检查
SQL> exec sys.dbms_tts.transport_set_check('tspitr,test',true,true); PL/SQL procedure successfully completed. SQL> select * from sys.transport_set_violations; no rows selected
14.使用Oracle导出工具生成传输表空间集的元数据
[oracle@jingyong1 u02]$ export ORACLE_SID=aux [oracle@jingyong1 u02]$ exp \'sys/jy as sysdba\' transport_tablespace=y tablespaces=tspitr,test tts_full_check=y file=/u02/tts.dmp log=/u02/tts.log Export: Release 10.2.0.5.0 - Production on Thu Apr 9 21:05:53 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set Note: table data (rows) will not be exported About to export transportable tablespace metadata... For tablespace TSPITR ... . exporting cluster definitions . exporting table definitions . . exporting table TSPITR For tablespace TEST ... . exporting cluster definitions . exporting table definitions . . exporting table TEST . exporting referential integrity constraints . exporting triggers . end transportable tablespace metadata export Export terminated successfully without warnings.
下面将表空间tspitr,test附加到主数据库中
15.连接到主数据库
[oracle@oracle11g ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.5.0 - Production on Thu Apr 9 21:22:32 2015 Copyright (c) 1982, 2010, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
16.从主数据库中将表空间tspitr,test删除
SQL> drop tablespace tspitr including contents and datafiles; Tablespace dropped. SQL> drop tablespace test including contents and datafiles; Tablespace dropped.
17.将辅助数据库中的恢复集表空间的数据文件复制到主数据库目录/u01/app/oracle/oradata/test中
[oracle@oracle11g test]$ scp -r oracle@192.168.56.11:/u02/tts.dmp /u02/ oracle@192.168.56.11's password: tts.dmp 100% 24KB 24.0KB/s 00:00 [oracle@oracle11g test]$ scp -r oracle@192.168.56.11:/u02/aux/tspitr01.dbf /u01/app/oracle/oradata/test/ oracle@192.168.56.11's password: tspitr01.dbf 100% 100MB 6.3MB/s 00:16 [oracle@oracle11g test]$ scp -r oracle@192.168.56.11:/u02/aux/test01.dbf /u01/app/oracle/oradata/test/ oracle@192.168.56.11's password: test01.dbf 100% 10MB 5.0MB/s 00:02 [oracle@oracle11g test]$ ls -lrt total 1450748 -rw-r----- 1 oracle oinstall 52436992 Apr 7 15:43 jy01.dbf.bak -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo03.log -rw-r----- 1 oracle oinstall 52429312 Apr 9 08:57 redo02.log -rw-r----- 1 oracle oinstall 10493952 Apr 9 16:59 users01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 16:59 jy01.dbf -rw-r----- 1 oracle oinstall 104865792 Apr 9 16:59 example01.dbf -rw-r----- 1 oracle oinstall 52436992 Apr 9 17:18 temp01.dbf -rw-r----- 1 oracle oinstall 293609472 Apr 9 21:19 sysaux01.dbf -rw-r----- 1 oracle oinstall 492838912 Apr 9 21:24 system01.dbf -rw-r----- 1 oracle oinstall 178266112 Apr 9 21:25 undotbs01.dbf -rw-r----- 1 oracle oinstall 52429312 Apr 9 21:25 redo01.log -rw-r----- 1 oracle oinstall 104865792 Apr 9 21:25 tspitr01.dbf -rw-r----- 1 oracle oinstall 10493952 Apr 9 21:26 test01.dbf -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:26 control03.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:26 control02.ctl -rw-r----- 1 oracle oinstall 7389184 Apr 9 21:26 control01.ctl [oracle@oracle11g test]$ ls -lrt /u02/ -rw-r--r-- 1 oracle oinstall 24576 Apr 9 21:25 tts.dmp
18.将传输表空间集中的表空间test,tspitr附加到主数据库test中
[oracle@oracle11g auxiliary]$ export ORACLE_SID=test [oracle@oracle11g auxiliary]$ imp \'sys/zzh_2046 as sysdba\' transport_tablespace=y file=/u02/tts.dmp log=/u02/tts_dr.log datafiles='/u01/app/oracle/oradata/test/tspitr01.dbf','/u01/app/oracle/oradata/test/test01.dbf' Import: Release 10.2.0.5.0 - Production on Thu Apr 9 21:27:47 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export file created by EXPORT:V10.02.01 via conventional path About to import transportable tablespace(s) metadata... import done in ZHS16GBK character set and AL16UTF16 NCHAR character set . importing SYS's objects into SYS . importing SYS's objects into SYS . importing TSPITR's objects into TSPITR . . importing table "TSPITR" . importing TEST's objects into TEST . . importing table "TEST" . importing SYS's objects into SYS Import terminated successfully without warnings. SQL> SELECT NAME FROM V$DATAFILE 2 UNION ALL 3 SELECT MEMBER FROM V$LOGFILE 4 UNION ALL 5 SELECT NAME FROM V$CONTROLFILE; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/test/system01.dbf /u01/app/oracle/oradata/test/undotbs01.dbf /u01/app/oracle/oradata/test/sysaux01.dbf /u01/app/oracle/oradata/test/users01.dbf /u01/app/oracle/oradata/test/example01.dbf /u01/app/oracle/oradata/test/tspitr01.dbf /u01/app/oracle/oradata/test/test01.dbf /u01/app/oracle/oradata/test/jy01.dbf /u01/app/oracle/oradata/test/redo02.log /u01/app/oracle/oradata/test/redo03.log /u01/app/oracle/oradata/test/redo01.log /u01/app/oracle/oradata/test/control01.ctl /u01/app/oracle/oradata/test/control02.ctl /u01/app/oracle/oradata/test/control03.ctl 14 rows selected. SQL> select count(*) from tspitr.tspitr; COUNT(*) ---------- 50707 SQL> select count(*) from test.test; COUNT(*) ---------- 50683
19.将辅助数据库中的表空间tspitr,test设置为读写模式
SQL> alter tablespace tspitr read write; Tablespace altered. SQL> alter tablespace test read write; Tablespace altered.
20.使用操作系统工具对恢复的表空间进行备份或者RMAN对整个主数据库进行备份这里不再赘述
Hello very nice blog!! Guy .. Excellent .. Wonderful ..
I will bookmark your blog and take the feeds also? I am glad
to search out a lot of helpful info here within the submit, we need develop more
techniques in this regard, thanks for sharing.
. . . . .
Pretty! This was a really wonderful post. Many thanks for providing these details.
Great post. I was checking constantly this blog and I am impressed!
Extremely helpful info specifically the last part 🙂 I care for such information much.
I was looking for this particular information for a long time.
Thank you and best of luck.
Hey there! I simply want to offer you a big thumbs up for the excellent information you’ve got here on this post.
I am coming back to your blog for more soon.