Oracle11G&12C备份脚本-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

Oracle11G&12C备份脚本

#对某服务器上的多个用户备份,自动删除N天前的备份数据
#::::::::::::::::::::::::::::::::::::::::::::::::::::: 参数配置(需要管理员初始化)
# param_oracleServerBin            可选    Oracle Server Bin所在目录
# param_LocalNetServicesName    必选    本地Net服务器名    (tnsnames.ora中的名称,而不是sid)

# param_homeBak_Local            可选    备份文件到本地        (dmp文件相关)    
# param_homeBak_Remote             可选    备份文件复制到远程    (dmp文件相关)    

# param_delFileDay_Local        可选    删除N天前本地备份    (dmp文件相关)
# param_delFileDay_Remote        可选    删除N天前远程备份    (dmp文件相关)
echo "==================================================="  
export param_homeBak_Local=/opt/backup
export param_homeBak_Remote=

export param_delFileDay_Local=
export param_delFileDay_Remote=

export param_oracleHome=/data/oracle/product/11.2.0/dbhome_1
export param_LocalNetServicesName=ORCL

export User01=NC20181113
export User02=
export User03=
export User04=
export User05=
export User06=
export User07=
export User08=
export User09=
export User10=
export User11=
export User12=
export User13=
export User14=
export User15=

export Pass01=NC20181113
export Pass02=
export Pass03=
export Pass04=
export Pass05=
export Pass06=
export Pass07=
export Pass08=
export Pass09=
export Pass10=
export Pass11=
export Pass12=
export Pass13=
export Pass14=
export Pass15=
#::::::::::::::::::::::::::::::::::::::::::::::::::::: 以下内容不要调整
#=================  生成日期 用于备份
export CurrentDateTime=`date +%Y%m%d%H%M%S`  
#================= 重新设置变量
# Home_Backup 当前sh位置
export Home_Backup=$(pwd)
export HomeBak_Local=$Home_Backup
export HomeBak_Remote=$Home_Backup

if [[ $param_homeBak_Local != "" ]] ; then export HomeBak_Local=$param_homeBak_Local ;fi
if [[ $param_homeBak_Remote != "" ]] ; then export HomeBak_Remote=$param_homeBak_Remote ;fi

if [[ $param_delFileDay_Local = "" ]] ; then export param_delFileDay_Local=7 ;fi
if [[ $param_delFileDay_Remote = "" ]] ; then export param_delFileDay_Remote=1 ;fi

export HomeBak_KeyName=OracleDb

export HomeBak_Local=$HomeBak_Local/$HomeBak_KeyName"_bakLocal"
export HomeBak_Remote=$HomeBak_Remote/$HomeBak_KeyName"_bakRemote"

export homeBak_TimeFolder=$CurrentDateTime"_"$HomeBak_KeyName

export homeBak_TimeFolder_Local=$HomeBak_Local
export homeBak_TimeFolder_Remote=$HomeBak_Remote

#================= 创建文件夹,删除N天前的备份文件夹
#创建文件夹
mkdir -p $homeBak_TimeFolder_Local
mkdir -p $HomeBak_Remote
#删除N天前文件
find $homeBak_TimeFolder_Local -mtime +$param_delFileDay_Local -name "*.*" -exec rm -rf {} \;
find $homeBak_TimeFolder_Remote -mtime +$param_delFileDay_Remote -name "*.*" -exec rm -rf {} \;

#================= 备份Oracle
# 创建新的路径+文件名
export FileName_01=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User01
export FileName_02=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User02
export FileName_03=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User03
export FileName_04=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User04
export FileName_05=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User05
export FileName_06=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User06
export FileName_07=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User07
export FileName_08=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User08
export FileName_09=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User09
export FileName_10=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User10
export FileName_11=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User11
export FileName_12=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User12
export FileName_13=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User13
export FileName_14=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User14
export FileName_15=$homeBak_TimeFolder_Local/$CurrentDateTime"_"$User15

export ORACLE_HOME=$param_oracleHome
export PATH=$ORACLE_HOME/bin:$PATH

if [[ $User01 != "" ]] && [[ $Pass01 != "" ]] ; then exp $User01/$Pass01@$param_LocalNetServicesName owner=$User01 file=$FileName_01.dmp log=$FileName_01.log ;fi
if [[ $User02 != "" ]] && [[ $Pass02 != "" ]] ; then exp $User02/$Pass02@$param_LocalNetServicesName owner=$User02 file=$FileName_02.dmp log=$FileName_02.log ;fi
if [[ $User03 != "" ]] && [[ $Pass03 != "" ]] ; then exp $User03/$Pass03@$param_LocalNetServicesName owner=$User03 file=$FileName_03.dmp log=$FileName_03.log ;fi
if [[ $User04 != "" ]] && [[ $Pass04 != "" ]] ; then exp $User04/$Pass04@$param_LocalNetServicesName owner=$User04 file=$FileName_04.dmp log=$FileName_04.log ;fi
if [[ $User05 != "" ]] && [[ $Pass05 != "" ]] ; then exp $User05/$Pass05@$param_LocalNetServicesName owner=$User05 file=$FileName_05.dmp log=$FileName_05.log ;fi
if [[ $User06 != "" ]] && [[ $Pass06 != "" ]] ; then exp $User06/$Pass06@$param_LocalNetServicesName owner=$User06 file=$FileName_06.dmp log=$FileName_06.log ;fi
if [[ $User07 != "" ]] && [[ $Pass07 != "" ]] ; then exp $User07/$Pass07@$param_LocalNetServicesName owner=$User07 file=$FileName_07.dmp log=$FileName_07.log ;fi
if [[ $User08 != "" ]] && [[ $Pass08 != "" ]] ; then exp $User08/$Pass08@$param_LocalNetServicesName owner=$User08 file=$FileName_08.dmp log=$FileName_08.log ;fi
if [[ $User09 != "" ]] && [[ $Pass09 != "" ]] ; then exp $User09/$Pass09@$param_LocalNetServicesName owner=$User09 file=$FileName_09.dmp log=$FileName_09.log ;fi
if [[ $User10 != "" ]] && [[ $Pass10 != "" ]] ; then exp $User10/$Pass10@$param_LocalNetServicesName owner=$User10 file=$FileName_10.dmp log=$FileName_10.log ;fi
if [[ $User11 != "" ]] && [[ $Pass11 != "" ]] ; then exp $User11/$Pass11@$param_LocalNetServicesName owner=$User11 file=$FileName_11.dmp log=$FileName_11.log ;fi
if [[ $User12 != "" ]] && [[ $Pass12 != "" ]] ; then exp $User12/$Pass12@$param_LocalNetServicesName owner=$User12 file=$FileName_12.dmp log=$FileName_12.log ;fi
if [[ $User13 != "" ]] && [[ $Pass13 != "" ]] ; then exp $User13/$Pass13@$param_LocalNetServicesName owner=$User13 file=$FileName_13.dmp log=$FileName_13.log ;fi
if [[ $User14 != "" ]] && [[ $Pass14 != "" ]] ; then exp $User14/$Pass14@$param_LocalNetServicesName owner=$User14 file=$FileName_14.dmp log=$FileName_14.log ;fi
if [[ $User15 != "" ]] && [[ $Pass15 != "" ]] ; then exp $User15/$Pass15@$param_LocalNetServicesName owner=$User15 file=$FileName_15.dmp log=$FileName_15.log ;fi

#================= 复制到远程
cp $homeBak_TimeFolder_Local/$CurrentDateTime*.* $homeBak_TimeFolder_Remote
#:::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "Bakup completed."  

创新互联于2013年开始,先为玉林等服务建站,玉林等地企业,进行企业商务咨询服务。为玉林企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。


网站栏目:Oracle11G&12C备份脚本
本文来源:http://kswsj.cn/article/ghopcs.html

其他资讯