RMAN备份策略与异机恢复一例

实验环境:

A机器(生产用途):RHEL 6.5 + Oracle 11.2.0.4 + IP Address 192.168.1.11

B机器(备机用途):RHEL 6.5 + Oracle 11.2.0.4 + IP Address 192.168.1.61

需求:

A机器RMAN备份完成后自动传输备份文件到B机器。防止A机器本身硬件Crash无法恢复造成核心数据库无法恢复的窘境。而且在B机器可以将数据异机恢复到任意时间点。

注意:因为要求备份完毕后直接脚本命令自动传输到异机备份目录,所以需要预先配置好到B机器的SSH无密码登录。

1.定时任务:

  • 每周日1点数据库全备
  • 每天8点备份归档
[[email protected] scripts]$ crontab -l
0 1 * * 0 /u01/orabak/scripts/backup.sh /u01/orabak
0 8 * * * /u01/orabak/scripts/backuparch.sh /u01/orabak

2.脚本内容:

  • 全备脚本:vi backup.sh
#!/bin/bash
#ENV
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

#backup RMAN
if [ ! -d "$1" ]; then
        echo "You have input no dir for \$1"
        exit 1
fi

echo "=================================================================================" >>${1}/backup_full.log
echo "Begin backup at : `date`" >> ${1}/backup_full.log
rman target / <<EOF >> ${1}/backup_full.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup as compressed backupset database format ‘${1}/FULLBAK_%d_%T_%s_%p.DBFILE‘;
backup current controlfile format ‘${1}/%d.%s.%p.%T.CTL‘;
backup spfile format ‘${1}/%d.%s.%p.%T.SPFILE‘;
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format ‘${1}/%d.%s.%p.%T.ARC‘;
crosscheck archivelog all;
delete noprompt archivelog all completed before ‘sysdate-10‘;
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_full.log

echo "Begin scp at : `date`" >>${1}/backup_full.log
scp ${1}/*`date +%Y%m%d`* [email protected]:/tmp/
echo "End scp at : `date`" >>${1}/backup_full.log
echo "=================================================================================" >>${1}/backup_full.log

exit 0
  • 归档备份脚本:vi backuparch.sh

    这里只是去掉全备的命令,其他保留。

#!/bin/bash
#ENV
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

#backup RMAN
if [ ! -d "$1" ]; then
        echo "You have input no dir for \$1"
        exit 1
fi

echo "=================================================================================" >>${1}/backup_arch.log
echo "Begin backup at : `date`" >> ${1}/backup_arch.log
rman target / <<EOF >> ${1}/backup_arch.log
run {
CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
backup current controlfile format ‘${1}/%d.%s.%p.%T.CTL‘;
backup spfile format ‘${1}/%d.%s.%p.%T.SPFILE‘;
crosscheck backup;
crosscheck copy;
sql "alter system archive log current";
backup as COMPRESSED backupset archivelog all not backed up format ‘${1}/%d.%s.%p.%T.ARC‘;
crosscheck archivelog all;
delete noprompt archivelog all completed before ‘sysdate-10‘;
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF
echo "End backup at : `date`" >>${1}/backup_arch.log

echo "Begin scp at : `date`" >>${1}/backup_arch.log
scp ${1}/*`date +%Y%m%d`*.{CTL,SPFILE,ARC} [email protected]:/tmp/
echo "End scp at : `date`" >>${1}/backup_arch.log
echo "=================================================================================" >>${1}/backup_arch.log

exit 0

注意:这里的通配只是满足去掉全备的备份传输,对于归档日志,控制文件和参数文件的备份并没有做进一步区分(如果你的归档文件很大,还需要进一步设计细分)

3.异机恢复:

异机恢复核心步骤:

3.1 参数文件:

$ strings ORCL.24.1.20180619.SPFILE

[[email protected] orcl]$ pwd
/u01/oradata/orcl
[[email protected] orcl]$ vi pfile.ora
*.audit_file_dest=‘/u01/app/oracle/admin/orcl/adump‘
*.audit_trail=‘db‘
*.compatible=‘11.2.0.4.0‘
*.control_files=‘/u01/oradata/orcl/control01.ctl‘,‘/u01/oradata/orcl/control02.ctl‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_name=‘orcl‘
*.diagnostic_dest=‘/u01/app/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=orclXDB)‘
*.log_archive_dest_1=‘LOCATION=/u01/arch‘
*.memory_target=1234173952
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.undo_tablespace=‘UNDOTBS1‘

SQL> startup nomount pfile=‘/u01/oradata/orcl/pfile.ora‘;
ORACLE instance started.

3.2 控制文件:

RMAN> restore controlfile from ‘/tmp/ORCL.23.1.20180619.CTL‘;
RMAN> alter database mount;
RMAN> catalog start with ‘/tmp/‘;
RMAN> crosscheck backup;

3.3 转储文件并恢复到指定时间点:

RMAN> restore database;
RMAN> sql "alter session set nls_date_format=‘‘yyyy-mm-dd hh24:mi:ss‘‘";
RMAN> recover database until time ‘2018-06-19 17:50:00‘;

--先只读打开确认数据是否符合要求
SQL> alter database open read only; 

--确认没问题后重新以resetlogs方式打开
SQL> create spfile from pfile=‘/u01/oradata/orcl/pfile.ora‘;
SQL> startup mount
SQL> alter database open resetlogs; 

至此,RMAN备份策略与异机恢复实例演示完成。

原文地址:https://www.cnblogs.com/jyzhao/p/9200714.html

时间: 2024-11-02 02:18:00

RMAN备份策略与异机恢复一例的相关文章

linux下只有rman备份集的异机不同目录恢复

昨天在客户那里做了一次rman异机的恢复,把生产库弄一份给测试库用,总库大概80G,总共花费了2个小时,当时客户的环境是windows 11.2.0.3,今天早晨在linux下重新测试了一下,记录下来供大家参考 环境: 所有操作都是按主机名区分 源库: 主机名  bre1  实例名为bre1  数据文件目录在/u01/app/oradata下 目标库: 主机名 bre2   数据文件准备放在/bre1/oradata下 废话不多说,下面是实际操作步骤 1.在源库创建备份集,并且拷贝到目标库 拷贝

linux下仅仅有rman备份集的异机不同文件夹恢复

昨天在客户那里做了一次rman异机的恢复,把生产库弄一份给測试库用,总库大概80G,总共花费了2个小时,当时客户的环境是windows 11.2.0.3,今天早晨在linux下又一次測试了一下,记录下来供大家參考 环境: 全部操作都是按主机名区分 源库: 主机名  bre1  实例名为bre1  数据文件文件夹在/u01/app/oradata下 目标库: 主机名 bre2   数据文件准备放在/bre1/oradata下 废话不多说,以下是实际操作步骤 1.在源库创建备份集,而且复制到目标库

rman备份与异机恢复

一.rman备份脚本并为定时任务 #!/bin/bashsource ~/.bash_profileexport LANG=en_USBACKUP_DATE=`date +%d`#RMAN_LOG_FILE=${0}.outRMAN_LOG_FILE=backupinfo.outTODAY=`date`USER=`id|cut -d "(" -f2|cut -d")" -f1`echo "---------------$TODAY-------------

RMAN - 备份异机恢复

OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production ① RMAN异机恢复的时候,db_name必须相同.如果想要改别的实例命,可以在RMAN恢复成功后,用 nid 命令修改. ② 恢复路径与源库不相同,在restore时用set指定新位置,并用switch logfile all 将信息更新到controlfile文

rman 备份并异机恢复

1.RMAN 备份脚本 RUN { CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/backup/ZGW_Controlfile_%F"; ALLOCATE CHANNEL CH1 DEVICE TYPE DISK;

Oracle12c RAC RMAN异机恢复

######################################################## #编辑pfile文件initspdb.ora vi /oracle/app/oracle/product/12.2.0/db_1/dbs/initspdb.ora audit_file_dest='/oracle/app/oracle/admin/spdb/adump' audit_trail='db' compatible='12.2.0' control_files='/orac

rman异机恢复

rman异机恢复 注意事项: 1.源数据库与目标数据库的目录结构相同 2.目标数据库只需要安装ORACLE软件(但是参数文件中指定的目录要创建) 3.要将源数据库的数据文件,参数文件,控制文件,密码文件,归档日志统统备份 1.源数据库备份 参数文件与控制文件自动备份 CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/r

如何使用 RMAN 异机恢复部分表空间

在oracle 数据库的日常维护和使用期间难免会遇到误删数据(drop,delete, truncate)当我们使用常规手段(flashback query ,flashback drop)也无法恢复数据时,我们可以使用最近的逻辑备份,在异机使用dmp 来恢复相应的表,但是如果没有这些逻辑备份,但是有一个最近的rman 全备,那么我们就可以利用这个备份来恢复被误删的表空间,从而实现数据的恢复,这里我以NBU 的备份环境为例简单描述下如何来回复部分 表空间: -------在nomount 状态

Oracle 单实例 迁移到 RAC 实例 -- 使用RMAN 异机恢复

Oracle 官网有关单实例迁移到RAC的一个步骤说明: How to Convert 10g Single-Instance database to 10g RAC using Manual Conversion procedure [ID 747457.1] http://blog.csdn.net/tianlesoftware/archive/2010/12/09/6065903.aspx   RMAN 备份异机恢复 并创建新DBID http://blog.csdn.net/tianle