RMAN表空间按时间点恢复(三)

重命名TSPITR辅助集数据文件
不像恢复集数据文件通常会被存储在它们原始目录中,辅助集数据文件不能覆盖目标数据库中相关文件。如果不对辅助集文件指定一个新目录而是使用原始目录,那么当RMAN试图覆盖原始目录中的相关文件时,会发现这些文件正在使用,那么TSPITR操作会失败。

为辅助集数据文件指定目录最简单的方法是为TSPITR指定一个辅助目录。然而RMAN支持两种方法来控制辅助集数据文件的目录:一是使用set newname来对单个文件指定新文件名,二是使用db_file_name_convert参数提将目标数据库中的数据文件名转换为辅助数据库中的数据文件名。

尽管你打算使用这些方法来给特定文件指定目录,仍然建议你给recover tablespace命令使用auxliary destination参数。如果你忽略了重命名一些辅助集数据文件,这将确保TSPITR操作仍然执行成功。存储在辅助目录中的任何文件不会被重命名。

使用set newname来重命名TSPITR辅助集数据文件
为了使用set newname命令来为辅助集数据文件指定新的文件名,在RUN块中使用recover tablespace命令,并且使用set newname命令来重命名文件。例如,下面我们对表空间tspitr执行tspitr将表空间恢复到logseq=32的时间点,并使用set newname将辅助集中的数据文件’ /u01/app/oracle/oradata/test/system01.dbf’重命名为’ /u01/app/oracle/oradata/auxiliary/system01.dbf’:

再次对表tspitr执行truncate操作:

SQL> truncate table tspitr;

Table truncated.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
         0

执行恢复命令

RMAN> run
2> {
3> set newname for datafile '/u01/app/oracle/oradata/test/system01.dbf' to '/u01/app/oracle/oradata/auxiliary/system01.dbf';
4> recover tablespace tspitr until logseq 32 auxiliary destination '/u01/app/oracle/oradata/auxiliary';
5> }

executing command: SET NEWNAME

Starting recover at 2015-03-16 19:34:58
using channel ORA_DISK_1

Creating automatic instance, with SID='pqny'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_pqny
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle/oradata/auxiliary
control_files=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  logseq 32 thread 1;
# 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 until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-16 19:34:59
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp tag=TAG20150316T103739
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f
Finished restore at 2015-03-16 19:35:02

sql statement: alter database mount clone database

sql statement: alter system archive log current

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

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 32 thread 1;
# set a destination filename for restore
set newname for datafile  1 to
 "/u01/app/oracle/oradata/auxiliary/system01.dbf";
# 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  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 6;
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  6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due 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";
}
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 temporary file 1 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-16 19:35:09
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/auxiliary/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492578_361
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:07
Finished restore at 2015-03-16 19:36:18

datafile 1 switched to datafile copy
input datafile copy recid=19 stamp=874524979 filename=/u01/app/oracle/oradata/auxiliary/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=20 stamp=874524979 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_bjfhzg5k_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  6 online

Starting recover at 2015-03-16 19:36:21
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 31 is already on disk as file /u02/1_31_870806981.dbf
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=30
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492656_371
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf thread=1 sequence=30
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf recid=38 stamp=874524983
archive log filename=/u02/1_31_870806981.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:03
Finished recover at 2015-03-16 19:36:27

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclepqny\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=pqny^'\)\)\(CONNECT_DATA=\(SID=pqny\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
 TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"sys/zzh_2046@test as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace  TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog after tspitr finished
resync catalog;
}
executing Memory Script


Export: Release 10.2.0.5.0 - Production on Mon Mar 16 19:36:56 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 Tablespace Point-in-time Recovery objects...
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.5.0 - Production on Mon Mar 16 19:37:17 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 Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing TSPITR's objects into TSPITR
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace TSPITR online

sql statement: alter tablespace  TSPITR offline

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

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/system01.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_bjfhzg5k_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_temp_bjfj2d21_.tmp deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_1_bjfj1w22_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_2_bjfj1z44_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_3_bjfj249p_.log deleted
Finished recover at 2015-03-16 19:37:26

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         OFFLINE

7 rows selected.

RMAN> sql 'alter tablespace tspitr online';

sql statement: alter tablespace tspitr online
starting full resync of recovery catalog
full resync complete

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         ONLINE

7 rows selected.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

从上面的结果可以看到对表空间tspitr恢复成功。

使用db_file_name_convert来重命名辅助集数据文件
如果不想对所有辅助集数据文件使用一个辅助目录,但也不想为每个文件单独命名,可以在辅助实例中设置db_file_name_convert参数。只有在以下两种情况下使用这个参数:
1.如果会为RMAN自动管理辅助实例创建自己的参数文件。
2.如果将要创建单独的辅助实例。
在辅助实例中的db_file_name_convert参数的作用是用来根据目标实例相关文件的原始文件名在辅助实例中生成相应的文件名。这个参数值由字符对列表组成。
例如,假设目标实例包含以下文件:
.system表空间中的/u01/app/oracle/oradata/test/system01.dbf
.undotbs表空间中的/u01/app/oracle/oradata/test/undotbs01.dbf

并且想将这些相关文件重新存储在辅助实例的’/u01/app/oracle/oradata/auxiliary ‘目录中,那么在辅助实例参数文件中增加以下记录:
DB_FILE_NAME_CONVERT=(‘/u01/app/oracle/oradata/test/ ‘, ‘/u01/app/oracle/oradata/auxiliary ‘)

在辅助实例中相关文件的新文件名就是如下形式:
/u01/app/oracle/oradata/auxiliary /system01.dbf和/u01/app/oracle/oradata/auxiliary /undotbs01.dbf

最重要的是要记住db_file_name_convert参数必须在辅助实例参数文件中进行设置。

如果辅助实例是手动创建的,将db_file_name_convert参数加入到辅助实例参数文件中。

注意仍然可以使用set newname或configure auxname来重命名单个辅助集数据文件。如果文件不匹配由db_file_name_convert参数所提供的匹配模式,那么文件是不会被重命名的。可以使用有auxiliary destination参数的recover tablespace命令来确保所有辅助集数据文件被发送到指定目录中。如果没有对辅助实例中的文件提供新文件名的命名方法,那么执行TSPITR将会失败。

使用db_file_name_convert重命名ASM OMF数据文件
当目标实例使用OMF管理数据文件对于辅助实例使用db_file_name_convert参数不能被用来控制文件的新文件名。当目标实例使用OMF管理数据文件时,通过替目标实例OMF文件名的相应字符串不能在辅助实例上生成有效的OMF文件名。当使用ASM OMF管理数据文件时,RMAN会将这些无效的文件名转换为有效的文件名。

为了避免这个问题,使用其它的支持选项来为OMF文件生成新文件名(包括存储在ASM中的数据文件):
1.使用辅助目录
2.在辅助实例中使用db_create_file_dest参数来为没有使用set newname或configure auxname指定新文件名的所有辅助实例文件指定目录
3.对于ASM文件,可以使用set newname为单个文件指定辅助实例可以访问的磁盘组(并允许数据库使用指定的磁盘组生成文件名)。例如:

RUN {
SET NEWNAME FOR DATAFILE 1 TO "+DISK2";
SET NEWNAME FOR DATAFILE 2 TO "+DISK3";
RECOVER TABLESPACE users, tools
UNTIL LOGSEQ 1300 THREAD 1
AUXILIARY DESTINATION '/disk1/auxdest';
}

执行TSPITR时重命名临时文件
临时文件被认为数据库辅助集的一部分。当创建辅助实例时,可以使用set newname for tempfile,db_file_name_convert或auxiliary destination来重命名临时文件。当打开辅助数据库时,会使用适用的重命名规则来创建临时文件。当清除辅助实例时,临时文件会和其它的辅助实例文件一起被删除。

TSPITR文件重命名方法之间的优先顺序
不同的重命名文件方法遵守以下的优先顺序:
1.set newname
2.configure auxname
3.db_file_name_convert
4.recover tablespace命令中的auxiliary destination参数

在同时使用几种重命名文件方法时,优先级高的会覆盖优先级低的重命名方法(例如,在目标数据库上执行recover tablespace … auxiliary destination时,也使用configure auxname为一些辅助集数据文件重命名文件名时,configure auxname会覆盖recover tablespace … auxiliary destination)。
可以使用show auxname命令来查看任何当前的configure auxname设置。

设置辅助实例控制文件目录
如果使用客户端参数文件可以为辅助实例设置控制文件目录。可以设置control_files参数来指定你要存储控制文件的目录。

如果没有为控制文件显式地指定目录,如果在执行TSPITR时使用了auxiliary destination参数,RMAN将会把控制文件存放在辅助目录中。如果在执行TSPITR时没有使用auxiliary destination参数,辅助实例控制文件将会存储在操作系统特定目录中(在Unix中,ORACLE_HOME/rdbms/admin/params_auxinit.ora)

不管将辅助实例控制文件存储在什么目录中,在TSPITR操作成功执行完后都是会被删除的。因为控制文件相对较小,RMAN在创建辅助控制文件遇到错误的概率是很小的,但如果创建控制文件的目录没有足够的空间,TSPITR操作将会失败。

设置辅助实例联机重做日志目录
如果在辅助实例参数文件中设置了log_file_name_convert参数,这个参数将会决定联机重做日志文件的存储目录。否则,如果RMAN正使用辅助目录和管理辅助实例,将会在辅助目录中创建联机重做日志文件。
注意,如果没有使用log_file_name_convert或auxiliary destination来指定联机重做日志文件目录,在试图创建联机重做日志文件时TSPITR操作会失败。即使在参数文件中设置了db_file_create_dest或者log_file_create_dest参数,在执行TSPITR时也不会对辅助实例创建联机重做日志文件。

使用log_file_name_convert重命名ASM OMF重做日志文件
当目标实例使用OMF时,在辅助实例中设置log_file_name_convert参数不能用来为重做日志文件生成新文件名。当目标实例使用OMF时,不能通过替换目标实例OMF文件名中的相关字符串来为辅助实例生成有效的OMF文件名。当使用ASM OMF时,RMAN在指定磁盘组中使用模式匹配的磁盘组名来生成有效的文件名。

为了避免这种问题,可以使用其它支持的方法为OMF重做日志文件生成新文件名(包括存储在ASM中的文件):
1.使用辅助目录
2.在辅助实例中设置db_create_file_dest,db_recovery_file_dest或db_create_online_log_dest_n参数来指定目录

发表评论

电子邮件地址不会被公开。