Chinaunix首页 | 论坛 | 博客
  • 博客访问: 395196
  • 博文数量: 99
  • 博客积分: 5134
  • 博客等级: 大校
  • 技术积分: 1607
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 09:31
文章分类

全部博文(99)

文章存档

2011年(48)

2010年(40)

2009年(10)

2008年(1)

分类:

2009-12-14 15:30:32

sh xxxx.sh full 完全备份
sh xxxx.sh inc  增量备份
 
 
 
#!/bin/sh
_MYSQL_BACK_DIR="/letv/backup/mysql.backup/"
_ORACLE_BACK_DIR="/data/backup.database/oracle/"
_log_file="/data/backup.database/oracle/db.backup.log"
_DEL_DAY=7

export _seed_file="/data/backup.database/oracle/backup.seed"
export _now_time=`date +%F-%H-%M`
export _OLD_DAY=`date -d "${_DEL_DAY} days ago" +%F`
###_ACTION is {full|inc}
_ACTION=$1
function do_mysql()
{
cd ${_MYSQL_BACK_DIR}
echo "`date +%F-%H.%M` mysql backup started... "
mysqldump -uroot -F -A > `date +%F-%H-%M`.sql && gzip `date +%F-%H-%M`.sql || return 10
echo "Now delete the old backups:\"${_OLD_DAY}\"..."
[ ! -z "${_OLD_DAY}" ] && rm -f ${_OLD_DAY}*
echo  "#################################################################################"

}
 
if [ "${_ACTION}" = "full" ]
then
        _BAK_LEVEL=0
elif [ "${_ACTION}" = "inc" ]
then
        _BAK_LEVEL=1
        _LAST_BAK_DIR=`tail -n 1 ${_seed_file}`
        echo "Last full backup dir:{${_LAST_BAK_DIR}}" >> ${_log_file}
else
        echo "ERROR: `date +%F:%H.%M` There is no ARGS..." >> ${_log_file}
fi
 
 
function helpm(){
cat <use " sh $0 {full|inc}"
MES
}

function do_oracle(){

su - oracle <
###backup oracle full
function do_full(){
rman target / <CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF ${_DEL_DAY} DAYS;
configure channel device type disk format '${_ORACLE_BACK_DIR}/${_now_time}/data_%U' ;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '${_ORACLE_BACK_DIR}/${_now_time}/ctl_%F';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
backup  INCREMENTAL LEVEL ${_BAK_LEVEL}  database tag = 'daily_full' plus archivelog DELETE INPUT;
DELETE OBSOLETE RECOVERY WINDOW OF ${_DEL_DAY} DAYS;
RMANB
}
function do_inc(){
###backup oracle inc
rman target / <CONFIGURE BACKUP OPTIMIZATION ON;
configure channel device type disk format '${_ORACLE_BACK_DIR}/${_LAST_BAK_DIR}/data_%U' ;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '${_ORACLE_BACK_DIR}/${_LAST_BAK_DIR}/ctl_%F';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
backup  INCREMENTAL LEVEL ${_BAK_LEVEL} database tag = 'daily_inc' plus archivelog DELETE INPUT;
RMANI
}

if [ "${_ACTION}" = "full" ]
then
        echo "`date +%F:%H.%M` Starting full oracle backup,please wait..."
        echo "Now mkdir backup dir..."
        mkdir -p ${_ORACLE_BACK_DIR}/${_now_time} && echo ${_now_time} >> ${_seed_file} || exit 10
        echo "backup level:${_BAK_LEVEL}"
        do_full
elif [ "${_ACTION}" = "inc" ]
then
        echo "`date +%F:%H.%M` Starting Differential incremental oracle backup,please wait..."
        echo "Last full backup dir:{${_LAST_BAK_DIR}}"
        echo "backup level:${_BAK_LEVEL}"
        do_inc
else
        echo "ERROR: `date +%F:%H.%M` There is no ARGS..."
fi
#echo "`date` gzip the backup files..."
#cd ${_ORACLE_BACK_DIR}/${_now_time} && gzip data* ctl* || echo "gzip files error"
#compress files
echo "`date` delete the too old backups:\"${_OLD_DAY}\"..."
cd ${_ORACLE_BACK_DIR} && rmdir ${_OLD_DAY}*
ORAB
 
echo "`date` oracle backup complete."
echo "-------------------------------------------------------------------------------"
}
 

#do_mysql
do_oracle >>  ${_log_file} 2>&1
#do_oracle | tee -a  ${_log_file}
阅读(760) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~