基本的数据库配置

OS:AIX6.1

Oracle:10205 RAC

Ogg:11.2.1.0

 

RMAN备份策略

#* * * * * echo “AAAA”>>/tmp/abc.txt
0 2 * * 0 /oracle/misc/script/backup/bak_0.sh  >/dev/null 2<&1
0 2 * * 1-6 /oracle/misc/script/backup/bak_1.sh >/dev/null 2<&1
#0 0 * * 0 /oracle/misc/script/backup/bak_arc.sh >/dev/null 2<&1
#0 3 * * 0 /oracle/misc/script/backup/del_obsolete.sh  >/dev/null 2<&1
0 3  * * * /oracle/misc/script/backup/bak_arc_for_gg.sh >/dev/null 2<&1
0 4 * * 0 /oracle/misc/script/backup/bak_taps.sh  >/dev/null 2<&1

 

1.bak_0.sh

#!/bin/bash
#Author:lengbo
#date:20120628
#Purpose:For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/crs

export ORACLE_SID=peppdb1
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=”American_America.UTF8″

source ~/.profile
log_path=/oracle/misc/script/backup/logs
log=bak_0.log

cat /dev/null > $log_path/$log

if [ $? -ne 0 ];then
   echo “Clear $log Failed!…”>/tmp/$log
fi

 

 
rman target /  <<EOF >$log_path/$log
run{
allocate channel ch1 device type disk format ‘/backup/db_inc0_%d_%T_%s_%p.bak’  connect sys/syseasipay2012@peppdb1  maxpiecesize=8000m;
allocate channel ch2 device type disk format ‘/backup/db_inc0_%d_%T_%s_%p.bak’  connect sys/syseasipay2012@peppdb2  maxpiecesize=8000m;
crosscheck backup;
sql ‘alter system archive log thread 1 current’;
sql ‘alter system archive log thread 2 current’;
backup incremental level 0 tag ‘inc_0’ database include current controlfile;
release channel ch1;
release channel ch2;
}

EOF

echo “#########################################################”>>/tmp/rman.log
echo $log>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Errors put head in rman.log” >> /tmp/rman.log
fi

cat $log_path/$log >>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Error put rman.log messsage!” >> /tmp/rman.log
fi

 

2.bak_1.sh

#!/bin/bash
#Author: lengbo
#date:   20120628
#Purpose:For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/crs

export ORACLE_SID=peppdb1
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=”American_America.UTF8″
log_path=/oracle/misc/script/backup/logs
source ~/.profile

log=bak_1.log

cat /dev/null > $log_path/$log

if [ $? -ne 0 ];then
   echo “Clear $log Failed!…”>/tmp/$log
fi

rman target / <<EOF > $log_path/$log
run{
crosscheck backup;
allocate channel ch1 device type disk format ‘/backup/db_inc1_%d_%T_%s_%p.bak’  connect sys/syseasipay2012@peppdb1  maxpiecesize=8000m;
allocate channel ch2 device type disk format ‘/backup/db_inc1_%d_%T_%s_%p.bak’  connect sys/syseasipay2012@peppdb2  maxpiecesize=8000m;
sql ‘alter system archive log thread 1 current’;
sql ‘alter system archive log thread 2 current’;
backup incremental level 1 tag ‘inc_1’ database include current controlfile;
release channel ch1;
release channel ch2;
}

EOF

echo “#################################################################”>> /tmp/rman.log
echo $log>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Errors put head in rman.log” >> /tmp/rman.log
fi

cat $log_path/$log >>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Error put rman.log messsage!” >> /tmp/rman.log
fi

 

 3.bak_arc.sh(由于存在ogg,需要对archive log进行必要的限定保证Extract进程必要的抽取)

#!/bin/bash
#Author   :lengbo
#date     :20120628
#Purpose  :For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/crs

export ORACLE_SID=peppdb1
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=”American_America.UTF8″
log_path=/oracle/misc/script/backup/logs
source ~/.profile

log=bak_arc.log

cat /dev/null > $log_path/$log

if [ $? -ne 0 ];then
   echo “Clear $log Failed!…”>/tmp/$log
fi

rman target /  <<EOF > $log_path/$log
run{
crosscheck archivelog all;
allocate channel ch1 device type disk format ‘/backup/arc_%d_%T_%s_%p.bak’ connect sys/syseasipay2012@peppdb1  maxpiecesize=200000m;
allocate channel ch2 device type disk format ‘/backup/arc_%d_%T_%s_%p.bak’ connect sys/syseasipay2012@peppdb2  maxpiecesize=200000m;

backup archivelog  all tag ‘arc_bak ‘ delete all input;
}

EOF

echo “##################################################”>>/tmp/rman.log
echo $log>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Errors put head in rman.log” >> /tmp/rman.log
fi

cat $log_path/$log >>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Error put rman.log messsage!” >> /tmp/rman.log
fi

 

4.bak_taps.sh(保留7天的备份+归档作为缓冲,同时保证足够的archivelog 作为ogg的所需,超过7天的数据通过pax(存储大文件)到磁带机

查看ogg所需为 info extract ext1,showch

)

#!/bin/bash
#Author    :lengbo
#Date      :20120628
#Purpose   :For Database Backup
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/crs

export ORACLE_SID=peppdb2
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=”American_America.UTF8″
log_path=/oracle/misc/script/backup/logs
dt=$(date +’%F’)
item=bak_taps.log
log=$log_path/$item

bak=bak_$dt.tar.gz
#retention =7 days before
retention=7

#trap 10
#sleep 5
source ~/.profile
cat /dev/null > $log

if [ $? -ne 0 ];then
   echo “Clear $log Failed!…”> $log
fi

cd /backup

echo “————–List All Backup Files Summary Befor Compress:———–“>>$log
echo “—————-db_backup files:”>>$log
find db_backup/ -type f  >>$log
echo “—————-arc_backup files:”>>$log
find arc_backup/ -type f >>$log
echo “————————-Backup size before to Taps:———–“>>$log
du -sg db_backup >>$log
du -sg arc_backup >>$log
#Begin compress and backup
#tar -Zcvf $bak  arc_backup db_backup
tar -Zcvf $bak  arc_backup db_backup

if [ $? -ne 0 ];then
   echo “Warning,Tar Compress db_backup,arc_backup failed!”>>$log
else
   echo “OK!…   Tar Compress db_backup,arc_backup Succeed!” >>$log
fi

echo “————————Backup size after Compress————“>>$log
du -sg bak_$dt.tar.gz  >>$log
#Begin backup to Taps

echo “————————Begin Backup to Taps——————-“>>$log
pax -awvf /dev/rmt1 -x pax bak_$dt.tar.gz

if [ $? -ne 0 ]; then
   echo “Warning,Backup to Taps Failed!Please check it…” >>$log
   exit 1
else
   echo “OK,Backup to Taps!”>>$log
fi

#list Backup Files in Taps
echo “———————–Backups in Taps Summary:—————–“>>$log
pax -vf /dev/rmt1 -x pax >>$log

 

 
#Remove bak_$dt
rm bak_$dt.tar.gz
if [ $? -ne 0 ];then
   echo “Warning,Remove Tar Compress backup Failed,Pleas check it…”>>$log
else
   echo “OK,Remove Tar Compress backup Succeed!”>>$log
fi

#Clean /backup space
echo “———————–Clean /backup’s Space——————-“>>$log

find db_backup/ -type f -exec rm -f {} \;
if [ $? -ne 0 ];then
   echo “Warning,Remove db_backup files Failed,Please check it…”>>$log
else
   echo “OK,Remove db_backup files”>>$log
fi

find  arc_backup/arc_peppdb1/ -type f -exec rm -f {} \;
if [ $? -ne 0 ];then
   echo “Warning, Remove arc_peppdb1 files Failed,Please check it…”>>$log
else
   echo “OK,Remove arc_peppdb1 files Succeed!”>>$log
fi

find  arc_backup/arc_peppdb2/ -type f -exec rm -f {} \;
if [ $? -ne 0 ];then
   echo “Warning,Remove arc_peppdb2 files Failed,Please check it…”>>$log
else
   echo “OK,Remove arc_peppdb2 files Succeed!”>>$log
fi
echo “===================================================================”>>/tmp/rman.log
echo “==============================Backup To Taps ======================”>>/tmp/rman.log
#After bak_0,bak_1 in 3 o’clock,for it’s logs to /tmp/rman.log

cat $log>>/tmp/rman.log
if [ $? -ne 0 ];then
   echo “Warning,Backup Taps’s log to  rman.log Failed!” >> /tmp/rman.log
fi