溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle 11G&12C備份腳本

發(fā)布時(shí)間:2020-07-03 14:24:55 來源:網(wǎng)絡(luò) 閱讀:270 作者:我不是九爺 欄目:云計(jì)算

#對某服務(wù)器上的多個(gè)用戶備份,自動刪除N天前的備份數(shù)據(jù)
#::::::::::::::::::::::::::::::::::::::::::::::::::::: 參數(shù)配置(需要管理員初始化)
# param_oracleServerBin?? ??? ??? ?可選?? ?Oracle Server Bin所在目錄
# param_LocalNetServicesName?? ?必選?? ?本地Net服務(wù)器名?? ?(tnsnames.ora中的名稱,而不是sid)

# param_homeBak_Local?? ??? ??? ?可選?? ?備份文件到本地?? ??? ?(dmp文件相關(guān))?? ?
# param_homeBak_Remote ?? ??? ??? ?可選?? ?備份文件復(fù)制到遠(yuǎn)程?? ?(dmp文件相關(guān))?? ?

# param_delFileDay_Local?? ??? ?可選?? ?刪除N天前本地備份?? ?(dmp文件相關(guān))
# param_delFileDay_Remote?? ??? ?可選?? ?刪除N天前遠(yuǎn)程備份?? ?(dmp文件相關(guān))
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=
#::::::::::::::::::::::::::::::::::::::::::::::::::::: 以下內(nèi)容不要調(diào)整
#=================? 生成日期 用于備份
export CurrentDateTime=`date +%Y%m%d%H%M%S` ?
#================= 重新設(shè)置變量
# Home_Backup 當(dāng)前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

#================= 創(chuàng)建文件夾,刪除N天前的備份文件夾
#創(chuàng)建文件夾
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
# 創(chuàng)建新的路徑+文件名
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

#================= 復(fù)制到遠(yuǎn)程
cp $homeBak_TimeFolder_Local/$CurrentDateTime*.* $homeBak_TimeFolder_Remote
#:::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "Bakup completed." ?

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI