代码改变世界

Oracle RMAN 备份一例

2014-07-18 23:03  AlfredZhao  阅读(1242)  评论(1编辑  收藏  举报
Oracle RMAN备份一例:
Solaris 10 + Oracle 11.2.0.3
Shell:csh,安装有bash,脚本调用bash
备份策略:周日0级备份,周一~周六1级备份,每6小时备份归档日志,每天清理历史文件夹.
--0级备份脚本:
#!/bin/bash
#db0 level backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi

export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.

rman target /  log=/oradata1/backup/$foldername/full_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata1/backup/$foldername/controlfile%F';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup incremental level 0 tag 'db0' database format '/oradata1/backup/$foldername/db0_%d_%T_%s' include current controlfile;
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
RMAN_BACKUP
--1级备份脚本:
#!/bin/bash
#db1 level backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi

export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.

rman target /  log=/oradata1/backup/$foldername/incr_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata1/backup/$foldername/controlfile%F';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup incremental level 1 tag 'db1' database format '/oradata1/backup/$foldername/db1_%d_%T_%s' include current controlfile;
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
RMAN_BACKUP
--归档备份
#!/bin/bash
#arch backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi

export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.

rman target /  log=/oradata1/backup/$foldername/arch_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql 'alter system archive log current';
backup archivelog all delete input format '/oradata1/backup/$foldername/arch_%d_%T_%s';
release channel c1;
release channel c2;
}
crosscheck archivelog all;
delete expired archivelog all;
RMAN_BACKUP
--系统级别删除过期备份的空文件夹
#!/bin/bash
#del old folders
cd /oradata1/backup
find . -mtime +10 | xargs rm -rf
--crontab调度
crontab -l
0 1 * * 0 /oradata1/backupsh/db0_backup.rman > /dev/null 2&>1#
0 1 * * 1-6 /oradata1/backupsh/db1_backup.rman > /dev/null 2&>1#
0 6,12,18 * * * /oradata1/backupsh/arch_backup.rman > /dev/null 2&>1#
0 3 * * * /oradata1/backupsh/del_old.sh > /dev/null 2&>1#