ORACLE 数据库自动备份脚本

#! /bin/bash
if  [ -f ~/.bashrc ];then
. ~/.bash_profile
fi
export script=/home/oracle/script
export bakdata_destination=/u02/rman_backup/data
export baklog_destination=/u02/rman_backup/log
export datadir=`date +'%Y_%m_%d'`
export days=`date +'%w'`
if ! test -d $script
then
   mkdir -p $script
fi

if ! test -d $bakdata_destination
then
   mkdir -p $bakdata_destination
fi

if ! test -d $baklog_destination
then
   mkdir -p $baklog_destination
fi

if [ $days -eq 1 ];then
#create the directory for datafile
if ! test -e $baklog_destination/failedlog.txt
then
  touch $baklog_destination/failedlog.txt
fi
if [ $? = 0 ];then
  echo "you is the frist create the failed file"
fi

if ! test -e $baklog_destination/successful.txt
then
   touch $baklog_destination/successful.txt
fi

if [ $? = 0 ] ; then
  echo "you is the frist creat the successful file"
fi

if ! test -d $bakdata_destination/$datadir
then
   mkdir $bakdata_destination/$datadir
fi

if [ $? -eq 1 ]; then
 echo "Error :Cann't create the directory,please check the reason! ">>$baklog_destination/failedlog.txt
fi
echo run {                      >$script/rman_level0.rman
echo "backup incremental level 0 database filesperset = 7 format '"$bakdata_destination/$datadir/bak0_`date '+%Y_%m_%d_%H_%M_%S'`.bak"';"       >>$script/rman_level0.rman
echo "sql /"ALTER SYSTEM ARCHIVE LOG CURRENT/"; ">>$script/rman_level0.rman
echo backup  archivelog all delete input   >>$script/rman_level0.rmanecho "format '"$bakdata_destination/$datadir/arc0_`date '+%Y_%m_%d_%H_%M_%S'`.bak"';"                  >>$script/rman_level0.rman
echo }                 >>$script/rman_level0.rman
if ! test -x ${script}/rman_level0.rman
then
    chmod +x $script/rman_level0.rman
    echo "xxxxxxxxxxxxx" $script/rman_level0.sh "now have the execute priviate"
    echo ""
fi

if [ $? -eq 1 ]
then   echo "chmod +x " $script/rman_level0.sh "failed">>$baklog_destination/failedlog.txt
fi

echo "#!/bin/bash">$script/rman_level0.sh
echo "source ~/.bash_profile">>$script/rman_level0.sh
echo "rman target sys/sys@passport @rman_level0.rman" >>$script/rman_level0.sh
if ! test -x $script/rman_level0.sh
then
chmod +x $script/rman_level0.sh
    echo "xxxxxxxxxxxxx" $script/rman_level0.sh "now have the execute priviate"
    echo ""
fi

if [ $? -eq 1 ]then   echo `date '+%Y.%m.%d-%H:%M:%M'` "chmod +x " $script/rman_level0.sh "failed">>$baklog_destination/failedlog.txt
fi
 . $script/rman_level0.sh  echo "backup incremental level 0 successfuly! at "`date '+%Y.%m.%d-%H:%M:%S'`>>$baklog_destination/successful.txt

else
#if [! $days -eq 1 ];then


if ! test -e $baklog_destination/failedlog.txt
then
touch $baklog_destination/failedlog.txt
fi
if [ $? = 0 ];then
  echo "you is the frist create the failed file"
fi

if ! test -e $baklog_destination/successful.txt
then
   touch $baklog_destination/successful.txtfi

if [ $? = 0 ] ; then
  echo "you is the frist creat the successful file"fi
if ! test -d $bakdata_destination/$datadir
then
   mkdir $bakdata_destination/$datadir
fi
if [ $? -eq 1 ]; then
echo "Error :Cann't create the directory,please check the reason! ">>$baklog_destination/failedlog.txt
fi
echo run {                      >$script/rman_level1.rmanecho "backup incremental level 1 database filesperset = 7 format '"$bakdata_destination/$datadir/bak1_`date '+%Y_%m_%d_%H_%M_%S'`.bak"';"       >>$script/rman_level1.rman
echo "sql /"ALTER SYSTEM ARCHIVE LOG CURRENT/"; ">>$script/rman_level1.rmanecho backup  archivelog all delete input   >>$script/rman_level1.rmanecho "format '"$bakdata_destination/$datadir/arc1_`date '+%Y_%m_%d_%H_%M_%S'`.bak"';"                  >>$script/rman_level1.rman
echo }                 >>$script/rman_level1.rman

if ! test -x ${script}/rman_level1.rman
then
    chmod +x $script/rman_level1.rman    echo "xxxxxxxxxxxxx" $script/rman_level1.rman "now have the execute priviate"
    echo ""
fi
echo "#!/bin/bash">$script/rman_level1.sh
echo "source ~/.bash_profile">>$script/rman_level1.shecho "rman target sys/sys@passport @rman_level1.rman" >>$script/rman_level1.sh

if ! test -x $script/rman_level1.sh
then    chmod +x $script/rman_level1.sh    echo "xxxxxxxxxxxxx" $script/rman_level1.sh "now have the execute priviate"
    echo ""
fi
if [ $? -eq 1 ]then   echo `date '+%Y.%m.%d-%H:%M:%M'` "chmod +x " $script/rman_level1.sh "failed">>$baklog_destination/failedlog.txt
fi
. $script/rman_level1.sh
echo backup incremental level 1 successfuly! at `date '+%Y.%m.%d-%H:%M:%S'`>>$baklog_destination/successful.txt
fi

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值