Chinaunix首页 | 论坛 | 博客
  • 博客访问: 645408
  • 博文数量: 66
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 2204
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-26 21:43
个人简介

曾就职于阿里巴巴担任Oracle DBA,MySQL DBA,目前在新美大担任SRE。[是普罗米修斯还是一块石头,你自己选择!] 欢迎关注微信公众号 “自己的设计师”,不定期有原创运维文章推送。

文章分类

全部博文(66)

文章存档

2017年(2)

2016年(3)

2015年(7)

2014年(12)

2013年(42)

分类: Oracle

2013-12-13 23:19:43

 #!/bin/bash
  file_name="/home/oracle/test/verfy"
  declare loader_file_name
  declare table_name
  declare -i x=0
  if [ ! -f "$file_name" ];
     then
   echo "file is loadding,please wait a minute! \n"
     while [ ! -f $file_name ]; 
    do
      if [ "$x" == "4" ]; then
                echo "Have wait 20 minutes,Wait Overtime! \n"
                sleep 1s
                exit
      fi
      sleep 5m


    done
   fi
  # imp xiaocai/xiaocai file=/data/xiaocai_`date +"%Y-%m-%d"`.dmp  fromuser=xiaocai touser=caixiao tables=(TEST1)  ignore=y;
  echo -e  "please input the  file date you want to load (eg:2010-01-03): \n"
  read loader_file_date
  echo -e  "\n please input the table name you want to load: \n"
  read table_name
  if [ $loader_file_date == ~ ]
    then
     echo "you input a blank to loader_file_date\n" 
      exit
  fi
  if [ $table_name == ~ ]
    then
     echo "you input a blank to table_name\n"
      exit
  fi


  UserId=""
  PassWd=""
  echo -e "\n please load the data to who(the username.) \n"
  read UserId
  echo -e "\n please input the user's password\n"
  read PassWd
  DATAPATH=`expr /home/oracle/test`
  #SQL*LOADER
  TAB_NAME=`expr ${table_name}`
  IN_FILE=`expr ${DATAPATH}``expr /datafile_${loader_file_date}.dat`
  CTRL_FILE=`expr ${DATAPATH}``expr /control_loader.ctl`
  LOG_FILE=`expr ${DATAPATH}``expr /loader.log`
  BAD_FILE=`expr ${DATAPATH}``expr /loader.bad`
  if [ -f ${CTRL_FILE} ]
     then
  rm -f ${CTRL_FILE}
     else
  echo "${CTRL_FILE} not exist"
  fi
  if [ -f ${LOG_FILE} ]
     then
  rm -f ${LOG_FILE}
     else                                                                                                         
  echo "${LOG_FILE} not exist"                                                                                    
  fi                                                                                                                                                                                                                               
  if [ -f ${BAD_FILE} ]                                                                                           
    then                                                                                                          
  rm -f ${BAD_FILE}                                                                                               
     else                                                                                                         
  echo "${BAD_FILE} not exist"                                                                                    
  fi                                                                                                                                                                                                                                                                                                                                               
  #make control file                                                                                              
                                                                                                                  
  make_ctrl()                                                                                                     
  {                                                                                                               
  printf "LOAD DATA\n">>${CTRL_FILE};                                                                             
  printf "INFILE '${IN_FILE}'\n">>${CTRL_FILE};                                                                   
  printf "INTO TABLE ${TAB_NAME}\n">>${CTRL_FILE};                                                                
  printf "TRUNCATE\n">>${CTRL_FILE};                                                                              
  printf "FIELDS TERMINATED BY ','\n">>${CTRL_FILE};                                                              
  printf "(\n">>${CTRL_FILE};                                                                                     
  printf "OWNER,\n">>${CTRL_FILE};                                                                                
  printf "OBJECT_NAME,\n">>${CTRL_FILE};                                                                          
  printf "SUBOBJECT_NAME,\n">>${CTRL_FILE};                                                                       
  printf "OBJECT_ID,\n">>${CTRL_FILE};                                                                            
  printf "DATA_OBJECT_ID,\n">>${CTRL_FILE};                                                                       
  printf "OBJECT_TYPE,\n">>${CTRL_FILE};                                                                          
  printf "CREATED DATE \"yyyy-mm-dd hh24:mi:ss\",\n">>${CTRL_FILE};                                               
  printf "LAST_DDL_TIME DATE \"yyyy-mm-dd hh24:mi:ss\",\n">>${CTRL_FILE};                                         
  printf "TIMESTAMP,\n">>${CTRL_FILE};                                                                            
  printf "STATUS,\n">>${CTRL_FILE};                                                                               
  printf "TEMPORARY,\n">>${CTRL_FILE};                                                                            
  printf "GENERATED,\n">>${CTRL_FILE};                                                                            
  printf "SECONDARY\n">>${CTRL_FILE};                                                                             
  printf ")\n">>${CTRL_FILE};                                                                                     
                                                                                                                  
 }                                                                                                                                                                                                                                 
  cd ${DATAPATH}                                                                                                  
   if [ -f ${IN_FILE} ]                                                                                           
   then                                                                                                           
     make_ctrl                                                                                                    
   sqlldr $UserId/$PassWd control=$CTRL_FILE log=$LOG_FILE bad=$BAD_FILE rows=100000                              
   else                                                                                                           
   echo "${IN_FILE} not exist"                                                                                    
   exit 1                                                                                                         
  fi                                                                                                              
                                                                                                                  
   if [ $? != 0 ]                                                                                                 
    then                                                                                                          
     echo "sql*loader have some errors! \n"                                                                       
     exit 1                                                                                                       
   fi                                                                                                                                                                                                                            
   sqlplus  "caixiao/caixiaocai"<    truncate table temp;                                                                                           
   alter table test1 exchange partition p_3000 with table temp;                                                   
   alter table test2 exchange partition p_3000 with table temp;                                                   
   truncate table temp;                                                                                           
   alter table test1 exchange partition p_6000 with table temp;                                                   
   alter table test2 exchange partition p_6000 with table temp;                                                   
   truncate table temp;                                                                                           
   alter table test1 exchange partition p_max with table temp;                                                    
   alter table test2 exchange partition p_max with table temp;                                                    
   truncate table test1;                                                                                          
   truncate table temp;                                                                                           
   exit    
阅读(1327) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~