Rman 备份和删除
一 脚本
1.1 fullback.sh
#!/bin/bash
/bin/sh /home/oracle/.bash_profile
#export ORACLE_BASE=/u01/app/oracle
#export ORACLE_SID=orcl
#ORACLE_HOME=$ORACLE_BASE/11.2.0/db_1; export ORACLE_HOME
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
#PATH=/usr/sbin:$PATH; export PATH
#PATH=$ORACLE_HOME/bin:$PATH; export PATH
#LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
#CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
#export CLASSPATH
TODAY=`date +%Y_%m_%d`
su - oracle -c "rman nocatalog target / cmdfile /home/oracle/fullback.rcv log /home/oracle/fullbackup_$TODAY.log"
find /home/oracle/oraclebackup/ -type f -name "fullback*" -mtime +7 -exec rm -rf {} \;
1.2 fullback.rcv
run{
allocate channel c4 type disk format '/home/oracle/oraclebackup/fullback_%d_%u_%s_%p';
backup as compressed backupset
skip inaccessible
tag fullbackupwitharchivelog
(database);
backup current controlfile;
backup spfile;
sql "alter system archive log current";
delete noprompt obsolete;
release channel c4;
}
1.3 rman_delete.sh
sh /home/oracle/.bash_profile
LOGFILE=/home/oracle/rman_delete.log
RMAN=$ORACLE_HOME/bin/rman
WEEK=$((`date +%w`))
date=`date +%Y-%m-%d`
echo "----------------------------begin backup ----------------------------------" >> $LOGFILE
date >>$LOGFILE
sh /home/oracle/archive_delete.sh $RMAN $LOGFILE
date >>$LOGFILE
echo "---------------------------end backup ---------" >> $LOGFILE
1.4 archive_delete.sh
$ORACLE_HOME/bin/rman <<EOF
connect target /
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-15';
exit;
EOF
二. 定时任务
01 08 * * * /bin/sh /home/oracle/fullback.sh
00 09 * * * /bin/sh /home/oracle/rman_delete.sh
三. 常用命令
- cron 是一个 linux 下 的定时执行工具,可以在无需人工干预的情况下运行作业
service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看服务状态
- 编辑和查看定时任务
编辑:crontab -e
查看:crontab -l
- 实时查看定时任务执行日志
tail -f /var/log/cron
附件:
Rman.zip