RMAN TSPITR 使用rman进行表空间基于时间点的恢复

实例说明:

      (1)先创建2个表空间。

create tablespace user01  datafile '+DG1' size 1M;


create tablespace user02  datafile '+DG1' size 1M;

 

      (2)在每个表空间上各创建一张表。

create table scott.customers
 (cust_id int,cust_name varchar2(10)) tablespace user01;


create table scott.sales
 (id int,cust_name varchar2(10),sales_amount number(8,2)) tablespace user02;

 

      (3)在每个表中插入2条记录,提交。检查当前的时间点,待会表空间user01要恢复到当前时间点。

 insert into scott.customers values(1,'SOCTT');
insert into scott.customers values(2,'SMITH');
insert into scott.sales values(1,'SCOTT',8000);
insert into scott.sales values(1,'SMITH',10000);

COMMIT;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;

 

date
2010年 03月 11日 星期四 21:44:52 CST

 

      (4) truncate 表1,往表2中插入2条记录。在表空间1中再创建一个表。

truncate table scott.customers;
insert into scott.sales values(3,'SCOTT',6000);
insert into scott.sales values(4,'BLAKE',6700);
commit;

create table scott.employee(id int,name varchar2(10)) tablespace user01;

 

      (5) 利用rman进行表空间1基于时间点的恢复。

--rman部分恢复表空间
recover tablespace user01
 until time "to_timestamp('2010-03-11 21:44:52','yyyy-mm-dd hh24:mi:ss')"
 auxiliary destination '/home/oracle/backup';

 

      (6)将表空间user01 联机, 检查表1的数据是否找回来,检查表2的数据是否是4条,检查新创建的表是否已经不存在。

alter tablespace user01 online;

 

 select * from scott.customers;

       CUST_ID CUST_NAME
---------- ----------
         1 SOCTT
         2 SMITH

select * from scott.sales;

         ID CUST_NAME  SALES_AMOUNT
---------- ---------- ------------
         1 SCOTT              8000
         1 SMITH             10000
         3 SCOTT              6000
         4 BLAKE              6700

 

select * from dba_tables where owner = 'SCOTT' and table_name='EMPLOYEE';

 no rows selected

 一切如我们所愿,此时,表空间不完全恢复完成。

 

注意:

只有自包含的表空间,才能基於单独不完全恢复。所谓自包含,是指该表空间中的对象不依赖于其它表空间中的对象,如该表空间中索引的基本在其它表空间,该表中某些表的lob列放在其它表空间。

如在上例中,执行:

create index scott.idx_customers on scott.customers(cust_name) tablespace user02;

begin
       dbms_tts.transport_set_check('user02',true);
end;

select * from transport_set_violations;

会提示:Index SCOTT.IDX_CUSTOMERS in tablespace USER02 points to table SCOTT.CUSTOMERS in tablespace USER01.

begin
       dbms_tts.transport_set_check('USER01,user02',true);
end;

select * from transport_set_violations;

不会有任何提示,因为user01/user02表空间作为一个集合,是自包含的。

 

 

上面这个过程看起来简单,但是数据库在步骤5时,自己做了很多的工作,所有以前人工需要做的它一步也没有少做,具体如下:

(1)建立参数文件

(2)启动辅助instance到nomount状态

(3)恢复辅助instance控制文件

(4)启动辅助instance到mount,restore表空间对应的数据文件及辅助文件(表空间system和undo的文件)

(5)将上面的几个数据文件online,恢复表空间user01,system和undo

(6)open 辅助数据库(resetlogs)

(7)exp 导出表空间user01;

(8)关闭辅助库

(9)imp 表空间user01;

(10)删除辅助库对应的数据文件及其它文件。

下面贴上恢复表空间user01时rman的log:

Starting recover at 11-MAR-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=158 devtype=DISK

Creating automatic instance, with SID='pudo'

initialization parameters used for automatic instance:
db_name=TESTASM
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TESTASM_pudo
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/home/oracle/backup
control_files=/home/oracle/backup/cntrl_tspitr_TESTASM_pudo.f


starting up automatic instance TESTASM

Oracle instance started

Total System Global Area     205520896 bytes

Fixed Size                     1218508 bytes
Variable Size                146802740 bytes
Database Buffers              50331648 bytes
Redo Buffers                   7168000 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  time "to_timestamp('2010-03-11 21:44:52','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 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 11-MAR-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 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 +RECOVERYDEST/testasm/autobackup/2010_03_11/s_713395242.273.713395243
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=+RECOVERYDEST/testasm/autobackup/2010_03_11/s_713395242.273.713395243 tag=TAG20100311T212042
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:17
output filename=/home/oracle/backup/cntrl_tspitr_TESTASM_pudo.f
Finished restore at 11-MAR-10

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
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  time "to_timestamp('2010-03-11 21:44:52','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 '||  'USER01' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# 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  8 to
 "+DG1/testasm/datafile/user01.271.713395239";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 8;
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  8 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "USER01", "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

sql statement: alter tablespace USER01 offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 11-MAR-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK

creating datafile fno=8 name=+DG1/testasm/datafile/user01.271.713395239
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 /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece +RECOVERYDEST/testasm/backupset/2010_03_11/nnndf0_tag20100311t132659_0.266.713366821
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=+RECOVERYDEST/testasm/backupset/2010_03_11/nnndf0_tag20100311t132659_0.266.713366821 tag=TAG20100311T132659
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
Finished restore at 11-MAR-10

datafile 1 switched to datafile copy
input datafile copy recid=4 stamp=713397364 filename=/home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_system_5skxkgkz_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=5 stamp=713397364 filename=/home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_undotbs1_5skxkgo1_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  8 online

Starting recover at 11-MAR-10
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 14 is already on disk as file +DG1/testasm/1_14_713269994.dbf
archive log thread 1 sequence 15 is already on disk as file +DG1/testasm/1_15_713269994.dbf
archive log thread 1 sequence 16 is already on disk as file +DG1/testasm/1_16_713269994.dbf
archive log thread 1 sequence 17 is already on disk as file +DG1/testasm/1_17_713269994.dbf
archive log thread 1 sequence 18 is already on disk as file +DG1/testasm/1_18_713269994.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=9
channel ORA_AUX_DISK_1: reading from backup piece +RECOVERYDEST/testasm/backupset/2010_03_11/annnf0_tag20100311t132929_0.268.713366971
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=+RECOVERYDEST/testasm/backupset/2010_03_11/annnf0_tag20100311t132929_0.268.713366971 tag=TAG20100311T132929
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/opt/oracle/product/10g/dbs/arch1_9_713269994.dbf thread=1 sequence=9
channel clone_default: deleting archive log(s)
archive log filename=/opt/oracle/product/10g/dbs/arch1_9_713269994.dbf recid=13 stamp=713397376
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=10
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=11
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=12
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=13
channel ORA_AUX_DISK_1: reading from backup piece +RECOVERYDEST/testasm/backupset/2010_03_11/annnf0_tag20100311t195513_0.270.713390115
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=+RECOVERYDEST/testasm/backupset/2010_03_11/annnf0_tag20100311t195513_0.270.713390115 tag=TAG20100311T195513
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/opt/oracle/product/10g/dbs/arch1_10_713269994.dbf thread=1 sequence=10
channel clone_default: deleting archive log(s)
archive log filename=/opt/oracle/product/10g/dbs/arch1_10_713269994.dbf recid=14 stamp=713397378
archive log filename=/opt/oracle/product/10g/dbs/arch1_11_713269994.dbf thread=1 sequence=11
channel clone_default: deleting archive log(s)
archive log filename=/opt/oracle/product/10g/dbs/arch1_11_713269994.dbf recid=17 stamp=713397379
archive log filename=/opt/oracle/product/10g/dbs/arch1_12_713269994.dbf thread=1 sequence=12
channel clone_default: deleting archive log(s)
archive log filename=/opt/oracle/product/10g/dbs/arch1_12_713269994.dbf recid=16 stamp=713397379
archive log filename=/opt/oracle/product/10g/dbs/arch1_13_713269994.dbf thread=1 sequence=13
channel clone_default: deleting archive log(s)
archive log filename=/opt/oracle/product/10g/dbs/arch1_13_713269994.dbf recid=15 stamp=713397378
archive log filename=+DG1/testasm/1_14_713269994.dbf thread=1 sequence=14
archive log filename=+DG1/testasm/1_15_713269994.dbf thread=1 sequence=15
archive log filename=+DG1/testasm/1_16_713269994.dbf thread=1 sequence=16
archive log filename=+DG1/testasm/1_17_713269994.dbf thread=1 sequence=17
archive log filename=+DG1/testasm/1_18_713269994.dbf thread=1 sequence=18
media recovery complete, elapsed time: 00:00:05
Finished recover at 11-MAR-10

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =/"/@/(DESCRIPTION=/(ADDRESS=/(PROTOCOL=beq/)/(PROGRAM=/opt/oracle/product/10g/bin/oracle/)/(ARGV0=oraclepudo/)/(ARGS=^'/(DESCRIPTION=/(LOCAL=YES/)/(ADDRESS=/(PROTOCOL=beq/)/)/)^'/)/(ENVS=^'ORACLE_SID=pudo^'/)/)/(CONNECT_DATA=/(SID=pudo/)/)/) as sysdba/" point_in_time_recover=y tablespaces=
 USER01 file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =/"/@ as sysdba/" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace  USER01 online";
sql "alter tablespace  USER01 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.1.0 - Production on Thu Mar 11 21:56:42 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace USER01 ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                      CUSTOMERS
. 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.1.0 - Production on Thu Mar 11 21:57:10 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing SYS's objects into SYS
. importing SCOTT's objects into SCOTT
. . importing table                    "CUSTOMERS"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace  USER01 online

sql statement: alter tablespace  USER01 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 /home/oracle/backup/cntrl_tspitr_TESTASM_pudo.f deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_system_5skxkgkz_.dbf deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_undotbs1_5skxkgo1_.dbf deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/datafile/o1_mf_temp_5skxnl1l_.tmp deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/onlinelog/o1_mf_1_5skxnbh2_.log deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/onlinelog/o1_mf_2_5skxnd3n_.log deleted
auxiliary instance file /home/oracle/backup/TSPITR_TESTASM_PUDO/onlinelog/o1_mf_3_5skxnfvw_.log deleted
Finished recover at 11-MAR-10

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章