列宿乃施于上荣兮 日月才经于柍桭

………… 白驹过隙 岁月如斯 梦萦回绕 心灵之声
posts - 57, comments - 8, trackbacks - 0, articles - 41
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

AIX下DB2数据库的导出导入脚本

Posted on 2008-08-17 08:18 默认为零 阅读(690) 评论(0)  编辑  收藏 所属分类: 技术

导出

-----------------------------------------------
if [ $# -lt 4 ]
then
  echo "Usage: $0 <table_name> <dbname> <dbuser> <dbpwd>"
  exit 1
fi

TBL=$1

EXP=$1.data

db2 connect to $2 user $3 using $4
db2 "export to $EXP of del modified by coldel: select * from $TBL with ur" > unload.log

nexp=`grep "Number of rows exported" unload.log | awk -F: '{print $2}'`
echo " ok ! ($nexp)\n"

db2 connect reset > /dev/null

rm -f unload.log

-----------------------------------------------


导入

-----------------------------------------------
if [ $# -lt 4 ]
then
  echo "Usage: $0 <table_name> <dbname> <dbuser> <dbpwd>"
  exit 1
fi

TBL=$1
DATA=$1.data
EXP=$1.exp

sed 's/:$//g' $DATA > $EXP
chmod a+r $EXP

db2 connect to $2 user $3 using $4
db2 "load from $EXP of del modified by coldel: usedefaults replace into $TBL nonrecoverable" > load.log
nread=`grep "Number of rows read" load.log | awk -F= '{print $2}'`
nload=`grep "Number of rows committed" load.log | awk -F= '{print $2}'`
echo " ok ! ($nread/$nload)\n"
rm -f $EXP

db2 connect reset > /dev/null

rm -f load.log

-----------------------------------------------

只有注册用户登录后才能发表评论。


网站导航: