生产环境中万一对生产数据进行了误操作,这个时候有没有什么技术能够进行紧急回滚?
一>备份没执行脱敏脚本之前的数据
select * from cr_dw as of timestamp to_timestamp('20190311 16:03:00','yyyymmdd hh24:mi:ss');
----正常 牵涉到字段: dwmc,jbrxm,dwfrdbxm,dwdz
create table cr_dwBackUp as select * from cr_dw as of timestamp to_timestamp('20190311 16:03:00','yyyymmdd hh24:mi:ss');
select count(*) from cr_dwBackUp;
select * from cr_gr as of timestamp to_timestamp('20190311 16:02:00','yyyymmdd hh24:mi:ss');
----正常 牵涉到字段: xingming,sjhm
create table cr_grBackUp as select * from cr_gr as of timestamp to_timestamp('20190311 16:02:00','yyyymmdd hh24:mi:ss');
select count(*) from grdk_sq_htxx as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');
----正常 牵涉到字段: jkrxm,lxdh,fwzl
create table grdk_sq_htxxBackUp as select * from grdk_sq_htxx as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');
select * from grdk_sq_gtjkr as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');
----正常 牵涉到字段: gtjkrxm
create table grdk_sq_gtjkrBackUp as select * from grdk_sq_gtjkr as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');
select * from im_gryhzh as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');----83942
----正常 牵涉到字段: zhhm
create table im_gryhzhBackUp as select * from im_gryhzh as of timestamp to_timestamp('20190311 16:05:00','yyyymmdd hh24:mi:ss');
select * from grdk_sq_dbxx as of timestamp to_timestamp('20190311 16:03:00','yyyymmdd hh24:mi:ss');
----正常 牵涉到字段: dywfwzl,dywsyrtxdz,dywsyr,dywsyrpo,dywsyryddh,dywsyrpoyddh
create table grdk_sq_dbxxBackUp as select * from grdk_sq_dbxx as of timestamp to_timestamp('20190311 16:03:00','yyyymmdd hh24:mi:ss');
二>备份执行脱敏脚本之后的数据
select * from cr_dw;
select count(*) from cr_dw;----8062行
create table cr_dwZhiXingHou as select * from cr_dw;
select * from cr_gr;
select count(*) from cr_gr;-----414530行
create table cr_grZhiXingHou as select * from cr_gr;
select * from grdk_sq_htxx;
select count(*) from grdk_sq_htxx;----77989行
create table grdk_sq_htxxZhiXingHou as select * from grdk_sq_htxx;
select * from grdk_sq_gtjkr;
select count(*) from grdk_sq_gtjkr;----51784行
create table grdk_sq_gtjkrZhiXingHou as select * from grdk_sq_gtjkr;
select * from im_gryhzh;
select count(*) from im_gryhzh;-------83943行
create table im_gryhzhZhiXingHou as select * from im_gryhzh;
select * from grdk_sq_dbxx;
select count(*) from grdk_sq_dbxx;-----30489行
create table grdk_sq_dbxxZhiXingHou as select * from grdk_sq_dbxx;
三>用expdp统一备份执行修改后的数据
expdp HHGJJ_SYS40/atwasoft2018@172.18.111.77:1521/orcl directory=BACKUP_DATA dumpfile=shineyue4020190311.dmp schemas=HHGJJ_SYS40;
四>跟新相关表的相关字段
----1>跟新cr_dw
update cr_dw a set (a.dwmc,a.jbrxm,a.dwfrdbxm,a.dwdz)=(select b.dwmc,b.jbrxm,b.dwfrdbxm,b.dwdz from cr_dwBackUp b where b.id=a.id and b.dwbh=a.dwbh)
where exists(
select * from cr_dwBackUp b where b.id=a.id and b.dwbh=a.dwbh);
--- 已执行
---2>跟新cr_gr
create index cr_grBackUp_id on cr_grBackUp (id) online;
update cr_gr a set (a.xingming,a.sjhm)=(select b.xingming,b.sjhm from cr_grBackUp b where b.id=a.id)
where exists(
select * from cr_grBackUp b where b.id=a.id);
---已执行
---3>跟新grdk_sq_htxx
create index grdk_sq_htxxBackUp_id on grdk_sq_htxxBackUp(id) online;
update grdk_sq_htxx a set (a.jkrxm,a.lxdh,a.fwzl)=(select b.jkrxm,b.lxdh,b.fwzl from grdk_sq_htxxBackUp b where b.id=a.id)
where exists(
select * from grdk_sq_htxxBackUp b where b.id=a.id
---已执行
---4>跟新grdk_sq_gtjkr
create index grdk_sq_gtjkrBackUp_id on grdk_sq_gtjkrBackUp(id) online;
update grdk_sq_gtjkr a set a.gtjkrxm=(select b.gtjkrxm from grdk_sq_gtjkrBackUp b where b.id=a.id)
where exists(
select * from grdk_sq_gtjkrBackUp b where b.id=a.id);
---5>跟新im_gryhzh
create index im_gryhzhBackUp_id on im_gryhzhBackUp(id) online;
update im_gryhzh a set a.zhhm=(select b.zhhm from im_gryhzhBackUp b where b.id=a.id)
where exists(
select * from im_gryhzhBackUp b where b.id=a.id
);
---6>跟新grdk_sq_dbxx
create index grdk_sq_dbxxBackUp_id on grdk_sq_dbxxBackUp(id) online;
update grdk_sq_dbxx a set (a.dywfwzl,a.dywsyrtxdz,a.dywsyr,a.dywsyrpo,a.dywsyryddh,dywsyrpoyddh)=(select b.dywfwzl,b.dywsyrtxdz,b.dywsyr,b.dywsyrpo,b.dywsyryddh,b.dywsyrpoyddh from grdk_sq_dbxxBackUp b where b.id=a.id)
where exists(
select * from grdk_sq_dbxxBackUp b where b.id=a.id
);
总结:
1>oracle的数据回滚技术:
SELECT * FROM 表名 as of TIMESTAMP "TO_TIMESTAMP"('2018-05-29 17:58:00', 'yyyy-MM-dd HH24:mi:ss') WHERE USERID IN (SELECT b."UID" FROM TS_APP_USERS_B b) ;
2>update跟新多个字段;
update grdk_sq_dbxx a set (a.dywfwzl,a.dywsyrtxdz,a.dywsyr,a.dywsyrpo,a.dywsyryddh,dywsyrpoyddh)=(select b.dywfwzl,b.dywsyrtxdz,b.dywsyr,b.dywsyrpo,b.dywsyryddh,b.dywsyrpoyddh from grdk_sq_dbxxBackUp b where b.id=a.id)
3>关联跟新的时候执行时间很慢可以考虑在大表上建立索引:
create index grdk_sq_dbxxBackUp_id on grdk_sq_dbxxBackUp(id) online;