一個shell 指令碼用來同步表用的
1.需先將外網的資料都export出來,本例的dump檔案是t_remhs.dmp,需同步的檔案是t_remhs_5,t_remhs_4,t_remhs_3,t_remhs_2,t_remhs_1
[oracle@qht109 remhs_dump]$ exp l5m/l5m file=t_remhs.dmp tables=t_remhs_5,t_remhs_4,t_remhs_3,t_remhs_2,t_remhs_1
Export: Release 10.2.0.4.0 - Production on Wed Mar 11 15:48:17 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table T_REMHS_5 999 rows exported
. . exporting table T_REMHS_4 999 rows exported
. . exporting table T_REMHS_3 999 rows exported
. . exporting table T_REMHS_2 999 rows exported
. . exporting table T_REMHS_1 999 rows exported
Export terminated successfully without warnings.
2.注意:此方法只是同步目標庫裡有的表,目標庫裡沒有的表需最後執行一次ignore=y的import操作。
3.建立的指令碼如下:
[oracle@qht109 remhs_dump]$ cat batch_remhs.sh
#!/bin/sh
. /home/oracle/.bash_profile
export user=l5m
export passwd=l5m
export service=orcl109
export table_name=$1
sqlplus -silent } << END
declare
table_name varchar2(100);
v_sql varchar2(200);
begin
table_name:='$1';
v_sql:='truncate table l5m.'||table_name;
execute immediate v_sql;
end;
/
exit;
END
imp l5m/l5m file=t_remhs.dmp log=t_remhs_$1.log tables=$1 ignore=y buffer=4096000
#end of file batch_remhs.sh
[oracle@qht109 remhs_dump]$ cat batch_retrive.sh
#!/bin/sh
. /home/oracle/.bash_profile
export user=l5m
export passwd=l5m
export service=orcl109
VALUE=`sqlplus -silent } << END
set pagesize 0 feedback off verify off heading off echo off linesize 32000
select max(substr(sys_connect_by_path(table_name,','),2)) exp from
(select table_name,rownum rn from all_tables where owner='L5M' and table_name like 'T_REMHS%' )
start with rn=1 connect by rn=rownum;
exit;
END`
table_name=$VALUE
while [ 1 = 1 ]
do
cur_name=${table_name%%,*}
echo "cur_name is $cur_name"
table_name=${table_name#*,}
echo "table_name is $table_name"
sh batch_remhs.sh "$cur_name"
if [ $cur_name == $table_name ]; then
exit 0
fi
done
#end of file batch_retrive.sh
3.執行的結果如下:
[oracle@qht109 remhs_dump]$ ./batch_retrive.sh
cur_name is T_REMHS_5
table_name is T_REMHS_4,T_REMHS_3,T_REMHS_2,T_REMHS_1
PL/SQL procedure successfully completed.
Import: Release 10.2.0.4.0 - Production on Wed Mar 11 16:19:59 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing L5M's objects into L5M
. importing L5M's objects into L5M
. . importing table "T_REMHS_5" 999 rows imported
Import terminated successfully without warnings.
cur_name is T_REMHS_4
table_name is T_REMHS_3,T_REMHS_2,T_REMHS_1
PL/SQL procedure successfully completed.
Import: Release 10.2.0.4.0 - Production on Wed Mar 11 16:19:59 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing L5M's objects into L5M
. importing L5M's objects into L5M
. . importing table "T_REMHS_4" 999 rows imported
Import terminated successfully without warnings.
cur_name is T_REMHS_3
table_name is T_REMHS_2,T_REMHS_1
PL/SQL procedure successfully completed.
Import: Release 10.2.0.4.0 - Production on Wed Mar 11 16:19:59 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing L5M's objects into L5M
. importing L5M's objects into L5M
. . importing table "T_REMHS_3" 999 rows imported
Import terminated successfully without warnings.
cur_name is T_REMHS_2
table_name is T_REMHS_1
PL/SQL procedure successfully completed.
Import: Release 10.2.0.4.0 - Production on Wed Mar 11 16:20:00 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing L5M's objects into L5M
. importing L5M's objects into L5M
. . importing table "T_REMHS_2" 999 rows imported
Import terminated successfully without warnings.
cur_name is T_REMHS_1
table_name is T_REMHS_1
PL/SQL procedure successfully completed.
Import: Release 10.2.0.4.0 - Production on Wed Mar 11 16:20:00 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing L5M's objects into L5M
. importing L5M's objects into L5M
. . importing table "T_REMHS_1" 999 rows imported
Import terminated successfully without warnings.
4.需同步源庫存在而目標庫不存在的表
imp l5m/l5m file=t_remhs.dmp log=t_remhs_full.log full=y ignore=y buffer=4096000
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271283/viewspace-1018469/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 9個實用shell指令碼指令碼
- 分享兩個實用的shell指令碼指令碼
- 7 個日常實用的 Shell 拿來就用指令碼例項!指令碼
- 用shell指令碼來給mysql加索引指令碼MySql索引
- Shell指令碼應用兩個例子指令碼
- 用指令碼來講一個技術生活的故事指令碼
- Shell指令碼應用(三)指令碼
- shell指令碼的一則簡單運用案例指令碼
- 幾例實用的Shell指令碼指令碼
- shell入門--第一個shell指令碼指令碼
- 用於管理應用程式得shell指令碼指令碼
- 有點用的linux shell 指令碼Linux指令碼
- 一個很好的指令碼,用來顯示cbo的統計資訊指令碼
- 用shell指令碼合併多個檔案內容指令碼
- 用Shell指令碼&sqlloader做ETL指令碼SQL
- 一個比較好的shell指令碼指令碼
- 每日同步環境SHELL指令碼指令碼
- shell指令碼中的變數及應用指令碼變數
- 用shell指令碼傳送帶附件的email指令碼AI
- 共享一個iptables的shell指令碼檔案指令碼
- 向大家分享一個shell指令碼的坑指令碼
- MySQL的一些功能實用的Linux shell指令碼分享MySqlLinux指令碼
- Shell指令碼之for迴圈語句的應用指令碼
- 讓我們來用php編寫一個搶購商品指令碼PHP指令碼
- Shell指令碼應用 – for、while迴圈語句指令碼While
- 資料庫環境中的shell指令碼應用資料庫指令碼
- 用Shell指令碼來解決DOS安全Linux伺服器生產指令碼Linux伺服器
- 用SHELL指令碼來防SSH和vsftpd暴力破解(第②版) 薦指令碼FTP
- 該死的埠占用!教你用 Shell 指令碼一鍵幹掉它!指令碼
- 一個還算可以用的啟動指令碼指令碼
- Shell:如何寫一個多選選單的指令碼指令碼
- 一個自動生成awr報告的shell指令碼指令碼
- [ Shell ] 通過 Shell 指令碼匯出 CDL 網表指令碼
- 輕鬆使用“Explain Shell”指令碼來理解 Shell 命令AI指令碼
- 一段shell 指令碼指令碼
- shell指令碼----輸入一個整數,將每個位上的數輸出出來,並求和指令碼
- 從一個shell指令碼執行出錯聊起指令碼
- 18 個一線工作中常用 Shell 指令碼指令碼