ITPub博客

首页 > 数据库 > Oracle > rman备份脚本

rman备份脚本

原创 Oracle 作者:九十一万里 时间:2017-08-18 11:42:33 0 删除 编辑
以前公司使用的em备份,来着家公司之后,客户的1158端口不对外开放,要求用rman备份,于是写这个自动备份脚本;
#!/bin/bash
# chkconfig: 345 99 10
# description: script for the SMS MESSAGE OR Oracle Instance, Listener
#Choose to run the script by week
#The script will automatically choose the backup level
#software make : muxinqing
time=$(date +%A)
ora=$(ps aux | grep ora | grep -v "grep" |  wc -l)


case $time in


'Monday')


#cmdfile=/backup/script/backup_0_level
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log" <<m
run
{allocate channel orademo type disk;
backup incremental level 0  as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Tuesday')


if [ $ora -ne 0  ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;
'Wednesday')


if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 1 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;


'Thursday')




if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;


'Friday')


if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;


'Saturday')
if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"
fi
;;


'Sunday')


if [ $ora -ne 0 ]; then
su - oracle -c "rman target / msglog=/app/backup/rman.log"  << m
run
{allocate channel orademo type disk;
backup incremental level 2 cumulative as compressed backupset database include current controlfile format '/app/backup/db_%s_%p_%t' plus archivelog format  '/app/backup/arch_%s_%p_%t' delete input;
crosscheck backup;
delete expired backup;
Delete noprompt obsolete;
}
m
else
echo "file not exist"


fi


esac

执行一个定时任务就完成自动备份了

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31477110/viewspace-2143772/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
一个oracle没有入门的dba

注册时间:2017-07-20

  • 博文量
    21
  • 访问量
    93447