首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

异地rman恢复数据库

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'

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 Size2251856 bytes

Redo Buffers5169152 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 Size2257800 bytes

Redo Buffers6586368 bytes

从 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> 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行。

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;

数据库已更改。

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180305G1P6FB00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券