【oracle】rman 恢复到异机

Posted on 2012-12-19 16:10  雅飞士  阅读(386)  评论(0编辑  收藏  举报

在虚拟机上搞的测试,把源库全备后,删除,利用备份文件恢复出来。模拟恢复到异机。

数据库版本:

SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

1.在源库中创建测试表并插入数据:

SQL> conn system/dang
Connected.
SQL> create table test(id number);
Table created.

SQL> insert into test values(1);
1 row created.
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
        ID
----------
         1
         2

2.备份数据文件:

RMAN> backup database format '/backup/test/db_test_full_%U' tag '2012-12-18-full';
Starting backup at 20121218151959
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oradata/test/test/system01.dbf
input datafile file number=00002 name=/oradata/test/test/sysaux01.dbf
input datafile file number=00003 name=/oradata/test/test/undotbs01.dbf
input datafile file number=00004 name=/oradata/test/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 20121218152000
channel ORA_DISK_1: finished piece 1 at 20121218152056
piece handle=/backup/test/db_test_full_01nt6850_1_1 tag=2012-12-18-FULL comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:56
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 20121218152059
channel ORA_DISK_1: finished piece 1 at 20121218152100
piece handle=/backup/test/db_test_full_02nt686o_1_1 tag=2012-12-18-FULL comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20121218152100

3.备份控制文件:

RMAN> backup current controlfile format '/backup/test/control_121218_test.bak';
Starting backup at 20121218152201
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 20121218152202
channel ORA_DISK_1: finished piece 1 at 20121218152203
piece handle=/backup/test/control_121218_test.bak tag=TAG20121218T152201 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20121218152203

4.备份spfile:
RMAN> backup spfile format '/backup/test/spfile_test.bak';
Starting backup at 20121218152229
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 20121218152229
channel ORA_DISK_1: finished piece 1 at 20121218152230
piece handle=/backup/test/spfile_test.bak tag=TAG20121218T152229 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20121218152230

5.用dbca删除test库。

删除完成后,把本机当做异机处理,创建一些必须的文件夹:

[oracle@yfs test]$ pwd

/s01/admin/test
[oracle@yfs test]$ ll
total 12
drwxr-xr-x. 2 oracle oinstall 4096 Dec 18 16:03 adump
drwxr-xr-x. 2 oracle oinstall 4096 Dec 18 15:53 dpdump
drwxr-xr-x. 2 oracle oinstall 4096 Dec 18 15:53 pfile

6.rman中起库:

[oracle@yfs ~]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Tue Dec 18 15:37:39 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)
RMAN> startup
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/s01/product/11.2.0/dbhome_1/dbs/inittest.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 12/18/2012 15:38:02
ORA-00205: error in identifying control file, check alert log for more info

7.上步报错,找不到初始化文件,利用刚才的备份先恢复spfile:
RMAN> restore spfile to '/s01/product/11.2.0/dbhome_1/dbs/spfiletest.ora' from '/backup/test/spfile_test.bak';
Starting restore at 20121218153924
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /backup/test/spfile_test.bak
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 20121218153926

8.恢复控制文件:

RMAN> restore controlfile from '/backup/test/control_121218_test.bak';
Starting restore at 20121218155637
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/oradata/test/test/control01.ctl
output file name=/s01/fast_recovery_area/test/control02.ctl
Finished restore at 20121218155642

9.加载数据库:

RMAN> sql 'alter database mount';
sql statement: alter database mount
released channel: ORA_DISK_1

10.修复数据库:

RMAN> restore database;
Starting restore at 20121218160052
Starting implicit crosscheck backup at 20121218160052
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 20121218160054
Starting implicit crosscheck copy at 20121218160054
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20121218160055
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oradata/test/test/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /oradata/test/test/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oradata/test/test/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oradata/test/test/users01.dbf
channel ORA_DISK_1: reading from backup piece /backup/test/db_test_full_01nt6850_1_1
channel ORA_DISK_1: piece handle=/backup/test/db_test_full_01nt6850_1_1 tag=2012-12-18-FULL
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
Finished restore at 20121218160225

11.恢复数据库:

RMAN> recover database;

12.resetlogs方式打开数据库:

SQL> alter database open resetlogs;
Database altered.

13.查看测试表数据:
SQL> conn system/dang
Connected.
SQL> select * from test;
        ID
----------
         1
         2

OK,恢复完成。



--EOF

原文地址:http://blog.yafeishi.net/2012/12/oracle-rman-restore-other-host.html

Copyright © 2024 雅飞士
Powered by .NET 8.0 on Kubernetes