鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 服务器相关 > 批处理 > >

Unix等平台下采用rman方式备份Oracle数据库并将备份上传至FTP,

来源:互联网 作者:佚名 时间:2015-11-04 09:37
无详细内容 无 #!/bin/ksh# Author: Edward.Zhou -- edgeman_03@163.com# Purpose: Unix平台下使用rman自动备份oracle并上传备份到ftp,并根据日期自动保留所需备份# Created: 2015/8/16source ~/.profileexport ORACLE_SID=odb1export NLS_LANG=AMERICAN_AMER
<无详细内容> <无>
#!/bin/ksh
# Author:  Edward.Zhou -- <edgeman_03@163.com>
# Purpose: Unix平台下使用rman自动备份oracle并上传备份到ftp,并根据日期自动保留所需备份
# Created: 2015/8/16

source ~/.profile
export ORACLE_SID=odb1
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
HOSTNAME=`hostname -s`
NOWDATE=`date +%Y_%m_%d`
NOWDATE1=`date +%Y%m%d`
NOWTIME=`date +%Y%m%d%H%M%S`
OLDDATE=`date +%Y%m%d -d '-1 days'`
FTPOLDDATE=`date +%Y_%m_%d -d '-2 days'`

#建议备份基本目录环境
BACKUPDIR=/tmp/rman
[ -d ${BACKUPDIR} ] || mkdir -p ${BACKUPDIR}

#rman备份
cat >> ${BACKUPDIR}/rman.txt <<EOF
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
crosscheck backup;
sql 'alter system archive log current';
backup as compressed backupset full tag '$HOSTNAME-$ORACLE_SID-$NOWDATE' database format '$BACKUPDIR/db_%d_%T_%s';
sql 'alter system archive log current';
backup as compressed backupset archivelog all tag '$HOSTNAME-$ORACLE_SID-$NOWDATE' format '$BACKUPDIR/arch_%d_%T_%s' delete all input;
backup as compressed backupset current controlfile tag '$HOSTNAME-$ORACLE_SID-$NOWDATE' format '$BACKUPDIR/con_%d_%T_%s';
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
release channel d3;
release channel d2;
release channel d1;
}
EOF

rman target / cmdfile="${BACKUPDIR}/rman.txt" log="$BACKUPDIR/$HOSTNAME-$ORACLE_SID-rmanfullbak-$NOWTIME.log"
rm -f ${BACKUPDIR}/rman.txt
find ${BACKUPDIR} -name *${OLDDATE}* | xargs /bin/rm -f


#上传备份至FTP
HOST=1.1.1.1
FTP_USERNAME=backup
FTP_PASSWORD=backup

cd ${BACKUPDIR}

ftp -i -n -v <<EOF
open ${HOST}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bin
mkdir rman
cd rman
mkdir ${HOSTNAME}
cd ${HOSTNAME}
mkdir ${NOWDATE}
cd ${NOWDATE}
mput *
cd ..
cd ${FTPOLDDATE}
mdelete .
cd ..
rmdir ${FTPOLDDATE}
bye
EOF


网友评论
<