博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RMAN异地恢复
阅读量:5872 次
发布时间:2019-06-19

本文共 5633 字,大约阅读时间需要 18 分钟。

Source db端:

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

ORACLE_SID=ygdg

数据文件位置:/u01/app/oracle/oradata/ygdg

Target db端:

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

ORACLE_SID=ygdg

数据文件位置:/u01/app/oracle/oradata/ygdg

【1.原库rman备份】

[oracle@oraclelinux rman]$ cat rman_for_dg.sh

export ORACLE_SID=ygdg

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

rman target=/ log='/u01/ygtest/fullbackup.log'<<EOF

crosscheck archivelog all;

run

{

allocate channel t1 type disk;

allocate channel t2 type disk;

allocate channel t3 type disk;

allocate channel t4 type disk;

backup as compressed backupset database format '/u01/ygtest/DB%d%s%p%t.bak' TAG='WHOLE BACKUP' section size 30G

plus archivelog format '/u01/ygtest/ARC%d%s%p%t.bak' TAG='ARC BACKUP' delete input;

backup current controlfile format '/u01/ygtest/CTL%d%s%p%t.bak' TAG='CTL BACKUP';

release channel t1;

release channel t2;

release channel t3;

release channel t4;

}

crosscheck backup;

delete noprompt obsolete recovery window of 3 days;

EOF

【2.原库查看DBID】

export ORACLE_SID=ygdg

rman target=/

连接上之后就可以看得到DBID,记下来

【3.原库生成pfile】

create pfile='/u01/pfileygdg.ora' from spfile;

【4.备份文件传至目标库】

scp /u01/ygtest/*.bak oracle@10.1.1.11:/u01/ygtest 记得确定目录权限和所属者

【5.原库目标库结合修改pfile,并将修改后的参数文件传到目标端】

建议将原库生成的pfile和目标库的spfile都下载到本地,根据“参数位置看pfile,其他看spfile”的原则进行修改

【6.目标数据库创建spfile,并使用spfile启动数据库到nomount状态】

如果上面参数修改没问题,正常应该是下面这样:

SQL> startup pfile='/software/pfileygdg.ora';

SQL> create spfile from pfile='/software/pfileygdg.ora';

SQL> shutdown immediate;

SQL> startup nomount;

但是有些参数没注意修改,就会出现ORA-,不用担心,看到什么错改什么就行,如下:

SQL> startup pfile='/software/pfileygdg.ora';

ORACLE 例程已经启动。

Total System Global Area 221331456 bytes

Fixed Size 2251856 bytes

Variable Size 163578800 bytes

Database Buffers 50331648 bytes

Redo Buffers 5169152 bytes

ORA-00201: control file version 11.2.0.4.0 incompatible with ORACLE version 11.2.0.0.0

ORA-00202: control file: '/u01/app/oracle/oradata/ygdg/control01.ctl'

分析:查看参数文件中compatible值为11.2.0.0.0,与控制文件中的值冲突;

解决:

SQL> create spfile from pfile='/software/pfileygdg.ora';

文件已创建。

SQL> shutdown immediate;

ORA-01507: ??????

ORACLE 例程已经关闭。

解决:修改spfile文件compatible参数后,使用spfile启动

SQL> startup nomount;

ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initygdg.ora'

解决此问题的方法就是到cd /u01/app/oracle/admin/ygdg/pfile/目录下,将init.ora.25201817331

复制到dbs目录下:

cp init.ora.25201817331 /u01/app/oracle/product/11.2.0/db_1/dbs/initygdg.ora

SQL> startup nomount;

ORACLE 例程已经启动。

Total System Global Area 830930944 bytes

Fixed Size 2257800 bytes

Variable Size 536874104 bytes

Database Buffers 285212672 bytes

Redo Buffers 6586368 bytes

SQL> exit

从 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开

【7.还原控制文件】

[oracle@localhost database]$ rman target=/

恢复管理器: Release 11.2.0.4.0 - Production on 星期一 3月 5 19:20:26 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

已连接到目标数据库: YGDG (未装载)

RMAN> set dbid=2428115541

RMAN> restore controlfile from '/software/ygtest/CTL_YGDG_55_1_969977274.bak';

RMAN> alter database mount;

【8.指定备份文件所在目录】

RMAN> catalog start with '/software/ygtest';

【9.还原与恢复数据库】

RMAN> run{

set newname for datafile 1 to "/u01/app/oracle/oradata/ygdg/system01.dbf";

set newname for datafile 2 to "/u01/app/oracle/oradata/ygdg/sysaux01.dbf";

set newname for datafile 3 to "/u01/app/oracle/oradata/ygdg/undotbs01.dbf";

set newname for datafile 4 to "/u01/app/oracle/oradata/ygdg/users01.dbf";

set newname for datafile 5 to "/u01/app/oracle/oradata/ygdg/test01.dbf";

set newname for tempfile 1 to "/u01/app/oracle/oradata/ygdg/temp01.dbf";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ygdg/redo01a.log'' to ''/u01/app/oracle/oradata/ygdg/redo01a.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ygdg/redo02a.log'' to ''/u01/app/oracle/oradata/ygdg/redo02a.log'' ";

}

RMAN> run{

restore database;

SWITCH DATAFILE ALL;

recover database;

} # update control file with new filenames

注:1.原库执行

SQL> select 'set newname for datafile ' || a.FILE# || ' to "' || a.NAME || '";'

from v$datafile a union all select 'set newname for tempfile ' || a.FILE# || ' to "' || a.NAME || '";' from v$tempfile a;

'SETNEWNAMEFORDATAFILE'||A.FILE#||'TO"'||A.NAME||'";'

set newname for datafile 1 to "/u01/app/oracle/oradata/ygdg/system01.dbf";

set newname for datafile 2 to "/u01/app/oracle/oradata/ygdg/sysaux01.dbf";

set newname for datafile 3 to "/u01/app/oracle/oradata/ygdg/undotbs01.dbf";

set newname for datafile 4 to "/u01/app/oracle/oradata/ygdg/users01.dbf";

set newname for datafile 5 to "/u01/app/oracle/oradata/ygdg/test01.dbf";

set newname for tempfile 1 to "/u01/app/oracle/oradata/ygdg/temp01.dbf";

已选择6行。

SQL>

SELECT 'SQL "ALTER DATABASE RENAME FILE ''''' || a.MEMBER || ''''' to ''''' || a.MEMBER || ''''' ";' FROM v$logfile a;

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ygdg/redo01a.log'' to

''/u01/app/oracle/oradata/ygdg/redo01a.log'' ";

SQL "ALTER DATABASE RENAME FILE ''/u01/app/oracle/oradata/ygdg/redo02a.log'' to

''/u01/app/oracle/oradata/ygdg/redo02a.log'' ";

2.使用newnam for datafile来实现修改不同的文件路径

3.switch datafile all用来更新还原回来的controlfile中的数据文件路径与联机日志文件路径,要不然recover时会报错RMAN-06094

[oracle@localhost database]$ sqlplus / as sysdba

SQL> select status from v$instance;

STATUS

MOUNTED

SQL> alter database open resetlogs;

数据库已更改。

转自:

转载于:https://blog.51cto.com/lyzbg/2091404

你可能感兴趣的文章
Acquisition of Localization Confidence for Accurate Object Detection
查看>>
偶数求1/2+1/4+...+1/n奇数1/1+1/3+...+1/n
查看>>
网络爬虫+HtmlAgilityPack+windows服务从博客园爬取20万博文
查看>>
C# CRC16 查表法
查看>>
【LeetCode题解】数组Array
查看>>
因式分解和恒等式
查看>>
ui方案设计
查看>>
AngularJs Test demo &front end MVVM implementation conjecture and argue.
查看>>
深入学习golang(2)—channel
查看>>
sping整合hibernate之二:dao层开发
查看>>
php 不用通过表单也能创建HTTPpost请求
查看>>
Java性能分析之线程栈详解(下)
查看>>
Python标准库——getpass
查看>>
oracle11实战详解
查看>>
面向对象
查看>>
Mouse w/o Borders实现两台主机共用一套键鼠方法及问题处理
查看>>
@RequestMapping的value属性
查看>>
SSL Pining Mode 设置iOS SSL 连接安全
查看>>
valgrind 的使用简介
查看>>
Linux 下批量创建用户(shell 命令)
查看>>