Oracle RMAN备份一例:
Solaris 10 + Oracle 11.2.0.3
Shell:csh
备份策略:周日0级备份,周一~周六1级备份,每6小时备份归档日志,每天清理历史文件夹.
--0级备份脚本:
--1级备份脚本:
--归档备份
--系统级别删除过期备份的空文件夹
--crontab调度
crontab -l
#!/bin/csh #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 set ORACLE_SID SHIRNOP set ORACLE_BASE /opt/app/oracle/ set ORACLE_HOME /opt/app/oracle/product/11.2.0/dbhome_1/ set NLS_LANG "simplified chinese_china.ZHS16GBK" set NLS_DATE_FORMAT "YYYY-MM-DD HH24:Mi:SS" set PATH /bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/bin/csh:/etc:/opt/app/oracle/product/11.2.0/dbhome_1//bin:. rman target / log=/oradata1/backup/$foldername/full_LOG_%U.log << RMAN_BACKUP run{ CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 8 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; 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; } RMAN_BACKUP
#!/bin/csh #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 set ORACLE_SID SHIRNOP set ORACLE_BASE /opt/app/oracle/ set ORACLE_HOME /opt/app/oracle/product/11.2.0/dbhome_1/ set NLS_LANG "simplified chinese_china.ZHS16GBK" set NLS_DATE_FORMAT "YYYY-MM-DD HH24:Mi:SS" set PATH /bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/bin/csh:/etc:/opt/app/oracle/product/11.2.0/dbhome_1//bin:. rman target / log=/oradata1/backup/$foldername/incr_LOG_%U.log << RMAN_BACKUP run{ CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 8 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; 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; } RMAN_BACKUP
#!/bin/csh #arch backup foldername=`date +%Y%m%d` cd /oradata1/backup if [ -d $foldername ] then echo ‘go on‘ else echo ‘need mkdir‘ mkdir $foldername fi set ORACLE_BASE /opt/app/oracle/ set ORACLE_HOME /opt/app/oracle/product/11.2.0/dbhome_1/ set ORACLE_SID SHIRNOP set NLS_LANG "simplified chinese_china.ZHS16GBK" set NLS_DATE_FORMAT "YYYY-MM-DD HH24:Mi:SS" set PATH /bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/bin/csh:/etc:/opt/app/oracle/product/11.2.0/dbhome_1//bin:. rman target / log=/oradata1/backup/$foldername/arch_LOG_%U.log << RMAN_BACKUP run{ CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 8 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 -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#