Oracle数据库物理备份不了,Oracle数据库使用rman物理备份

本文详细介绍了如何配置Oracle数据库的RMAN备份脚本,包括全库备份、归档日志备份,并制定了保留策略。此外,还提供了一个删除归档日志的脚本,以保持数据库存储的整洁。最后,设置了一个定时任务,每天凌晨1点10分执行备份操作。
摘要由CSDN通过智能技术生成

一、 准备备份脚本

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;

结果如图所示:

7904572ad0cf

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,请根据实际情况修改

|

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值