dblink每天將生產庫資料備份到測試庫(proc,jobs)

來源:互聯網
上載者:User

 

原理:

(1)利用database link使兩個資料庫之間建立串連。

   (2)建立一個預存程序:實現所有資料表內容的刪除,然後將生產庫的資料表內容插入到測試庫中。(commit)

  (3)利用Jobs定期執行預存程序即可。

1、 在測試庫中建立dblink:

createdatabaselink to_shengchan(dblink名稱)

connectto visuidentifiedby visu

using'(DESCRIPTION=

          (ADDRESS_LIST =

             (ADDRESS = (PROTOCOL = TCP)(HOST =10.138.10.196)(PORT = 1521))

             (ADDRESS = (PROTOCOL = TCP)(HOST =10.138.10.198)(PORT = 1521)) --生產庫叢集IP

          )

          (CONNECT_DATA =

             (SERVICE_NAME = yyjcrac)  --執行個體名

          )

        )'

 

2、 建立預存程序:

createorreplaceprocedure proc_shengchan_bakis

begin

 

    ------------以下是非即時表資料-----------------

 

deletefromz_visu_data_chk;   

commit;

    insertinto z_visu_data_chk

    select *from z_visu_data_chk@to_shengchan t;

    commit;

   

    deletefrom z_visu_data_dish;

    commit;

    insertinto z_visu_data_dish

    select *from z_visu_data_dish@to_shengchan t;

    commit;

   

deletefromz_visu_data_fin;   

commit;

    insertinto z_visu_data_fin

    select *from z_visu_data_fin@to_shengchan t;

    commit;

   

deletefromz_visu_data_hr;   

commit;

    insertinto z_visu_data_hr

    select *from z_visu_data_hr@to_shengchan t;

    commit;   

   

end;

建立預存程序時,必須執行F8,使其編譯成功。

 

3、 執行預存程序

3.1 手動執行

call proc_shengchan_bak()

或者 exec proc_shengchan_bak

3.2 通過Jobs執行(建立job)

 

DECLARE

            X NUMBER;

         BEGIN

            SYS.DBMS_JOB.SUBMIT

            ( job => X

               ,what => 'TESTPROC;'

               ,next_date => to_date('02-07-2008 01:00:00','dd/mm/yyyyhh24:mi:ss')

               ,interval =>'TRUNC(sysdate) + 1 +9/ (24)'  --每天早上9點執行

               ,no_parse => FALSE

            );

                SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));

               COMMIT;

         END;

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.