Oracle数据库RMAN的自动备份脚本
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#Oracleauto backup using rman
#
# author:songrh
# week:1,3,6 Level 0 backup
# 2,4,5,0 Level 1 backup
# Copyright by ChenLong Tec
#--------------------------------------------
FTPUSER="ftpbak"
FTPPASS="******"
FTPROOT0="L0"
FTPROOT1="L1"
#
DISK_USE=`df -k |sed -n '/u02/'p | awk '{print $5}' |sed 's/%//'`
####check path function
############
bi
mput *
bye
FTPIT
export NLS_LANG=american_america.ZHS16GBK
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NL33=$ORACLE_HOME/ocommon/nls/admin/data
export PATH=/bin:/usr/bin:/usr/sbin:$ORACLE_HOME/bin:$PATH
release channel c0;
}
#crosscheck backup;
#delete noprompt expired backup;
#delete noprompt obsolete;
EOF
db_l1_backup.sh一级备份程序
#!/bin/bash
L1_PATH=$1
DAY_TAG=`date "%Y-%m-%d"`
backup tag 'L1_spfile_bak' format '$L1_PATH/L1_%d_SPFILE_s.%s_p.%p_%T.bak' spfile;
backup tag 'L1_ctl_bak' format '$L1_PATH/L1_%d_CTL_s.%s_p.%p_%T.bak' current controlfile;
rename 0 0.bak
mkdir 0
cd /
cd /$_FTPROOT/3
mdelete *
cd /$_FTPROOT/6.bak
mdelete *
cd /$_FTPROOT
rmdir 6.bak
rename 6 6.bak
mkdir 6
cd /$_FTPROOT/$_WEEK
mdelete *
#
#
export ORACLE_BASE=/u02/oracle
export ORACLE_HOME=/u02/oracle/product/9.2.4
export ORACLE_SID=PROD
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib
ftp -d -i -n > $_LOG 2>>$_LOG
open $_IP
user $_FTPUSER $_FTPPASS
cd $_FTPROOT/$_WEEK
bi
mdelete *
mput *
bye
FTPIT
FTP目录维护程序
#!/bin/bash
_IP=$1
_FTPUSER=$2
_FTwk.baidu.comPASS=$3
rmanbak :数据库备份文件的保存目录
rmanscripts :数据库脚本存放路径
5、FTP目录
ftp上必须手动建立目录
L0:
---1
---3
---6
---6.bak
L1:
---2
---4
---5
---0
---0.bak
rman_bak.sh脚本主程序
#!/bin/bash
#--------------------------------------------
mkdir $L1_PATH/$WEEK
$SH_PATH/db_l1_backup.sh $L1_PATH/$WEEK
cd $L1_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT1 $WEEK $WEEK_$LOG_TAG.log
else
$SH_PATH/ftp_del.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
else
if [ ! -d $L0_PATH/$WEEK ]; then
mkdir $L0_PATH/$WEEK
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
export PATH=$PATH:/opt/local/bin
#
SH_PATH=/u02/rmanscripts
ARC_PATH=/u02/arch
RMAN_BAK_PATH=/u02/rmanbak
#
#FULL_PATH=$RMAN_BAK_PATH/full
L0_PATH=$RMAN_BAK_PATH/L0
cd $L0_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
else
rm -rf $L0_PATH/$WEEK/*
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
rm -rf $L1_PATH/$WEEK/*
$SH_PATH/db_l1_backup.sh $L1_PATH/$WEEK
cd $L1_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT1 $WEEK $WEEK_$LOG_TAG.log
fi
fi
db_l0_backup.sh零级备份程序
#!/bin/bash
L0_PATH=$1
DAY_TAG=`date "%Y-%m-%d"`
rman target / nocatalog msglog $L0_PATH/L0_db_backup_$DAY_TAG.log /dev/null
run{
_WEEK=$5
_LOG=$6
#_FILE=$7
echo "..................FTP Trans $_IP...................." >>$_LOG
date "%Y-%m-%d-%T:FTP $_IP Trans Begin..." >> $_LOG 2>>$_LOG
rman_bak.sh :数据备份主程序
3、备份原理
每周1、3、6进行0级备份
每周日、2、4、5进行1级备份
备份文件上传到FTP服务器
FTP服务器每周清理一次,但是清理后将周六和周日的备份进行保留(6.bak和0.bak)
所有工作防暑crontab中自动执行备份
4、备份目录含义
arc :数据库归档目录
Oracle数据库RMAN的自动备份脚本
1、数据库设置为归档方式
2、数据库的备份脚本
db_full_backup.sh :数据库全备脚本
db_l0_backup.sh :数据库0级备份脚本
db_l1_backup.sh :数据库1级备份脚本
ftp.sh:数据FTP上传脚本
ftp_del.sh :数据FTP清理脚本
_FTPROOT=$4
_WEEK=$5
_LOG=$6
#_FILE=$7
echo "..................FTP Delete And Trans $_IP...................." >>$_LOG
date "%Y-%m-%d-%T:FTP $_IP Begin..." >> $_LOG 2>>$_LOG
cd $L0_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
fi
fi
else
if [ ! -d $L1_PATH ]; then
mkdir $L1_PATH
fi
if [ ! -d $L1_PATH/$WEEK ]; then
release channel c1;
}
#crosscheck backup;
#delete noprompt expired backup;
#delete noprompt obsolete;
EOF
FTP主程序
#!/bin/bash
_IP=$1
_FTPUSER=$2
_FTPPASS=$3
_FTPROOT=$4
backup tag 'L0_spfile_bak' format '$L0_PATH/L0_%d_SPFILE_s.%s_p.%p_%T.bak' spfile;
backup tag 'L0_ctl_bak' format '$L0_PATH/L0_%d_CTL_s.%s_p.%p_%T.bak' current controlfile;
ftp -d -i -n > $_LOG 2>>$_LOG
open $_IP
user $_FTPUSER $_FTPPASS
cd /l1/2
mdelete *
cd /l1/4
mdelete *
cd /l1/5
mdelete *
cd /l1/0.bak
mdelete *
cd /l1
rmdir 0.bak
rman target / nocatalog msglog $L1_PATH/L1_db_backup_$DAY_TAG.log /dev/null
run{
allocate channel c1 type disk;
backup incremental level 1 database tag 'L1_dbf_bak' format '$L1_PATH/L1_%d_DF_s.%s_p.%p_%T.bak' plus archivelog tag 'L1_arc_bak' format '$L1_PATH/L1_%d_ARC_s.%s_p.%p_%T.bak' delete all input;
allocate channel c0 type disk;
backup incremental level 0 database tag 'L0_dbf_bak' format '$L0_PATH/L0_%d_DF_s.%s_p.%p_%T.bak' plus archivelog tag 'L0_arc_bak' format '$L0_PATH/L0_%d_ARC_s.%s_p.%p_%T.bak' delete all input;
mkdir $L0_PATH
fi
if [ "$WEEK" = "1" ]; then
rm -rf $L0_PATH/*
rm -rf $L1_PATH/*
mkdir $L0_PATH/$WEEK
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
cd $L0_PATH/$WEEK
if [[ $DISK_USE -ge 90 ]]; then
rm -rf $L0_PATH/*
rm -rf $L1_PATH/*
fi
if [ "$WEEK" = "6" -o "$WEEK" = "3" -o "$WEEK" = "1" ]; then
if [ ! -d $L0_PATH ]; then
L1_PATH=$RMAN_BAK_PATH/L1
#
#DAY_TAG=`date "%Y-%m-%d"`
LOG_TAG=`date "%Y-%m-%d"`
#FIRST_DAY=`date %e`
WEEK=`date %w`
#WEEK=1
#
# FTP configure
IP="122.120.150.155"
#
# author:songrh
# week:1,3,6 Level 0 backup
# 2,4,5,0 Level 1 backup
# Copyright by ChenLong Tec
#--------------------------------------------
FTPUSER="ftpbak"
FTPPASS="******"
FTPROOT0="L0"
FTPROOT1="L1"
#
DISK_USE=`df -k |sed -n '/u02/'p | awk '{print $5}' |sed 's/%//'`
####check path function
############
bi
mput *
bye
FTPIT
export NLS_LANG=american_america.ZHS16GBK
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NL33=$ORACLE_HOME/ocommon/nls/admin/data
export PATH=/bin:/usr/bin:/usr/sbin:$ORACLE_HOME/bin:$PATH
release channel c0;
}
#crosscheck backup;
#delete noprompt expired backup;
#delete noprompt obsolete;
EOF
db_l1_backup.sh一级备份程序
#!/bin/bash
L1_PATH=$1
DAY_TAG=`date "%Y-%m-%d"`
backup tag 'L1_spfile_bak' format '$L1_PATH/L1_%d_SPFILE_s.%s_p.%p_%T.bak' spfile;
backup tag 'L1_ctl_bak' format '$L1_PATH/L1_%d_CTL_s.%s_p.%p_%T.bak' current controlfile;
rename 0 0.bak
mkdir 0
cd /
cd /$_FTPROOT/3
mdelete *
cd /$_FTPROOT/6.bak
mdelete *
cd /$_FTPROOT
rmdir 6.bak
rename 6 6.bak
mkdir 6
cd /$_FTPROOT/$_WEEK
mdelete *
#
#
export ORACLE_BASE=/u02/oracle
export ORACLE_HOME=/u02/oracle/product/9.2.4
export ORACLE_SID=PROD
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib
ftp -d -i -n > $_LOG 2>>$_LOG
open $_IP
user $_FTPUSER $_FTPPASS
cd $_FTPROOT/$_WEEK
bi
mdelete *
mput *
bye
FTPIT
FTP目录维护程序
#!/bin/bash
_IP=$1
_FTPUSER=$2
_FTwk.baidu.comPASS=$3
rmanbak :数据库备份文件的保存目录
rmanscripts :数据库脚本存放路径
5、FTP目录
ftp上必须手动建立目录
L0:
---1
---3
---6
---6.bak
L1:
---2
---4
---5
---0
---0.bak
rman_bak.sh脚本主程序
#!/bin/bash
#--------------------------------------------
mkdir $L1_PATH/$WEEK
$SH_PATH/db_l1_backup.sh $L1_PATH/$WEEK
cd $L1_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT1 $WEEK $WEEK_$LOG_TAG.log
else
$SH_PATH/ftp_del.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
else
if [ ! -d $L0_PATH/$WEEK ]; then
mkdir $L0_PATH/$WEEK
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
export PATH=$PATH:/opt/local/bin
#
SH_PATH=/u02/rmanscripts
ARC_PATH=/u02/arch
RMAN_BAK_PATH=/u02/rmanbak
#
#FULL_PATH=$RMAN_BAK_PATH/full
L0_PATH=$RMAN_BAK_PATH/L0
cd $L0_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
else
rm -rf $L0_PATH/$WEEK/*
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
rm -rf $L1_PATH/$WEEK/*
$SH_PATH/db_l1_backup.sh $L1_PATH/$WEEK
cd $L1_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT1 $WEEK $WEEK_$LOG_TAG.log
fi
fi
db_l0_backup.sh零级备份程序
#!/bin/bash
L0_PATH=$1
DAY_TAG=`date "%Y-%m-%d"`
rman target / nocatalog msglog $L0_PATH/L0_db_backup_$DAY_TAG.log /dev/null
run{
_WEEK=$5
_LOG=$6
#_FILE=$7
echo "..................FTP Trans $_IP...................." >>$_LOG
date "%Y-%m-%d-%T:FTP $_IP Trans Begin..." >> $_LOG 2>>$_LOG
rman_bak.sh :数据备份主程序
3、备份原理
每周1、3、6进行0级备份
每周日、2、4、5进行1级备份
备份文件上传到FTP服务器
FTP服务器每周清理一次,但是清理后将周六和周日的备份进行保留(6.bak和0.bak)
所有工作防暑crontab中自动执行备份
4、备份目录含义
arc :数据库归档目录
Oracle数据库RMAN的自动备份脚本
1、数据库设置为归档方式
2、数据库的备份脚本
db_full_backup.sh :数据库全备脚本
db_l0_backup.sh :数据库0级备份脚本
db_l1_backup.sh :数据库1级备份脚本
ftp.sh:数据FTP上传脚本
ftp_del.sh :数据FTP清理脚本
_FTPROOT=$4
_WEEK=$5
_LOG=$6
#_FILE=$7
echo "..................FTP Delete And Trans $_IP...................." >>$_LOG
date "%Y-%m-%d-%T:FTP $_IP Begin..." >> $_LOG 2>>$_LOG
cd $L0_PATH/$WEEK
$SH_PATH/ftp.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log
fi
fi
else
if [ ! -d $L1_PATH ]; then
mkdir $L1_PATH
fi
if [ ! -d $L1_PATH/$WEEK ]; then
release channel c1;
}
#crosscheck backup;
#delete noprompt expired backup;
#delete noprompt obsolete;
EOF
FTP主程序
#!/bin/bash
_IP=$1
_FTPUSER=$2
_FTPPASS=$3
_FTPROOT=$4
backup tag 'L0_spfile_bak' format '$L0_PATH/L0_%d_SPFILE_s.%s_p.%p_%T.bak' spfile;
backup tag 'L0_ctl_bak' format '$L0_PATH/L0_%d_CTL_s.%s_p.%p_%T.bak' current controlfile;
ftp -d -i -n > $_LOG 2>>$_LOG
open $_IP
user $_FTPUSER $_FTPPASS
cd /l1/2
mdelete *
cd /l1/4
mdelete *
cd /l1/5
mdelete *
cd /l1/0.bak
mdelete *
cd /l1
rmdir 0.bak
rman target / nocatalog msglog $L1_PATH/L1_db_backup_$DAY_TAG.log /dev/null
run{
allocate channel c1 type disk;
backup incremental level 1 database tag 'L1_dbf_bak' format '$L1_PATH/L1_%d_DF_s.%s_p.%p_%T.bak' plus archivelog tag 'L1_arc_bak' format '$L1_PATH/L1_%d_ARC_s.%s_p.%p_%T.bak' delete all input;
allocate channel c0 type disk;
backup incremental level 0 database tag 'L0_dbf_bak' format '$L0_PATH/L0_%d_DF_s.%s_p.%p_%T.bak' plus archivelog tag 'L0_arc_bak' format '$L0_PATH/L0_%d_ARC_s.%s_p.%p_%T.bak' delete all input;
mkdir $L0_PATH
fi
if [ "$WEEK" = "1" ]; then
rm -rf $L0_PATH/*
rm -rf $L1_PATH/*
mkdir $L0_PATH/$WEEK
$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK
cd $L0_PATH/$WEEK
if [[ $DISK_USE -ge 90 ]]; then
rm -rf $L0_PATH/*
rm -rf $L1_PATH/*
fi
if [ "$WEEK" = "6" -o "$WEEK" = "3" -o "$WEEK" = "1" ]; then
if [ ! -d $L0_PATH ]; then
L1_PATH=$RMAN_BAK_PATH/L1
#
#DAY_TAG=`date "%Y-%m-%d"`
LOG_TAG=`date "%Y-%m-%d"`
#FIRST_DAY=`date %e`
WEEK=`date %w`
#WEEK=1
#
# FTP configure
IP="122.120.150.155"