生產環境中萬一對生產數據進行了誤操做,這個時候有沒有什麼技術可以進行緊急回滾?sql
一>備份沒執行脫敏腳本以前的數據oracle
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');
二>備份執行脫敏腳本以後的數據ide
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統一備份執行修改後的數據spa
expdp HHGJJ_SYS40/atwasoft2018@172.18.111.77:1521/orcl directory=BACKUP_DATA dumpfile=shineyue4020190311.dmp schemas=HHGJJ_SYS40;
四>跟新相關表的相關字段orm
----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;it
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)table
where exists(class
select * from grdk_sq_dbxxBackUp b where b.id=a.iddate
);
總結:
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;