configure retention policy to recovery window of 15 days;
delete noprompt obsolete;
release channel d1;
release channel d2;
}
EOF
else
echo "$i's full db backup on $current_day has been completed;"
fi
done
4.2归档日志备份脚本:
vi /home/oracle/arclog_bak.sh
#! /bin/bash
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
current_day=`date +%Y%m%d`
basdir=/home/oracle/rmanbackup
for i in {orcl,prod}
do
export ORACLE_SID=${i}"1"
Rdir=$basdir/$i
if [ ! -d $Rdir/$current_day ]
then
mkdir -p $Rdir/$current_day
rman target / <<EOF
run{
allocate channel d1 type disk maxpiecesize=30G;
allocate channel d2 type disk maxpiecesize=30G;
sql 'alter system archive log current';
backup archivelog all not backed up 1 times format '$Rdir/$current_day/arclog_%d_%T_%u.bkp';
backup spfile format '$Rdir/$current_day/spfile_%d_%T_%u.bkp';
backup current controlfile format '$Rdir/$current_day/controlfile_%d_%T_%u.bkp';
crosscheck backup;
delete noprompt expired backup;
configure retention policy to recovery window of 15 days;
delete noprompt obsolete;
release channel d1;
release channel d2;
}
EOF
else
echo "$i's archivelog backup on $current_day has been completed;"
fi
done
说明:
%d:Oracle数据库名称
%T:当前时间的年月日格式(YYYYMMDD)
%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称
4.3日志删除脚本:
vi /home/oracle/del_arclog_bak.sh
#! /bin/bash
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
basdir=/home/oracle/rmanbackup
current_day=`date +%Y%m%d`
for i in {orcl,prod}
do
export ORACLE_SID=${i}"1"
rman target / <<EOF
run{
delete noprompt archivelog all completed before 'sysdate-30';
}
EOF
done
4.4备份空文删脚本:
vi /home/oracle/del_db_bak.sh
#!/bin/bash
removedir=/home/oracle/rmanbackup
dt=`date +%Y%m%d -d "15 day ago"`
current_day=`date +%Y%m%d`
for i in {orcl,prod}
do
Rdir=$removedir/$i
for subdir in `ls $Rdir`;
do
if [ "${subdir}" -lt "${dt}" ];
then
rm -rf $Rdir/$subdir >/dev/null
echo "on $current_day the directory $Rdir/$subdir has been removed."
fi
done
done
5.调试脚本
5.1更改脚本具有可执行权限
su - oracle
chmod u+x full_bak.sh
chmod u+x arclog_bak.sh
chmod u+x del_arclog_bak.sh
chmod u+x del_db_bak.sh
5.2设置定时任务前调试脚本
于脚本当前路径下执行,测试脚本
./full_bak.sh >> full_bak.log 2>&1
./arclog_bak.sh >> arclog_bak.log 2>&1
./del_arclog_bak.sh >> del_arclog.log 2>&1
./del_db_bak.sh >> del_bak.log 2>&1
6.配置定时任务执行脚本
在节点1上执行:
=========================
输入crontab -e
按下a键进入到编辑模式
输入如下
10 0 * * 1,4,6 /home/oracle/full_bak.sh >> /home/oracle/rmanbackup/backup.log 2>&1
10 0 * * 2,3,5,0 /home/oracle/arclog_bak.sh >> /home/oracle/rmanbackup/backup.log 2>&1
10 2 * * * /home/oracle/del_arclog_bak.sh >> /home/oracle/rmanbackup/del.log 2>&1
10 3 * * * /home/oracle/del_db_bak.sh >> /home/oracle/rmanbackup/del.log 2>&1
同时按下ctrl+c退出编辑模式
按下shift+: 输入wq 退出 crontab
crontab -l 查看已经建立的定时任务
原文地址:http://blog.51cto.com/candice/2094682