用shell批量转储表
生活随笔
收集整理的這篇文章主要介紹了
用shell批量转储表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近經常做一些轉儲表的工作,之前的腳步太簡單了,人工干預工作太多(手工重構清理腳步,整合轉儲日志等工作),于是對之前的腳步進行更新!
之前的腳本如下:
cat /oracle/lu/expcxdb_table.out|while read username tablename do exp \'sys/oracle as sysdba\' tables="$username"."$tablename" buffer=498430400 direct=y recordlength=65535 file=/orabak/"$tablename" indexes=y constraints=y compress=n log=/oracle/lu/cxdblog/exp_"$tablename".log done修改后的腳本如下
#清理垃圾文件 rm clear_data.txt rm cd_dump_cxdb_table_all.log#構建清理腳本,獲取數據總行數 while read username tablename do echo "alter table $username"."$tablename" " rename to od_""$tablename" >>clear_data.txt i=$(($i+1)) done </oracle/lu/expcxdb_table.out echo "總數據條目為:"$i"條">>cd_dump_cxdb_table_all.log cat /oracle/lu/expcxdb_table.out|while read username tablename do echo "drop table " "$username"."od_""$tablename">>clear_data.txt done#導出要轉儲的表 j=0 cat /oracle/lu/expcxdb_table.out|while read username tablename do j=$(($j+1)) k=$(($i-$j)) exp \'sys/oracle as sysdba\' tables="$username"."$tablename" buffer=498430400 direct=y recordlength=65535 file=/orabak/"$tablename" indexes=y constraints=y compress=n log=/oracle/lu/cxdblog/exp_"$tablename".log dmpsize=`du -sm /orabak/$tablename.dmp|awk -F' ' '{print $1}'` cat /oracle/lu/cxdblog/exp_"$tablename".log|grep "without warnings" if [[ $? -eq 0 ]];then echo "第" "$j" "張表" ":$username"."$tablename" " 已導出,dump文件大小為:" "$dmpsize" "M 剩余" "$k" "張表" "無告警提示 詳細日志如下:">>cd_dump_cxdb_table_all.log echo " ">>cd_dump_cxdb_table_all.log#統計所有轉儲日志到同一個日志文件 cat /oracle/lu/cxdblog/exp_"$tablename".log>>cd_dump_cxdb_table_all.log echo " ">>cd_dump_cxdb_table_all.log echo "----------------------表間分割線-------------------">>cd_dump_cxdb_table_all.log echo " ">>cd_dump_cxdb_table_all.log else echo "第" "$j" "張表" ":$username"."$tablename" " 已導出,dump文件大小為:" "$dmpsize" "M 剩余" "$k" "張表" "有告警提示 詳細日志如下:">>cd_dump_cxdb_table_all.log cat /oracle/lu/cxdblog/exp_"$tablename".log>>cd_dump_cxdb_table_all.log echo " ">>cd_dump_cxdb_table_all.log echo "----------------------表間分割線-------------------">>cd_dump_cxdb_table_all.log echo " ">>cd_dump_cxdb_table_all.log fi done腳本首先會自動構建清理表的腳本
[oracle@localhost lu]$ cat clear_data.txt alter table hzq.table1 rename to od_table1 alter table hzq.table2 rename to od_table2 alter table hzq.table3 rename to od_table3 alter table hzq.table4 rename to od_table4 alter table hzq.table5 rename to od_table5 alter table hzq.table6 rename to od_table6 alter table hzq.table7 rename to od_table7 alter table hzq.table8 rename to od_table8 alter table hzq.table9 rename to od_table9 alter table hzq.table10 rename to od_table10 alter table hzq.table11 rename to od_table11 drop table hzq.od_table1 drop table hzq.od_table2 drop table hzq.od_table3 drop table hzq.od_table4 drop table hzq.od_table5 drop table hzq.od_table6 drop table hzq.od_table7 drop table hzq.od_table8 drop table hzq.od_table9 drop table hzq.od_table10 drop table hzq.od_table11能夠統計總共要清理表的數量,后臺執行腳本,通過日志能夠實時查看腳本轉儲到了哪張表,查看轉儲出的日志大小,具體如下
[oracle@localhost lu]$ cat cd_dump_cxdb_table_all.log |more 總數據條目為:11條 第 1 張表 :hzq.table1 已導出,dump文件大小為: 1 M 剩余 10 張表 無告警提示 詳細日志如下:Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in AL32UTF8 character set and AL16UTF16 NCHAR character setAbout to export specified tables via Direct Path ... Current user changed to HZQ . . exporting table TABLE1 12 rows exported Export terminated successfully without warnings.----------------------表間分割線-------------------第 2 張表 :hzq.table2 已導出,dump文件大小為: 1 M 剩余 9 張表 無告警提示 詳細日志如下:Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in AL32UTF8 character set and AL16UTF16 NCHAR character setAbout to export specified tables via Direct Path ... Current user changed to HZQ . . exporting table TABLE2 1 rows exported Export terminated successfully without warnings.----------------------表間分割線-------------------第 3 張表 :hzq.table3 已導出,dump文件大小為: 1 M 剩余 8 張表 無告警提示 詳細日志如下:Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Export done in AL32UTF8 character set and AL16UTF16 NCHAR character setAbout to export specified tables via Direct Path ... Current user changed to HZQ . . exporting table TABLE3 1 rows exported Export terminated successfully without warnings.?
轉載于:https://www.cnblogs.com/houzhiqing/p/5892575.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的用shell批量转储表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android应用截图嵌入到真实设备
- 下一篇: 基于struts2的文件上传下载