设为首页 收藏本站
查看: 1438|回复: 0

ORACLE自动备份并且自动FTP到备份机的SHELL脚本

[复制链接]

尚未签到

发表于 2015-5-28 12:00:48 | 显示全部楼层 |阅读模式
ORACLE自动备份并且自动FTP到备份机的SHELL脚本

创建:2005-10-27 16:18:20
作者:Unlinux
来自: http://www.Unlinux.com

本次上传的脚本有很多可以改进的地方!这也是本人第一次在网上发帖,SH写的不好的地方
不要见笑!!!!!!本SH以在SCO OPENSERVER 505(ORACLE 7.3.2)和IBM RS6000 AIX 4.3(ORACLE 8.1.6)调试通过!!如果要转载,请加上出处!!!谢谢!!!详细功能见脚本文件SH的批注!!!如果能要加上自动执行的功能请使用crontab配置即可!!!!

第一个文件:INIT.TXT这是脚本INI初始化文件:
##################################################################
#This is a system ini file :
# CopyRight By WangZuXiang 2002
# the '#' is ingnor :
#the format style is xxxx=value
#
##################################################################

#Oracle cionfig
[oracle]
username=ydyx
password=ydyx
con_alias=MISDB

#the main machine config
[mainhost]
myhost_ip=10.232.193.2
myhost_username=oracle
myhost_password=oracle
dump_dir=/u2/oracleback

#the backup machine config
[backuphost]
backhost_ip=10.232.193.5
backhost_username=oracle
backhost_password=oracleydyx
backup_dir=/u2/oracleshaoshanback

#delete the dump file x days ago?!!!
[deletedumpfile]
delete_days=2

#the Oracle database's back method
#如果start_tactic=Y 则采用策略备份,否则按每天完全到出
#如果采用策略备份,则必须给SYSTEM用户的口令
[backmethod]
start_tactic=N
system_password=manager11

#the recode the system execute's log!
[systemlog]
sys_log=/home/oracle/wzx/x.log
#end

第二个文件:主程序文件:MY.SH:
#!/bin/sh
#############################################################################
#
#Get the all ini file config
#CopyRight By WangZuXiang 2002-2005?
#版权所有(C) 2002-2005? WangZuXiang .
#All Rights Reserved.
#program date 2002-10-22
#usage: main
#This script is used to start oracle dump database .
#It should ONLY be executed as part of the crontabs.
#function content is:
#1:自动检查是否能连上Oracle!
#2:通过初始化文本来解析各种需要的参数!
#3:自动完全到出ORACLE数据库(每天)!,以后将增加相关的增量备份等!
#4:自动删除配置文件中规定的前X天的备份文件!
#5:自动将到出文件打包并转存到其他的备份机器上!
#6:自动记录程序执行过程中的所有日期信息!
#if you find some bugs please send it to my mailpost :
#e-mail:wzxherry@sina.com !
#new function:增加了对ORACLE数据库备份策略的方法!2002-10-31
##############################################################################
mypwd=`pwd`
inifile=/home/oracle/wzx/init.txt
oratab=/etc/oratab
TEMP=temp.$$
DUMP_FILE=`date +'%Y%m%d`

initme ()
{
#read from the config file 'ini.txt'

#oracle config
USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^username' | awk -F = '{print $2}'`
PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^password' | awk -F = '{print $2}'`
MY_ALIAS=`cat ${inifile:-"init.txt"} | grep -i '^con_alias' | awk -F = '{print $2}'`

#the main host config
MYHOST_IP=`cat ${inifile:-"init.txt"} | grep -i '^myhost_ip' | awk -F = '{print $2}'`
MYHOST_USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^myhost_username' | awk -F = '{print $2}'`
MYHOST_PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^myhost_password' | awk -F = '{print $2}'`
DUMP_DIR=`cat ${inifile:-"init.txt"} | grep -i '^dump_dir' | awk -F = '{print $2}'`

#the backup host config
BACKHOST_IP=`cat ${inifile:-"init.txt"} | grep -i '^backhost_ip' | awk -F = '{print $2}'`
BACKHOST_USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^backhost_username' | awk -F = '{print $2}'`
BACKHOST_PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^backhost_password' | awk -F = '{print $2}'`
BACKUP_DIR=`cat ${inifile:-"init.txt"} | grep -i '^backup_dir' | awk -F = '{print $2}'`

#the define's delete dump file days!
DAYS=`cat ${inifile:-"init.txt"} | grep -i '^delete_days' | awk -F = '{print $2}'`
#to get the system log
LOGS=`cat ${inifile:-"init.txt"} | grep -i '^sys_log' | awk -F = '{print $2}'`
TACTIC=`cat ${inifile:-"init.txt"} | grep -i '^start_tactic' | awk -F = '{print $2}'`
SYSTEMPASS=`cat ${inifile:-"init.txt"} | grep -i '^system_password' | awk -F = '{print $2}'`

#read the config file end.
}

#WHOAMI=`id | awk '/uid=[0-9]*(oracle)/ {print $1}'`
#WHOAMI=`id | awk '{print $1}' | sed 's/uid=[0-9]*(.*).*/1/'`
WHOAMI=`id | sed 's/uid=[0-9]*(.*) gid.*/1/'`
#if test "$WHOAMI" = "" ; then
if test "$WHOAMI" != "(oracle)" ; then
echo "

"
echo "=============================================================="
echo "=========you must use oracle user to run this script!========="
echo "=============================================================="
echo "

"
exit 0
fi

#run the init parameter
test ! -e $inifile && echo "not find the init file:"$inifile"!" && exit 0

initme

if [ -z $LOGS ]; then
echo ""
fi

#LOG = ${LOGS:-"x.log"}
LOGME="tee -a ${LOGS:-"x.log"}"

if [ -e $LOGS -a -f $LOGS ]; then
if test ! -w $LOGS; then
echo ""
exit
fi
fi

echo "

" | $LOGME
echo "-----------------------------------------------------------------" | $LOGME
echo "" | $LOGME

#check the parameter value
if [ -z $USERNAME ]; then
echo ">" | $LOGME
exit 2
fi

if [ -z $MY_ALIAS ]; then
echo ">" | $LOGME
exit 0
fi

if [ -z $MYHOST_IP ]; then
echo ">" | $LOGME
exit 0
fi

if [ -z $MYHOST_USERNAME ]; then
echo "" | $LOGME
exit 4
fi

if [ -z $MYHOST_PASSWORD ]; then
echo "" | $LOGME
exit 5
fi

if [ -z $BACKHOST_IP ]; then
echo ">" | $LOGME
exit 7
fi

if [ -z $BACKHOST_PASSWORD ]; then
echo ">" | $LOGME
exit 9
fi
#elif [ ! -e $BACKUP_DIR -o ! -d $BACKUP_DIR ]; then
#echo "" | $LOGME
#exit 0
#fi

#if [ ! -O $BACKUP_DIR ]; then
#echo ">" | $LOGME
exit 0
fi

ORACLE_SID=`cat $oratab | grep -v "^#" | grep "Y$" | awk -F : '{print $1}' `
if [ -z $ORACLE_SID ]; then
echo "" | $LOGME
exit -1
fi
export ORACLE_SID
ORACLE_HOME=`cat $oratab | grep -v "^#" | grep "Y$" | awk -F : '{print $2}' `
if [ ! -d $ORACLE_HOME ]; then
echo "the oracle's home directory "$ORACLE_HOME" is not exist..............!>>" | $LOGME
exit -1
fi
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/usr/lib:/bin:$HOME/bin:.
ORACLE_BASE=/u1/app/oracle
export ORACLE_BASE
ORACLE_SID=misdb
export ORACLE_SID
ORACLE_HOME=$ORACLE_BASE/product/8.1.6
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
LIBPATH=$LIBPATH:$ORACLE_HOME/lib
export LIBPATH
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export ORA_NLS33
export PATH
#############################################
## begin to dump the database
#############################################

#trying to connect oracle .....
if [ -e $TEMP ]; then
rm -f $TEMP
if [ ! $? -eq 0 ]; then
echo "" | $LOGME
exit -1
fi
fi

if [ -x $ORACLE_HOME/bin/tnsping ]; then
#$ORACLE_HOME/bin/tnsping $MY_ALIAS > $TEMP
tnsping $MY_ALIAS > $TEMP
ME=`cat $TEMP | grep "OK" | awk '{print $1}'`
if [ "$ME" != "OK" ]; then
echo "" | $LOGME
rm -f $TEMP
exit $?
else
echo "" | $LOGME
fi
fi

rm -f $TEMP

if [ -x $ORACLE_HOME/bin/exp ]; then
#MY_ALIAS
#cd $ORACLE_HOME/bin
#if [ ! $? -eq 0 ]; then
#echo "error
"
#exit 0
#fi

trap "" 1 2 3 15

#如果不用策略备份,则采用倒用户的方式,到出!!!!
#echo $TACTIC
#
#if [ "$TACTIC" = "Y" ]; then
#if [ -x $ORACLE_HOME/bin/svrmgrl ]; then
#svrmgrl

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-71488-1-1.html 上篇帖子: [转]c#上传下载ftp(支持断点续传) 下篇帖子: VB用API实现FTP上传文件,创建远程目录(类模块)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表