废话不多说了,直接给大家贴代码了,具体代码如下所示:
$installdir/runback.sh
echo “nowdate=\$(date +%Y-%m-%d_%k.%M.%S)”>>$installdir/runback.sh
echo “nowmouth=\$(date +%Y-%m)”>>$installdir/runback.sh
echo “echo \”\$nowdate开始备份…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
scount=0
snum=${#username[@]}
while [ $scount -lt $snum ]
do
echo “exp ${username[$scount]}/${password[$scount]}@${sname[$scount]} file=$installdir/temp/${username[$scount]}_${sname[$scount]}\$nowdate.dmp compress=N>>$installdir/logs/\$nowmouth.log 2>&1”>>$installdir/runback.sh
scount=$(($scount+1))
done
echo “echo \”\$(date +%Y-%m-%d_%k.%M.%S)完成备份…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
echo “echo \”\$(date +%Y-%m-%d_%k.%M.%S)开始打包…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
echo “gzip $installdir/zip/\$nowdate.zip $installdir/temp/>>$installdir/logs/\$nowmouth.log 2>&1”>>$installdir/runback.sh
echo “rm -Rvf $installdir/temp/*>>$installdir/logs/\$nowmouth.log 2>&1”>>$installdir/runback.sh
echo “echo \”\$(date +%Y-%m-%d_%k.%M.%S)打包完成…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
scount=0
if [ ${#rtype[@]} -ne 0 ]
then
echo “echo \”\$(date +%Y-%m-%d_%k.%M.%S)进行远程备份…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
snum=${#rtype[@]}
while [ $scount -lt $snum ]
do
echo “lftp -u ${rname[$scount]},${rpass[$scount]} ${rtype[$scount]}://${rurl[$scount]}<$installdir/runback.sh
echo “mkdir remotedbback”>>$installdir/runback.sh
echo “cd remotedbback”>>$installdir/runback.sh
echo “mput $installdir/zip/\$nowdate.zip”>>$installdir/runback.sh
echo “exit”>>$installdir/runback.sh
echo “remote”>>$installdir/runback.sh
scount=$(($scount+1))
done
echo “echo \”\$(date +%Y-%m-%d_%k.%M.%S)完成远程备份…………………………………\”>>$installdir/logs/\$nowmouth.log”>>$installdir/runback.sh
fi
echo “exit 0”>>$installdir/runback.sh
chmod 775 $installdir/runback.sh
chown $execuser $installdir/runback.sh
echo “生成备份执行文件完成……………………….”
echo “开始定制值守时间…………………………..”
scount=0
snum=${#backtime[@]}
while [ $scount -lt $snum ]
do
echo “${backtime[$scount]} $installdir/runback.sh”>>$installdir/planlist
scount=$(($scount+1))
done
su -l -c”crontab $installdir/planlist” oracle
echo “完成值守时间定制…………………………..”
exit 0
接下来给大家介绍linux oracle自动备份脚本
1、备份脚本:
2、添加到任务调度
crontab -u oracle -e
* 3 * * * /home/bakup/bakup.sh
即每天凌晨3点进行备份
如需每天备份多次,可设置不同时间段备份:
例如:* 3,13,18 * * * /home/bakup/bakup.sh,即每天3点、13点、18点进行备份。
说明:文件备份目录,用户oracle必须有更改权限,否则无法备份。