Oracle数据库使用rman物理备份

一、 准备备份脚本

1、备份脚本文件rmanfull.bak,存放目录/home/oracle/scripts
connect target / ;

run{
   crosscheck archivelog all;
   delete expired archivelog all;
   backup as compressed backupset database format '/home/oracle/dbbackup/wldb_db_%T_%s' filesperset 5;
   sql 'alter system archive log current';

   backup as compressed backupset archivelog all format '/home/oracle/dbbackup/wldb_arch_%T_%s' delete input;

   backup current controlfile format '/home/oracle/dbbackup/dbbackup_cntl_%T_%s';
   delete noprompt obsolete;
   delete noprompt expired backup;
}

exit;

备注:备份文件存放目录/home/oracle/dbbackup
wldb_db_%T_%s、wldb_arch_%T_%s 请根据自身情况重命名
%T表示日期
%s表示总秒数

2、执行备份的脚本文件Fullbackrman.sh,存放目录/home/oracle/scripts

#!/bin/bash

export ORACLE_SID=wldb
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin

rman cmdfile=/home/oracle/scripts/rmanfull.bak log=/home/oracle/scripts/log/rman_`date +%Y%m%d`.log

if [ $? -eq 0 ] then
    echo "rman run successfull"
else
    echo "rman run failed"
fi

备注:ORACLE_SID、ORACLE_BASE、ORACLE_HOME,请根据实际情况修改
日志文件存放在/home/oracle/scripts/log/目录

二、修改备份策略

1、在oracle用户下修改备份策略,保留3次的备份集合

[root@oracle-backup scripts]# su – oracle

[oracle@oracle-backup ~]$ rman target /

RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 3;

2、查看rman备份策略,在rman下执行show all;命令。

[root@oracle-backup scripts]# su – oracle

[oracle@oracle-backup ~]$ rman target /

RMAN> show all;

结果如图所示:


ip_image006.jpeg

3、制定定时任务,每天凌晨1点10分备份

vi /etc/crontab
10 1 * * * /home/oracle/scripts/Fullbackrman.sh >/tmp/Fullbackrman.log 2>&1 &

三、 附
归档日志删除脚本
解释:归档日志会不断的增加,所以需要进行定期清理

1、删除归档日志命令文件ArchBack.rman

connect target / ;
run{
  #allocate channel t1 type disk;
  #allocate channel t2 type disk;
  crosscheck archivelog all;
  delete noprompt archivelog all completed before 'sysdate -1/48';
  #release channel t1;
  #release channel t2;
}
exit;

备注:crosscheck archivelog all;的作用就是检查控制文件和实际物理文件的差别。
delete noprompt archivelog all completed before 'sysdate -1/48'; 删除半小时前的归档日志。
sysdate -1/48 减半小时

2、清除归档日志脚本文件delarchivelog.sh

#!/bin/sh
#--------------------------------------------------
# We backup the database with RMAN and using nocatalog 
# So we must Record the DBID must first
#
# set DBID=2176833531
# The backup RETENTION POLICY TO REDUNDANCY 7
# The CONTROLFILE AUTOBACKUP OFF
#--------------------------------------------------
PATH=$PATH:/home/oracle/scripts ; export PATH
BK_STATUS=/home/oracle/scripts/log/BK_STATUS ; export BK_STATUS
MSG_LOG=/home/oracle/scripts/log/joblog_`date +%Y%m`.log ;export MSG_LOG
JOBNAME=Rman_Backup; export JOBNAME

RMAN_LOG=/home/oracle/scripts/log/rmanlog_`date +%Y%m%d`.log

ORACLE_SID=wldb; export ORACLE_SID
ORACLE_BASE=/oracle; export ORACLE_BASE
ORACLE_HOME=/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME

PATH=$PATH:$ORACLE_HOME/bin; export PATH
Date_Num=`date +%u`

MSG_JOB S

rman cmdfile=/home/oracle/scripts/ArchBack.rman append log=/home/oracle/scripts/log/rmanlog_`date +%Y%m%d`.log
if [ $? -eq 0 ]
then
  MSG_JOB I 'Rman delete archivelog Finish'
  export SUBJECT="Rman Run Result"
else
  MSG_JOB I 'Rman delete archivelog Error'
  export SUBJECT="Rman Run failure"
  MYMAIL "ALL" "$RMAN_LOG"
fi

MSG_JOB N
# Crosscheck Backup -----------------------------------------------#

#rman cmdfile=/home/oracle/scripts/Crosscheck.rman append log=/home/oracle/scripts/log/rmanlog_`date +%Y%m%d`.log

# Send Mail to DBA ------------------------------------------------#
#export SUBJECT "RMAN Run Result"
#MYMAIL "ALL" "$RMAN_LOG"

备注:ORACLE_SID、ORACLE_BASE、ORACLE_HOME,请根据实际情况修改

|

你可能感兴趣的:(Oracle数据库使用rman物理备份)