一、 DRS恢复数据原理
DRS数据回滚功能是DDS数据复制技术一个特殊的功能模块,经过多年的不懈努力,现在DRS功能已经成功无缝的集成在DDS软件当中。
DRS数据回滚功能在Target OS平台通过逆向rput(Rollbackput)命令回滚*.dtf(交易文件)到DataBase,轻松在在TargetDataBase重现某一时刻的状态。数据在TargetDataBase重现后,可用exp/imp的方式导出至Source DataBase进行恢复;
DRS数据回滚完成后,可以rrput 命令取消对Target DataBase回滚操作。
原理如下图所示:
利用DRS数据回滚功能回滚源端truncate表的原理如下:
举例来说,比如Source DataBase的做了truncate表AA操作,同步到target DataBases数据库以后,DDS首先会把目标的表AA重命名为表AA.old表(也就是改变表的名称),这样就在targetDataBase 保留了truncate表AA,这样就能够利用DRS数据回滚功能在目标端回滚在源端truncate掉的表。
二、 使用DRS恢复数据
2.1、 全部恢复到指定的交易
具体使用过程,请参考以下使用过程
(1)ddstop停止目标端DDS软件
(2)通过查看msg.log或vshow 命令确认打算恢复的sql语句位于哪个dtf文件,如:
$cd $DDS_DATA
$ vshow -3 10001
--------------10001.dtf.bak
--BEGIN WORK; SCN:0x4dbc9 Time:2007/05/16 14:11:40 OracleVer:169869568
--DROP TABLE ( objn=10279 objp=0 NO Dict)
COMMIT; --SCN:0x4dbf9 Time:2007/05/16 14:11:41 Session:159.11
(3)通过rput命令在目标端数据库恢复该事务:
$ rput -d 10001
PROCESS ALL TABLES.
0516141220[5] TGT DB VER 10
。。。。。。
0516141220[5] ReverseLoad /oracle/dds_t/dt/put0/10001.dtf.bak (LEN=113)
0516141220[5] UNDROP TABLE: ALTER TABLE "AA"."TEST_RB_0" RENAME TO "TEST_RB"
0516141220[5] UNDROP TABLE: MOVE /oracle/dds_t/dt/dict/2827_0-->/oracle/dds_t/dt/dict/2827
0516141220[5] UNDROP TABLE: MOVE /oracle/dds_t/dt/rm/00002827_0-->/oracle/dds_t/dt/rm/00002827
0516141220[5] CY I-0 U-0 D-0 DDL-0 IGN=0 BAD-0 Time:21ms MIN:39s MAX:39s AVG:39s THE:39s
这时可通过在目标端查询恢复后数据的准确性,确认无误后,导出需要在源端恢复的对象和记录,可以通过exp/imp方式将该表数据导入到源端。
(4)通过 rrput命令在目标端数据库反向恢复该事务:
$ rrput -d 10001
PROCESS ALL TABLES.
0516141239[5] TGT DB VER 10
0516141239[5] ReverseLoad /oracle/dds_t/dt/put0/10001.dtf.bak (LEN=113)
0516141239[5] DROP TABLE: ALTER TABLE "AA"."TEST_RB" RENAME TO "TEST_RB_0"
0516141239[5] DROP TABLE: RENAME(/oracle/dds_t/dt/dict/2827->/oracle/dds_t/dt/dict/2827_0)
0516141239[5] DROP TABLE: RENAME(/oracle/dds_t/dt/rm/00002827->/oracle/dds_t/dt/rm/00002827_0)
0516141239[5] CY I-0 U-0 D-0 DDL-1 IGN=0 BAD-0 Time:42ms MIN:58s MAX:58s AVG:58s THE:58s
。。。。。。
(5)在源端导入恢复的对象和记录,恢复操作完成
(6)ddstart启动目标端,增量同步继续正常进行
文件包含多个事务,只恢复到其中的部分交易
使用如下方法操作:
1。源端模拟操作语句,其中包括三个事务(insert表AA,update表BB,delete表CC):
sqlplus aa/aa <<EOF
insert into aa select * from aa;
commit;
update bb set col2='def' where 1=1;
commit;
delete from cc where 1=1;
commit;
EOF
2.在源端的第1步操作后,目标端生成DTF文件$DDS_DATA/dt/put0/28.dtf.bak,使用vshow -3 命令查看:
$ vshow -3 28.dtf.bak |more
-------------- 28.dtf.bak
--BEGIN WORK; SCN:0x7270a Time:2007/05/21 17:31:59 OracleVer:169869568
INSERT INTO "AA"."AA" ("COL1","COL2","COL3","COL4") VALUES ('abc','def','ghi ','
jkl'); --AAACkhAAEAAAAHmAAB
COMMIT; --SCN:0x7270b Time:2007/05/21 17:31:59 Session:134.55
--BEGIN WORK; SCN:0x7270e Time:2007/05/21 17:31:59 OracleVer:169869568
UPDATE "AA"."BB" SET "COL2"='def' WHERE "COL2"='abc' AND "COL1"=100; --AAACkiAAE
AAAAHuAAA
COMMIT; --SCN:0x7270f Time:2007/05/21 17:31:59 Session:134.55
--BEGIN WORK; SCN:0x72711 Time:2007/05/21 17:31:59 OracleVer:169869568
DELETE FROM "AA"."CC" WHERE "COL1"='abc' AND "COL2"=100 AND "COL3"=200; --AAACkj
AAEAAAAH2AAA
COMMIT; --SCN:0x72712 Time:2007/05/21 17:31:59 Session:134.55
3.在目标端使用vshow -7命令按事务分解DTF文件28.dtf.bak:
$ vshow -7 28
-------------- 28.dtf.bak
$ ls -al 000*
-rw------- 1 dds_t oinstall 141 May 21 17:33 00000.dtf.2.2c.b2
-rw------- 1 dds_t oinstall 142 May 21 17:33 00001.dtf.1.1b.85
-rw------- 1 dds_t oinstall 129 May 21 17:33 00002.dtf.3.27.ac
4.在目标端使用vshow -3 命令查看第3步生成的文件,确定需要恢复的sql语句。如只需恢复update 表BB的事务和delete表CC的事务,可确定文件 00001.dtf.1.1b.85和00002.dtf.3.27.ac包含需要恢复的sql语句
$ vshow -3 000* |more
-------------- 00000.dtf.2.2c.b2
--BEGIN WORK; SCN:0x7270a Time:2007/05/21 17:31:59 OracleVer:169869568
INSERT INTO "AA"."AA" ("COL1","COL2","COL3","COL4") VALUES ('abc','def','ghi ','
jkl'); --AAACkhAAEAAAAHmAAB
COMMIT; --SCN:0x7270b Time:2007/05/21 17:31:59 Session:134.55
-------------- 00001.dtf.1.1b.85
--BEGIN WORK; SCN:0x7270e Time:2007/05/21 17:31:59 OracleVer:169869568
UPDATE "AA"."BB" SET "COL2"='def' WHERE "COL2"='abc' AND "COL1"=100; --AAACkiAAE
AAAAHuAAA
COMMIT; --SCN:0x7270f Time:2007/05/21 17:31:59 Session:134.55
-------------- 00002.dtf.3.27.ac
--BEGIN WORK; SCN:0x72711 Time:2007/05/21 17:31:59 OracleVer:169869568
DELETE FROM "AA"."CC" WHERE "COL1"='abc' AND "COL2"=100 AND "COL3"=200; --AAACkj
AAEAAAAH2AAA
COMMIT; --SCN:0x72712 Time:2007/05/21 17:31:59 Session:134.55
5.在目标端使用cat命令修改28.dtf.bak文件,cat文件00001.dtf.1.1b.85和00002.dtf.3.27.ac到28.dtf.bak中,文件之间以空格分开,其中包含需要恢复的update 表BB的事务和delete表CC的事务
$cat 00001.dtf.1.1b.85 00002.dtf.3.27.ac > 28.dtf.bak
6.在目标端使用vshow -3 命令检查第5步修改的DTF文件,确认其中包含的sql语句是需要恢复的:
$ vshow -3 28.dtf.bak |more
-------------- 28.dtf.bak
--BEGIN WORK; SCN:0x7270e Time:2007/05/21 17:31:59 OracleVer:169869568
UPDATE "AA"."BB" SET "COL2"='def' WHERE "COL2"='abc' AND "COL1"=100; --AAACkiAAE
AAAAHuAAA
COMMIT; --SCN:0x7270f Time:2007/05/21 17:31:59 Session:134.55
--BEGIN WORK; SCN:0x72711 Time:2007/05/21 17:31:59 OracleVer:169869568
DELETE FROM "AA"."CC" WHERE "COL1"='abc' AND "COL2"=100 AND "COL3"=200; --AAACkj
AAEAAAAH2AAA
COMMIT; --SCN:0x72712 Time:2007/05/21 17:31:59 Session:134.55
7.ddstop停止目标端DDS软件
8.通过rput命令在目标端数据库恢复这两个事务:
$ rput -d 28
PROCESS ALL TABLES.
0521173903[5] TGT DB VER 10
0521173903[5] ReverseLoad /oracle/dds_t/dt/put0/28.dtf.bak (LEN=271)
0521173904[5] CY I-1 U-1 D-0 DDL-0 IGN=0 BAD-0 Time:253ms MIN:425s MAX:425s AVG:425s THE:425s
这时可通过在目标端查询恢复后数据的准确性,确认无误后,导出需要在源端恢复的对象或记录
9.通过 rrput命令在目标端数据库反向恢复这两个事务:
$ rrput -d 28
PROCESS ALL TABLES.
0521182259[5] TGT DB VER 10
0521182259[5] ReverseLoad /oracle/dds_t/dt/put0/28.dtf.bak (LEN=271)
0521182259[5] CY I-0 U-1 D-1 DDL-0 IGN=0 BAD-0 Time:257ms MIN:44s MAX:44s AVG:44s THE:44s
10.ddstart启动目标端,增量同步继续正常进行
2.3、 指定表恢复到指定的交易
这种方式也包含该事务包含了多个dtf文件中的情况。使用如下方法操作:
1。源端模拟操作语句:
SQL> delete from dd where rownum<40000;
39999 rows deleted.
SQL> commit;
Commit complete.
2。在源端的第1步操作后,目标端生成$DDS_DATA/dt/put0/83.dtf.bak和$DDS_DATA/dt/put0/84.dtf.bak两个DTF文件,使用vshow -3 命令查看:
$ vshow -3 83.dtf.bak |more
-------------- 83.dtf.bak
--BEGIN WORK; SCN:0x81be4 Time:2007/05/22 10:59:56 OracleVer:169869568
DELETE FROM "AA"."DD" WHERE "OWNER"='SYS' AND "OBJECT_NAME"='ALERT_QUE' AND "SUB
OBJECT_NAME"=NULL AND "OBJECT_ID"=8809 AND "DATA_OBJECT_ID"=NULL AND "OBJECT_TYP
E"='QUEUE' AND "CREATED"=TO_DATE('20070513201409','YYYYMMDDHH24MISS') AND "LAST_
DDL_TIME"=TO_DATE('20070513201546','YYYYMMDDHH24MISS') AND "TIMESTAMP"='2007-05-
13:20:15:46' AND "STATUS"='VALID' AND "TEMPORARY"='N' AND "GENERATED"='N' AND "S
ECONDARY"='N'; --AAACkrAAEAAAAeCAA4
....................................................................................................................................................................................................................................
DELETE FROM "AA"."DD" WHERE "OWNER"='PUBLIC' AND "OBJECT_NAME"='AWRSQRPT_TEXT_TYPE_TABLE' AND "SUBOBJECT_NAME"=NULL AND "OBJECT_ID"=9167 AND "DATA_OBJECT_ID"=NULL AND "OBJECT_TYPE"='SYNONYM' AND "CREATED"=TO_DATE('20070513201419','YYYYMMDDHH24MISS') AND "LAST_DDL_TIME"=TO_DATE('20070513201419','YYYYMMDDHH24MISS') AND "TIMESTAMP"='2007-05-13:20:14:19' AND "STATUS"='VALID' AND "TEMPORARY"='N' AND "GENERATED"='N' AND "SECONDARY"='N'; --AAACkrAAEAAAAjKAAL
$ vshow -3 84.dtf.bak|more
-------------- 84.dtf.bak
--BEGIN WORK; SCN:0x81be4 Time:2007/05/22 10:59:56 OracleVer:169869568
DELETE FROM "AA"."DD" WHERE "OWNER"='SYS' AND "OBJECT_NAME"='AWRRPT_NUM_ARY' AND
"SUBOBJECT_NAME"=NULL AND "OBJECT_ID"=9168 AND "DATA_OBJECT_ID"=NULL AND "OBJEC
T_TYPE"='TYPE' AND "CREATED"=TO_DATE('20070513201419','YYYYMMDDHH24MISS') AND "L
AST_DDL_TIME"=TO_DATE('20070513201419','YYYYMMDDHH24MISS') AND "TIMESTAMP"='2007
-05-13:20:14:19' AND "STATUS"='VALID' AND "TEMPORARY"='N' AND "GENERATED"='N' AN
D "SECONDARY"='N'; --AAACkrAAEAAAAjKAAM
....................................................................................................................................................................................................................................
DELETE FROM "AA"."DD" WHERE "OWNER"='PUBLIC' AND "OBJECT_NAME"='GV$LOGSTDBY_TRANSACTION' AND "SUBOBJECT_NAME"=NULL AND "OBJECT_ID"=7292 AND "DATA_OBJECT_ID"=NULL AND "OBJECT_TYPE"='SYNONYM' AND "CREATED"=TO_DATE('20070513201244','YYYYMMDDHH24MISS') AND "LAST_DDL_TIME"=TO_DATE('20070513201244','YYYYMMDDHH24MISS') AND "TIMESTAMP"='2007-05-13:20:12:44' AND "STATUS"='VALID' AND "TEMPORARY"='N' AND "GENERATED"='N' AND "SECONDARY"='N'; --AAACkrAAEAAAAl9AAP
COMMIT; --SCN:0x822a4 Time:2007/05/22 11:00:15 Session:159.78
3。ddstop停止目标端DDS软件
4.在目标端数据库恢复这个事务至83.dtf.bak这个DTF文件,并且只恢复与表DD有关的操作,其余操作不做处理(本例中85.dtf.bak 没有恢复):
$ rput -d 83 -t aa.dd
PROCESS OBJ# 0 = 10539
0522114810[5] TGT DB VER 10
0522114810[5] ReverseLoad /oracle/dds_t/dt/put0/85.dtf.bak (LEN=111)
0522114810[5] CY I-0 U-0 D-0 DDL-0 IGN=0 BAD-0 Time:0ms MIN:730s MAX:730s AVG:730s THE:730s
0522114810[5] ReverseLoad /oracle/dds_t/dt/put0/84.dtf.bak (LEN=1734424)
0522114811[5] CY I-14193 U-0 D-0 DDL-0 IGN=0 BAD-0 Time:966ms MIN:730s MAX:753s AVG:741s THE:753s
0522114811[5] ReverseLoad /oracle/dds_t/dt/put0/83.dtf.bak (LEN=3145851)
0522114815[5] CY I-25806 U-0 D-0 DDL-0 IGN=0 BAD-0 Time:3952ms MIN:730s MAX:757s AVG:746s THE:757s
这时可通过在目标端查询恢复后数据的准确性,确认无误后,导出需要在源端恢复的对象或记录
5.在目标端数据库开始反向恢复这个事务至83.dtf.bak这个DTF文件,并且只反向恢复与表DD有关的操作,其余操作不做处理(本例中85.dtf.bak没有反向恢复)::
$rrput -d 83 -t aa.dd
PROCESS OBJ# 0 = 10539
0522115138[5] TGT DB VER 10
0522115138[5] ReverseLoad /oracle/dds_t/dt/put0/83.dtf.bak (LEN=3145851)
0522115139[5] CY I-0 U-0 D-25806 DDL-0 IGN=0 BAD-0 Time:1130ms MIN:961s MAX:961s AVG:961s THE:961s
0522115139[5] ReverseLoad /oracle/dds_t/dt/put0/84.dtf.bak (LEN=1734424)
0522115140[5] CY I-0 U-0 D-14193 DDL-0 IGN=0 BAD-0 Time:670ms MIN:961s MAX:962s AVG:961s THE:962s
0522115140[5] ReverseLoad /oracle/dds_t/dt/put0/85.dtf.bak (LEN=111)
0522115140[5] CY I-0 U-0 D-0 DDL-0 IGN=0 BAD-0 Time:1ms MIN:940s MAX:962s AVG:954s THE:940s
6.ddstart启动目标端,增量同步继续正常进行