linux下oracle rman 複製資料庫技術(until cancel不完全恢復)

sun642514265發表於2013-05-29
環境介紹:
rhel5.4 32位 192.168.0.201,ORACLE_SID=orcl
rhel5.4 32位 192.168.0.202,ORACLE_SID=orcl

oracle版本: 11.2.0.1 32位企業版

主庫(192.168.0.201)

1、首先在主庫上建立測試資料

/*第1步:建立臨時表空間  */
create temporary tablespace orcl_temp tempfile '/u01/app/oracle/oradata/orcl/orcl_temp.dbf' size 50m autoextend on next 50m maxsize 2048m extent management local;

/*第2步:建立資料表空間  */
create tablespace orcl_data logging datafile '/u01/app/oracle/oradata/orcl/orcl_data.dbf' size 50m autoextend on next 50m maxsize 2048m extent management local;

/*第3步:建立使用者並指定表空間  */
create user orcl identified by orcl default tablespace orcl_data temporary tablespace orcl_temp;

/*第4步:給使用者授予許可權  */
grant connect,resource,dba to orcl;

登陸剛剛建立的使用者orcl

SQL> conn orcl/orcl
Connected.

建立測試表

SQL> create table a(id number,name varchar(10));
SQL> insert into a values(1,'xiao');
SQL> insert into a select * from a;

SQL> select * from a;

ID NAME
---------- ----------
1 xiao
1 xiao

2、通過rman建立備份檔案

[oracle@dg1 ~]$mkdir -p /u01/app/oracle/bak

[oracle@dg1 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Wed May 29 15:09:56 2013

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

connected to target database: ORCL (DBID=1344401817)

RMAN> 
RMAN>backup database format '/u01/app/oracle/bak/%d_%s.bak';

`````````````````````
`````````````````````備份資訊--略
`````````````````````
Finished backup at 29-MAY-13


3、複製引數檔案到另一臺伺服器(initorcl.ora)

(如果目錄下沒有該引數檔案,通過create pfile from spfile;建立)

[oracle@dg1 ~]$ cd $ORACLE_HOME/dbs

[oracle@dg1 dbs]$ ls
hc_DBUA0.dat  init.ora      lkORCL     peshm_DBUA0_0  snapcf_orcl.f
hc_orcl.dat   initorcl.ora  orapworcl  peshm_orcl_0   spfileorcl.ora

[oracle@dg1 dbs]$ scp initorcl.ora 192.168.0.202:$ORACLE_HOME/dbs

reverse mapping checking getaddrinfo for bogon failed - POSSIBLE BREAK-IN ATTEMPT!
oracle@192.168.0.202's password: 
initorcl.ora                                                                  100% 1395     1.4KB/s   00:00    
[oracle@dg1 dbs]$ 

備資料庫(192.168.0.202)

1、首先安裝oracle軟體,不建立資料庫

2、建立相應目錄

[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/bak

[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/oradata/orcl

[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,dpdump,udump,pfile}
 
[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/archive/orcl

[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/oradata/orcl

[oracle@dg2 ~]$ mkdir -p /u01/app/oracle/flash_recovery_area/orcl


主庫複製rman備份的資料檔案和歸檔日誌檔案 到備庫相應目錄下(注意:主庫和備庫目錄必須一致)

[oracle@dg1 ~]$ cd /u01/app/oracle/bak


[oracle@dg1 bak]$ scp * 192.168.0.202:/u01/app/oracle/bak/


[oracle@dg1 ~]$ cd /u01/app/oracle/archive/orcl

[oracle@dg1 orcl]$ scp * 192.168.0.202:/u01/app/oracle/archive/orcl/


備庫通過rman進行恢復

[oracle@dg2 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Wed May 29 15:33:11 2013

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

connected to target database (not started)

RMAN> 
RMAN> startup nomount;

Oracle instance started

Total System Global Area     368263168 bytes

Fixed Size                     1336596 bytes
Variable Size                306186988 bytes
Database Buffers              54525952 bytes
Redo Buffers                   6213632 bytes

RMAN> 

轉儲controlfile控制檔案(因為預設備份資訊全部放在控制檔案中)

RMAN> restore controlfile from '/u01/app/oracle/bak/ORCL_27.bak';

Starting restore at 29-MAY-13
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 control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
Finished restore at 29-MAY-13

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

檢視備份資訊

RMAN> list backup of database;

················
·················
·················

轉儲資料庫

RMAN> restore database;

···············
···············
·················

oracle@dg1 ~]$ sqlplus "/as sysdba"

SQL> recover using backup controlfile until cancel;

ORA-00308: cannot open archived log
'/u01/app/oracle/archive/orcl/1_62_816621081.arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3(可以忽略)

SQL> alter database open resetlogs;

SQL> conn orcl/orcl
Connected.
SQL> select * from a;

ID NAME
---------- ----------
1 xiao
1 xiao


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28698327/viewspace-762366/,如需轉載,請註明出處,否則將追究法律責任。

相關文章