ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle-RMAN异机恢复

oracle-RMAN异机恢复

原创 Linux操作系统 作者:anna0030 时间:2011-03-22 11:40:35 0 删除 编辑

Step1: 设置环境变量

[oracle@ehrprod ~]$ export ORACLE_SID=szuat01

 

Step 2: 恢复参数文件

[oracle@ehrprod ~]$ rman target /

 

Recovery Manager: Release 10.2.0.4.0 - Production on Thu Mar 10 15:01:36 2011

 

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

 

connected to target database (not started)

 

RMAN> set dbid 2805194251;

 

executing command: SET DBID

  

RMAN> restore spfile to pfile '/u01/oracle/product/10.2.0.1/dbs/initszuat01.ora' from '/backup/szuat01/rman/backupset/SZUAT01_df0_20110303_95_1_744768707';

 

Starting restore at 10-MAR-11

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=36 devtype=DISK

 

channel ORA_DISK_1: autobackup found: /backup/szuat01/rman/backupset/SZUAT01_df0_20110303_95_1_744768707

channel ORA_DISK_1: SPFILE restore from autobackup complete

Finished restore at 10-MAR-11

 

Step3: 根据initSID.ora文件创建目录,同时也可以根据需要修改initSID.ora里面的参数

 

Step 4: 用参数文件启动DBnomount

 

RMAN> startup force nomount pfile='/u01/oracle/product/10.2.0.1/dbs/initszuat01.ora';

 

Oracle instance started

 

Total System Global Area    2147483648 bytes

 

Fixed Size                     1268508 bytes

Variable Size                570426596 bytes

Database Buffers            1560281088 bytes

Redo Buffers                  15507456 bytes

 

Step 5: 恢复控制文件:

 

RMAN> restore controlfile from '/backup/szuat01/rman/backupset/SZUAT01_df0_20110303_95_1_744768707';

 

Starting restore at 10-MAR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=156 devtype=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

output filename=/u01/oracle/szuat01/control01.ctl

output filename=/u01/oracle/szuat01/control02.ctl

output filename=/u02/oracle/szuat01/control03.ctl

Finished restore at 10-MAR-11

 

Step 6: 恢复Datafile文件。

RMAN> alter database mount;

 

database mounted

released channel: ORA_DISK_1

 

RMAN> run{

2> set newname for datafile 1 to '/u01/oracle/oradata/testdb/system01.dbf';

3> set newname for datafile 2 to '/u01/oracle/oradata/testdb/undotbs01.dbf';

4> set newname for datafile 3 to '/u01/oracle/oradata/testdb/sysaux01.dbf';

5> set newname for datafile 4 to '/u01/oracle/oradata/testdb/users01.dbf';

6> set newname for datafile 5 to '/u01/oracle/oradata/testdb/####.dbf';

7> set newname for datafile 6 to '/u01/oracle/oradata/testdb/###.dbf';

8> restore database; 

9> }

 

(说明:Datafile可以通过查询SQL> select file#, name, status from v$datafile;获得,restore database 必须和set newname在一个run里,否则会去取原DB的路径去restore. 如果不需要改文件路径,则直接restore即可,下一部也可以不要。restore 前可能需要执行一下RMAN> catalog start with '/backup/szuat01/rman/backupset';

 

 

Step 7: 根据需要修改DBDatafileLogfile, tempfile文件路径。 (此步在其他很多文档里没有提到。实践时发现如果文件改了路径,即使有前面的set newname,recover的时候也还是会去找原来的路径,所以需要手动去改下。)

 

SQL> select file#, name from v$datafile;

 

。。。 

SQL> alter database rename file '/oracle/oradata/testdb/system01.dbf' to '/u01/oracle/oradata/testdb/ system01.dbf';

 

Database altered.

。。。 

 

 

SQL> select group#,member from v$logfile;

 .... 

 

SQL> alter database rename file '/oracle/oradata/testdb/redo01.log' to '/u01/oracle/oradata/testdb/redo01.log';

 

Database altered.

...

 

 

 

SQL> select * from dba_temp_files;

select * from dba_temp_files

              *

ERROR at line 1:

ORA-01157: cannot identify/lock data file 201 - see DBWR trace file

ORA-01110: data file 201: '/oracle/oradata/macaubb/temp01.dbf'

 

 

SQL> alter database tempfile '/oracle/oradata/testdb/temp01.dbf' drop;

 

Database altered.

 

SQL> select * from dba_temp_files;

 

no rows selected

 

SQL> alter tablespace temp add tempfile '/u01/oracle/oradata/testdb/temp01.dbf' size 50m reuse;

 

Tablespace altered.

 ... 

 

Step 8: 恢复数据库。

RMAN> recover database;

….

RMAN> alter database open resetlogs;

 

using target database control file instead of recovery catalog

database opened

 

 

Step 9: 检查运行是否正常,可以登陆测试,重启测试,查看一下alert文件。

 

恢复后的DB想要在dbca里看得到,需要修改文件/etc/oratab,这样才可以用dbca去删除。

 

 

另外: 

迁移后如果报错,

 ORA-39700: database must be opened with UPGRADE option

可能是因为数据库版本不一致。原DB的版本较低,导致软件升级了,DB没有升级。解决办法是用startup upgrade后执行

SQL>@/data/oracle/OracleHome/rdbms/admin/catupgrd.sql

后重启就好了。

(可能某些情况下还需执行

SQL>@/data/oracle/OracleHome/rdbms/admin/catalog.sql
SQL>@/data/oracle/OracleHome/rdbms/admin/catproc.sql

 

如果恢复时不想恢复某个tablespace, 可以用命令:

RMAN> restore database skip [forever] tablespace rmand;  

 

RMAN> recover database skip [forever] tablespace rmand;  

 

如果想要恢复archivelog,可以用命令

RMAN> restore archivelog from logseq 2088 [until logseq 2092];

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9480809/viewspace-690143/,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-07-23

  • 博文量
    4
  • 访问量
    16136