使用CRONTAB调用shell脚本执行EXP

使用CRONTAB调用shell脚本执行EXP[@more@]

通过SHELL脚本执行全库导出是很常见的。但是如果将这个SHELL脚本通过CRONTAB定时调用,则需要修改很多地方。这里简单记录一下。


由于对UNIX系统不是很熟悉。将一个已经可以运行的csh脚本,改成一个可以在CRONTAB中调用的bash脚本,花了我足足大半天的时间。又用了不少时间将整个CRONTAB环境从测试的LINUX环境移植到UNIX环境。

下面是根据Tom的expert one-on-one oracle上代码稍加修改后的初始版本:

#!/bin/csh -f

# Set this to the userid you want to perform the export as I always use OPS$ (os
# authenticated) accounts for all jobs that will be run in the background. In that
# way a password never appears in a script file or in the ps output.
setenv UID system/systempassword@bjdb01

# This is the name of the export file. SPLIT will use this to name the pieces of
# the compressed DMP file.
setenv FN bjdb01_full_`date +%y%m%d`.dmp

# This is the name of the named pipe we will use.
setenv PIPE /tmp/exp_tmp.dmp

# Here I limit the size of the compressed files to 500 MG each. Anything less
# than 2 GB would be fine.

# This is what we are going to export. By default I am doing a full database
# export.
setenv EXPORT_WHAT "full=y COMPRESS=n"


# This is where the export will go to.
cd /data/exp

# Clear out the last export.
#rm expbjdb01.log export.test exp.*.dmp* $PIPE

# Create the named pipe.
mknod $PIPE p

# Write the datetime to the log file.
date > expbjdb01.log

# Start a gzip process in the background. Gzip will read the pipe and put the
# compressed data out to split. Split will then create 500 MB files out of the
# input data adding .aa, .ab, .ac, .ad, ... file extensions to the template name
# found in $FN.
(gzip < $PIPE) > $FN.gz &

# Now, start up export. The Gzip above is waiting for export to start filling the
# pipe up.
exp userid=$UID buffer=204800000 file=$PIPE $EXPORT_WHAT >>& expbjdb01.log
date >> expbjdb01.log

# Now the export is done, this is how to IMP. We need to sort the filenames and
# then simply cat their contents into gunzip. We write that into the pipe. IMP
# will then read that pipe and write what it would do to stderr. The >>& in the
# csh redirects both stdout and stderr for us.

#date > export.test
#gunzip $FN.gz > $PIPE &
#imp userid=$UID file=$PIPE show=y full=y >>& export.test
#date >> export.test

# Clean up the pipe, we don't need it anymore.
rm -f $PIPE

这个是我修改以后可以被CRONTAB调用的脚本:

ORACLE_HOME=/u1/oracle/product/9.2.0;
export ORACLE_HOME;
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH;
export PATH;
NLS_LANG='SIMPLIFIED CHINESE_CHINA.ZHS16GBK';
export NLS_LANG;
USERID=system/systempassword@bjdb01;
export USERID;
FN=/data/exp/bjdb01_full_`date +%y%m%d`.dmp;
export FN;
PIPE=/tmp/exp_tmp.dmp;
export PIPE;
EXPORT_WHAT="full=y COMPRESS=n";
export EXPORT_WHAT;
cd /data/exp;
rm expbjdb01.log;
/usr/sbin/mknod $PIPE p;
date > expbjdb01.log;
(gzip < $PIPE) > $FN.gz &
exp userid=$USERID buffer=204800000 file=$PIPE $EXPORT_WHAT >> expbjdb01.log 2>> expbjdb01.log;
date >> expbjdb01.log;
rm -f $PIPE
~

主要注意两个地方:

通过CRONTAB调用和当前Oracle用户调用并不一样,通过CRONTAB调用不会包含当前用户中的各种环境变量的设置。因此必须开始的就设置好ORACLE_HOME等环境变量;

在每条命令后都加上分号,而这在非CRONTAB调用的脚本中是不需要的

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/190276/viewspace-902969/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/190276/viewspace-902969/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值