ITPub博客

首页 > 大数据 > 数据挖掘 > 一个数据仓库数据刷新的实现机制(七)

一个数据仓库数据刷新的实现机制(七)

原创 数据挖掘 作者:zhyuh 时间:2005-04-07 19:34:11 0 删除 编辑

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 $USERNAME/$PASSWORD@$DATABASE<
 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
$USERNAME/$PASSWORD@$DATABASE<
 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
$USERNAME/$PASSWORD@$DATABASE<
  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
>$LOG_PATH/$LOG_DETAIL$USERNAME/$PASSWORD@$DATABASE>>$LOG_PATH/$LOG_DETAIL<
      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
$USERNAME/$PASSWORD@$DATABASE<
  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
>$LOG_PATH/$LOG_DETAIL$USERNAME/$PASSWORD@$DATABASE>>$LOG_PATH/$LOG_DETAIL<
      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
$USERNAME/$PASSWORD@$DATABASE<
 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
$USERNAME/$PASSWORD@$DATABASE<
 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
$USERNAME/$PASSWORD@$DATABASE<
  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
>$LOG_PATH/$LOG_DETAIL$USERNAME/$PASSWORD@$DATABASE>>$LOG_PATH/$LOG_DETAIL<
      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
$USERNAME/$PASSWORD@$DATABASE<
  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
>$LOG_PATH/$LOG_DETAIL$USERNAME/$PASSWORD@$DATABASE>>$LOG_PATH/$LOG_DETAIL<
      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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2008666