一個資料倉儲資料重新整理的實現機制(七)
shell refresh_schema
該shell透過呼叫上面的兩個procedures和shell refresh_table,重新整理某個國家的所有要重新整理的資料庫物件
[@more@]該指令碼自動讀取表eden_refr_objt中的內容,重新整理某個國家的資料庫物件
用法:Usage: refresh_schema SCHEMA SCHEMA_PASSWORD SCHEMA2 SCHEMA_PASSWORD2
$refresh_schema edenfr password1 ewrfrmaster password2
其中灰掉部分程式碼基本上重複上面的程式碼,只是處理schema2所屬的資料庫物件。這樣的寫法好像不是很好,也沒想到更合理的方法,先這樣吧。
該shell指令碼如下:
###################################################################
#
# Fiel Name: refresh_schema
#
# Purpose: To refresh all the necessary Matarialized Views and
# Tables for a specified schema, log refresh information also.
# If there are more MVs or Tables to be refreshed, please
# change this script and add commands here
#
# Usage: refresh_schema SCHEMA SCHEMA_PASSWORD SCHEMA2 SCHEMA_PASSWORD2
#
# Global varialbles
# LOG_PATH: where does the log file locate
# LOG_FILE: the file to log information,
# file name in format refresh_log.yyyy-mm-dd
# LOG_DETAIL: the file to log detail inforamtion
# file name in format refresh_log.SCHEMA.yyyy-mm-dd
# USERNAME: the database user name
# PASSWORD: the password of the user
# DATABASE: the service name of database
# WEEK_DAY: the day of current day
# OBJECT_TYPE: object type.
# V: materialized views
# T: table,refreshed by SQL file
# P: table, refreshed by stored procedure
# REFRESH_TYPE: refresh type
# W: weekly
# D: daily
# N: none or never
# PROC_NAME: the procedure to refresh a specified table
#
#
###################################################################
#!/usr/bin/bash
rfsh_env()
{
LOG_PATH=/erdb/log
LOG_FILE=refresh_log.`date "+%Y-%m-%d"`
LOG_DETAIL=log_detail.$SCHEMA.`date "+%Y-%m-%d"`
USERNAME=eden
PASSWORD=****
DATABASE=service_name
}
rfsh_schema(){
echo "START REFRESHING $SCHEMA......">$LOG_PATH/$LOG_DETAIL
echo "`date`">>$LOG_PATH/$LOG_DETAIL
echo " ">>$LOG_PATH/$LOG_DETAIL
echo " ">>$LOG_PATH/$LOG_DETAIL
for OBJECT_NAME in `sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT lower(obj_nam)
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA'
ORDER BY obj_seq ASC;
EOF`
do
REFRESH_TYPE=`sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT upper(refr_type)
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
WEEK_DAY=`date "+%w"`
if [ $WEEK_DAY = "6" ] && [ $REFRESH_TYPE = "W" ] || [ $REFRESH_TYPE = "D" ]; then
OBJECT_TYPE=`sqlplus -s
SET TERM OFF
SET HEAD OFF
SET FEED OFF
SELECT upper(trim(obj_type))
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
if [ $OBJECT_TYPE = "V" ]; then
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
echo "start refreshing $SCHEMA.$OBJECT_NAME ...">>$LOG_PATH/$LOG_DETAIL
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
sqlplus -s
set serveroutput on
execute EDEN_REFRESH.REFRESH_MV('$SCHEMA','$OBJECT_NAME','$LOG_PATH');
exit;
EOF
elif [ $OBJECT_TYPE = "T" ]; then
SQL_FILE=${OBJECT_NAME}_${COUNTRY}.sql
/usr/bin/bash /erdb/bin/refresh_table $SQL_FILE $SCHEMA $SCHEMA_PASS
elif [ $OBJECT_TYPE = "P" ]; then
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
echo "start refreshing $SCHEMA.$OBJECT_NAME ...">>$LOG_PATH/$LOG_DETAIL
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
PROC_NAME=`sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT proc_nam
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
PROC_NAME=`echo $PROC_NAME|sed -e "s/^n//g"`
sqlplus -s
set serveroutput on
execute EDEN_REFRESH.REFRESH_TAB('$SCHEMA','$OBJECT_NAME','$PROC_NAME','$LOG_PATH');
exit;
EOF
else
echo "Error: type should be in V / T / P">>$LOG_PATH/$LOG_DETAIL
fi
fi
done
for OBJECT_NAME in `sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT lower(obj_nam)
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA2'
ORDER BY obj_seq ASC;
EOF`
do
REFRESH_TYPE=`sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT upper(refr_type)
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA2'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
WEEK_DAY=`date "+%w"`
if [ $WEEK_DAY = "6" ] && [ $REFRESH_TYPE = "W" ] || [ $REFRESH_TYPE = "D" ]; then
OBJECT_TYPE=`sqlplus -s
SET TERM OFF
SET HEAD OFF
SET FEED OFF
SELECT upper(trim(obj_type))
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA2'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
if [ $OBJECT_TYPE = "V" ]; then
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
echo "start refreshing $SCHEMA2.$OBJECT_NAME ...">>$LOG_PATH/$LOG_DETAIL
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
sqlplus -s
execute EDEN_REFRESH.REFRESH_MV('$SCHEMA2','$OBJECT_NAME','$LOG_PATH');
exit;
EOF
elif [ $OBJECT_TYPE = "T" ]; then
SQL_FILE=${OBJECT_NAME}_${COUNTRY}.sql
/usr/bin/bash /erdb/bin/refresh_table $SQL_FILE $SCHEMA2 $SCHEMA_PASS2
elif [ $OBJECT_TYPE = "P" ]; then
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
echo "start refreshing $SCHEMA2.$OBJECT_NAME ...">>$LOG_PATH/$LOG_DETAIL
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
PROC_NAME=`sqlplus -s
SET FEED OFF
SET HEAD OFF
SET TERM OFF
SELECT proc_nam
FROM eden_refr_objt
WHERE lower(user_nam)='$SCHEMA2'
AND lower(obj_nam)='$OBJECT_NAME';
EOF`
PROC_NAME=`echo $PROC_NAME|sed -e "s/^n//g"`
sqlplus -s
execute EDEN_REFRESH.REFRESH_TAB('$SCHEMA2','$OBJECT_NAME','$PROC_NAME','$LOG_PATH');
exit;
EOF
else
echo "Error: type should be in V / T / P">>$LOG_PATH/$LOG_DETAIL
fi
fi
done
echo " ">>$LOG_PATH/$LOG_DETAIL
echo "`date`">>$LOG_PATH/$LOG_DETAIL
echo " REFRESHING $SCHEMA FINISHED!">>$LOG_PATH/$LOG_DETAIL
echo "----------------------------------------------------">>$LOG_PATH/$LOG_DETAIL
ERR_COUNT=`cat $LOG_PATH/$LOG_DETAIL|grep ORA-|wc -l`
if [ $ERR_COUNT -gt 0 ]; then
echo " "
echo "ERRORS during refresh!!!"
echo "please check file $LOG_PATH/$LOG_DETAIL for detail information."
echo " "
exit 1
else
echo " "
echo "Refresh succeed"
exit 0
fi
}
#########################################
#
# Main
#
#########################################
if [ $# -lt 4 ]; then
echo " "
echo "Usage: refresh_schema SCHEMA SCHEMA_PASSWORD SCHEMA2 SCHEMA_PASSWORD2"
echo " "
exit
fi
SCHEMA=`echo $1|tr "[A-Z]" "[a-z]"`
SCHEMA_PASS=`echo $2|tr "[A-Z]" "[a-z]"`
SCHEMA2=`echo $3|tr "[A-Z]" "[a-z]"`
SCHEMA_PASS2=`echo $4|tr "[A-Z]" "[a-z]"`
COUNTRY=`echo $1|awk '{print substr($1,length($1)-1,length($1))}'`
rfsh_env
rfsh_schema
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/207/viewspace-795326/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 一個資料倉儲資料重新整理的實現機制(一)
- 一個資料倉儲資料重新整理的實現機制(八)
- 一個資料倉儲資料重新整理的實現機制(六)
- 一個資料倉儲資料重新整理的實現機制(五)
- 一個資料倉儲資料重新整理的實現機制(四)
- 一個資料倉儲資料重新整理的實現機制(三)
- 一個資料倉儲資料重新整理的實現機制(二)
- 如何用資料倉儲管理海量資料?直接訪問資料倉儲資料時的4個限制
- 設計資料倉儲和資料倉儲的粒度
- 資料庫倉庫系列:(一)什麼是資料倉儲,為什麼要資料倉儲資料庫
- 資料倉儲—資料倉儲—Sybase IQ 介紹
- 資料倉儲中的分析SQL——資料倉儲手冊SQL
- 資料倉儲
- 一個簡化、落地的實時資料倉儲解決方案
- Oracle資料倉儲的實時資料採集XSOracle
- 資料庫和資料倉儲資料庫
- 資料倉儲應該用什麼方案——資料倉儲實施方案概述
- 資料倉儲—資料倉儲—NCR Teradata Warehouse 介紹
- 資料倉儲之路
- 用Rust 實現的現代化實時開源資料倉儲Rust
- 資料倉儲和後設資料
- 資料倉儲、資料湖與湖倉一體的區別與聯絡
- hive資料倉儲匯入資料的方法Hive
- 關於資料湖、資料倉儲的想法
- 資料倉儲與大資料的區別大資料
- 資料湖 vs 資料倉儲 vs 資料庫資料庫
- 資料倉儲的組成
- 資料倉儲中的概念
- 資料湖是下一代資料倉儲?
- DW資料倉儲的一些概念
- 資料倉儲—資料倉儲—IBM DB2 Datawarehouse 介紹IBMDB2
- 一個不錯的資料倉儲名字查詢網站網站
- 萬字詳解資料倉儲、資料湖、資料中臺和湖倉一體
- 資料湖會取代資料倉儲嗎?
- 談談資料湖和資料倉儲
- 淺談資料倉儲和大資料大資料
- 資料倉儲—資料庫—Oracle 介紹資料庫Oracle
- 資料倉儲一般模式分析模式