Oracle rman定时备份策略

Posted Demonson

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle rman定时备份策略相关的知识,希望对你有一定的参考价值。

一、备份脚本

<1>.0级备份

vim level0_backup.sh

#!/bin/bash

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

dateTime=`date +%Y-%m-%d`

rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level0_$dateTime.log


vim level0_backup.rcv

connect target sys/***@orcl
run
crosscheck backup;

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt expired backup;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0  as compressed backupset database format '/dbbak/backup/LEVEL0/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql'alter system archive log current';
backup as compressed backupset archivelog all format '/dbbak/backup/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
backup spfile tag='spfile' format='/dbbak/backup/LEVEL0/spfile_%U_%T';
delete force noprompt archivelog all completed before 'sysdate-7'; 
release channel d2;
release channel d1;

<2>.1级备份

vim level1_backup.sh

#!/bin/bash

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

dateTime=`date +%Y-%m-%d`

rman cmdfile=/u01/app/ora_backup/backup_scripts/level1_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level1_$dateTime.log

vim level1_backup.rcv

connect target sys/***@orcl
run
crosscheck backup;

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt expired backup;
allocate channel d1 type disk;
backup incremental level 1  as compressed backupset database format '/ora_backup/backup_sets/LEVEL1/level1_%d_%s_%p_%u.bak'
tag='level 1';
sql'alter system archive log current';
backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL1/log_%d_%s_%p_%u.bak' delete all input;
delete force noprompt archivelog all completed before 'sysdate-7';
release channel d1;

<3>.2级备份

vim level2_backup.sh

#!/bin/bash

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

dateTime=`date +%Y-%m-%d`

rman cmdfile=/u01/app/ora_backup/backup_scripts/level2_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level2_$dateTime.log

vim level2_backup.rcv

connect target sys/***@orcl
run
crosscheck backup;

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt expired backup;
allocate channel d1 type disk;
backup incremental level 2  as compressed backupset database format '/ora_backup/backup_sets/LEVEL2/level2_%d_%s_%p_%u.bak'
tag='level 2';
sql'alter system archive log current';
backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL2/log_%d_%s_%p_%u.bak' delete all input;
delete force noprompt archivelog all completed before 'sysdate-7';
release channel d1;

二、每月1号备份脚本

<1>.每月一号定时备份


vim level0_backup_arch.sh

#!/bin/bash

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

dateTime=`date +%Y-%m-%d`

rm -f /ora_archive_bk/arch/LEVEL0/*

rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup_arch.rcv msglog=/u01/app/ora_backup/backup_logs/level0_arch_$dateTime.log

vim level0_backup_arch.rcv

connect target sys/***@orcl
run
crosscheck backup;

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt expired backup;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0  as compressed backupset database format '/dbbak/LEVEL0/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql'alter system archive log current';
backup as compressed backupset archivelog all format '/dbbak/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
backup spfile tag='spfile' format='/dbbak/LEVEL0/spfile_%U_%T';
delete force noprompt archivelog all completed before 'sysdate-7'; 
release channel d2;
release channel d1;

<2>.备份归档文件

vim level0_bk_arch.sh

#!/bin/bash

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

dateTime=`date +%Y%m%d`
cd /dbbak/arch_rar_file

#加密打包拷贝
/usr/local/bin/rar -p"****" a -agYYYYMMDD -ep -ta`date +%F` -r /dbbak/arch_rar_file/BkArc_ /dbbak/LEVEL0/*.* /u01/app/ora_backup/control_backup/*$dateTime*

三、定时脚本

<1>.使用crontab定时执行

crontab -l

0 5 1 * * sh /u01/app/ora_backup/backup_scripts/level0_bk_arch.sh
10 1 * * 0 sh /u01/app/ora_backup/backup_scripts/level0_backup.sh
10 1 1 * * sh /u01/app/ora_backup/backup_scripts/level0_backup_arch.sh
10 1 * * 3,6 sh /u01/app/ora_backup/backup_scripts/level1_backup.sh
10 1 * * 1,2,4,5 sh /u01/app/ora_backup/backup_scripts/level2_backup.sh
#DG备库定时清理应用过的日志
10 1 * * * sh /home/oracle/clear_archlog.sh  

四、定时清理DG归档脚本

vim clear_archlog.sh

#!/bin/sh

BACK_DIR=/home/oracle/clear_archlog

export DATE=`date +%F`

mkdir  $BACK_DIR/$DATE

echo "      " >> $BACK_DIR/$DATE/rman_backup.log

echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log

su - oracle -c "

rman log=$BACK_DIR/$DATE/rman_backup.log target / <<EOF

# delete force archivelog all completed before 'sysdate - 1';  # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数

delete force noprompt archivelog all completed before 'sysdate - 2';

exit;

EOF

"

echo "   " >> $BACK_DIR/$DATE/rman_backup.log

以上是关于Oracle rman定时备份策略的主要内容,如果未能解决你的问题,请参考以下文章

[原创]Oracle 12c的备份和恢复策略

Oracle RMAN备份和异机恢复

【MySQL】Xtrabackup备份及恢复脚本

三种Oracle RMAN备份加密策略

100天精通Oracle-实战系列(第12天)Oracle 本地部署 RMAN 脚本定时备份数据库

Oracle RMAN备份策略