3、执行基于RMAN的TSPITR
[root@rh6 prod]# mkdir /home/Oracle/prod
存放辅助库文件
[oracle@rh6 ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 24 14:24:46 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=239333010)
执行recover tablespace:
RMAN> recover tablespace tbs1 until time "to_date('2014-06-24 14:08:18','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/home/oracle/prod';
Starting recover at 24-JUN-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 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='nhxv'
建立Auxiliary instance:
initialization parameters used for automatic instance:
db_name=PROD
db_unique_name=nhxv_tspitr_PROD
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/home/oracle/prod
log_archive_dest_1='location=/home/oracle/prod'
#No auxiliary parameter file used
starting up automatic instance PROD
Oracle instance started
Total System Global Area 292278272 bytes
Fixed Size 2212736 bytes
Variable Size 100666496 bytes
Database Buffers 184549376 bytes
Redo Buffers 4849664 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('2014-06-24 14:08:18','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;';
}
通过备份建立Auxiliary database:
executing Memory Script
executing command: SET until clause
Starting restore at 24-JUN-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 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 /dsk4/bak/PROD_10.bak
channel ORA_AUX_DISK_1: piece handle=/dsk4/bak/PROD_10.bak tag=TAG20140624T121907
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/prod/PROD/controlfile/o1_mf_9tl6lyhz_.ctl
Finished restore at 24-JUN-14
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('2014-06-24 14:08:18','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 '|| 'TBS1' ||' 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/prod/tbs1.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;
}
restore 数据到Auxiliary database:
executing Memory Script
executing command: SET until clause
sql statement: alter tablespace TBS1 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 /home/oracle/prod/PROD/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 24-JUN-14
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 /home/oracle/prod/PROD/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/prod/PROD/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /home/oracle/prod/PROD/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/prod/tbs1.dbf
channel ORA_AUX_DISK_1: reading from backup piece /dsk4/bak/PROD_9.bak
channel ORA_AUX_DISK_1: piece handle=/dsk4/bak/PROD_9.bak tag=TAG20140624T121907
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:55
Finished restore at 24-JUN-14
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=851092186 file name=/home/oracle/prod/PROD/datafile/o1_mf_system_9tl6m7sd_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=851092186 file name=/home/oracle/prod/PROD/datafile/o1_mf_undotbs1_9tl6m7x5_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=7 STAMP=851092186 file name=/home/oracle/prod/PROD/datafile/o1_mf_sysaux_9tl6m7vy_.dbf
contents of Memory Script:
{
# set requested point in time
set until time "to_date('2014-06-24 14:08:18','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 "TBS1", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
将Auxiliary database的datafile激活,只需要system、undo、sysaux和要恢复的表空间(tbs1):
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 24-JUN-14
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 25 is already on disk as file /dsk4/arch1/arch_1_25_847900609.log
archived log file name=/dsk4/arch1/arch_1_25_847900609.log thread=1 sequence=25
media recovery complete, elapsed time: 00:00:05
Finished recover at 24-JUN-14
database opened
contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace TBS1 read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/prod''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/home/oracle/prod''";
}
通过Auxiliary database导出恢复的数据:
executing Memory Script
sql statement: alter tablespace TBS1 read only
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/prod''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/home/oracle/prod''
Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_nhxv":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_nhxv" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_nhxv is:
EXPDP> /home/oracle/prod/tspitr_nhxv_69835.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace TBS1:
EXPDP> /u01/app/oracle/oradata/prod/tbs1.dbf
EXPDP> Job "SYS"."TSPITR_EXP_nhxv" successfully completed at 14:32:23
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace TBS1 including contents keep datafiles';
}
在目标库导入要恢复的数据:
executing Memory Script
database closed
database dismounted
Oracle instance shut down
sql statement: drop tablespace TBS1 including contents keep datafiles
Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_nhxv" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_nhxv":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_nhxv" successfully completed at 14:32:55
Import completed
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace TBS1 read write';
sql 'alter tablespace TBS1 offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
sql statement: alter tablespace TBS1 read write
sql statement: alter tablespace TBS1 offline
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
Removing automatic instance
Automatic instance removed
auxiliary instance file /home/oracle/prod/PROD/datafile/o1_mf_temp_9tl6qbyc_.tmp deleted
auxiliary instance file /home/oracle/prod/PROD/onlinelog/o1_mf_3_9tl6q6v9_.log deleted
auxiliary instance file /home/oracle/prod/PROD/onlinelog/o1_mf_2_9tl6q41j_.log deleted
auxiliary instance file /home/oracle/prod/PROD/onlinelog/o1_mf_1_9tl6q1bx_.log deleted
auxiliary instance file /home/oracle/prod/PROD/datafile/o1_mf_sysaux_9tl6m7vy_.dbf deleted
auxiliary instance file /home/oracle/prod/PROD/datafile/o1_mf_undotbs1_9tl6m7x5_.dbf deleted
auxiliary instance file /home/oracle/prod/PROD/datafile/o1_mf_system_9tl6m7sd_.dbf deleted
auxiliary instance file /home/oracle/prod/PROD/controlfile/o1_mf_9tl6lyhz_.ctl deleted
Finished recover at 24-JUN-14
RMAN>
4、恢复完成校验
14:33:44 SCOTT@ prod>conn /as sysdba
Connected.
14:34:17 SYS@ prod>select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
EXAMPLE ONLINE
TBS1 OFFLINE
7 rows selected.
Elapsed: 00:00:00.03
14:34:20 SYS@ prod>alter tablespace tbs1 online;
Tablespace altered.
Elapsed: 00:00:00.24
14:34:30 SYS@ prod>select count(*) from scott.emp1;
COUNT(*)
----------
18
当执行表空间基于时间的恢复,通过使用当前数据文件的镜像副本可以避免转储数据文件,从而提高TSPITR的性能。
建立数据文件镜像的两种方法:
RMAN> backup as copy format='/dsk4/bak/system.bak' datafile 1;
RMAN> copy datafile 2 to '/dsk4/bak/sysaux.bak';
RMAN> configure auxname for datafile 1 to '/dsk4/bak/system.bak';
RMAN> configure auxname for datafile 2 to '/dsk4/bak/sysaux.bak';
RMAN> recover tablespace tbs1 untiltime '2014-06-24 14:08:18' auxiliary destination '/home/oracle/prod';
RMAN> configure auxname for datafile 1 clear;
RMAN> configure auxname for datafile 2 clear;
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-06/103782.htm
