环境介绍:
操作系统版本:RHEL5.4 32位
ORALCE版本: 10.2.0.1 32位
ORACLE_SID: orcl
源服务器和目的服务器的操作系统,oracle版本均一致
源服务器:192.168.227.20
目的服务器:192.168.227.30,只需要安装oracle软件即可,不需要建库操作
一:在源服务器上使用rman备份数据库,包括数据文件,归档日志文件和控制文件,参数文件的备份
- [oracle@orcl ~]$ mkdir /u01/backup
- [oracle@orcl ~]$ rman target /
- Recovery Manager: Release 10.2.0.1.0 - Production on Tue Sep 6 16:04:53 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database: ORCL (DBID=1287906064)
- RMAN> run {
- 2> allocate channel c1 device type disk;
- 3> backup incremental level 0
- 4> format '/u01/backup/db_full_%U.bkp'
- 5> tag '2011-09-06-FULL'
- 6> database plus archivelog;
- 7> release channel c1;
- 8> }
- RMAN> backup current controlfile format '/u01/backup/control20110906.bak';
- RMAN> backup spfile format '/u01/backup/spfile20110906.bak';
二:在目的服务器上复制备份数据,并准备好相关的目录
- [oracle@orcl ~]$ mkdir /u01/backup
- [oracle@orcl ~]$ scp -rp 192.168.227.20:/u01/backup/* /u01/backup/
- oracle@192.168.227.20's password:
- control20110906.bak 100% 6944KB 1.7MB/s 00:04
- db_full_0fmlsmdt_1_1.bkp 100% 97MB 4.4MB/s 00:22
- db_full_0gmlsme5_1_1.bkp 100% 593MB 9.1MB/s 01:05
- db_full_0hmlsmg7_1_1.bkp 100% 6656 6.5KB/s 00:00
- spfile20110906.bak 100% 96KB 96.0KB/s 00:00
- [oracle@orcl ~]$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,dpdump,udump,pfile}
- [oracle@orcl ~]$ mkdir -p /u01/app/oracle/oradata/orcl
- [oracle@orcl ~]$ mkdir -p /u01/app/oracle/flash_recover_area/ORCL
三:在目的服务器上进行恢复
- [oracle@orcl ~]$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora
- [oracle@orcl ~]$ export ORACLE_SID=orcl
- [oracle@orcl ~]$ rman target /
- Recovery Manager: Release 10.2.0.1.0 - Production on Tue Sep 6 16:18:19 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- connected to target database (not started)
- RMAN> set dbid 1287906064; //指定DBID,需要和源服务器的DBID一致
- RMAN> startup nomount; //启动数据库到nomount状态,这里需要前面创建initorcl.ora文件,否则将报错
- RMAN> restore spfile from '/u01/backup/spfile20110906.bak'; //恢复参数文件
- RMAN> startup nomount force; //重启实例到nomout状态
- RMAN> restore controlfile from '/u01/backup/control20110906.bak'; //恢复控制文件
- RMAN> restore database; //还原数据库文件
- RMAN> recover database; //恢复数据库文件,这里将报错
- RMAN-03002: failure of recover command at 09/06/2011 17:03:51
- RMAN-06054: media recovery requesting unknown log: thread 1 seq 15 lowscn 547974
- RMAN> exit
- [oracle@orcl ~]$ sqlplus /nolog //在sqlplus中对数据库进行until cancel操作后以resetlogs方式打开
- SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 6 17:04:22 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> recover database using backup controlfile until cancel;
- ORA-00279: change 547974 generated at 09/06/2011 16:49:11 needed for thread 1
- ORA-00289: suggestion :
- /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_09_06/o1_mf_1_15_%u_.ar
- c
- ORA-00280: change 547974 for thread 1 is in sequence #15
- Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
- cancel
- Media recovery cancelled.
- SQL> alter database open resetlogs;
四:测试
- SQL> select member from v$logfile;
- MEMBER
- --------------------------------------------------------------------------------
- /u01/app/oracle/oradata/orcl/redo03.log
- /u01/app/oracle/oradata/orcl/redo02.log
- /u01/app/oracle/oradata/orcl/redo01.log
- SQL> select file_name from dba_data_files;
- FILE_NAME
- --------------------------------------------------------------------------------
- /u01/app/oracle/oradata/orcl/users01.dbf
- /u01/app/oracle/oradata/orcl/sysaux01.dbf
- /u01/app/oracle/oradata/orcl/undotbs01.dbf
- /u01/app/oracle/oradata/orcl/system01.dbf
- /u01/app/oracle/oradata/orcl/example01.dbf
- /u01/app/oracle/oradata/orcl/tbs_apple01.dbf
- 6 rows selected.
- SQL> select count(*) from dba_temp_files;
- COUNT(*)
- ----------
- 1
- SQL> select count(*) from hr.employees;
- COUNT(*)
- ----------
- 107
五:注意事项
- RMAN> list incarnation; //生成一个新的incarnation
- using target database control file instead of recovery catalog
- List of Database Incarnations
- DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
- ------- ------- -------- ---------------- --- ---------- ----------
- 1 1 ORCL 1287906064 PARENT 1 2005-06-30:19:09:40
- 2 2 ORCL 1287906064 PARENT 446075 2011-08-25:17:55:31
- 3 3 ORCL 1287906064 CURRENT 547975 2011-09-06:17:07:09
- [oracle@orcl ~]$ emctl start dbconsole //dbconsole需要重新配置,orapwd文件也需要创建
- TZ set to PRC
- OC4J Configuration issue. /u01/app/oracle/product/10.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_orcl.herostart.com_orcl not found
六:增量备份的异机恢复
1:源服务器
- SQL> create user rman_inr identified by "123456" default tablespace users;
- User created.
- SQL> grant connect,resource to rman_inr;
- Grant succeeded.
- SQL> create table rman_inr.test as select * from dba_source;
- Table created.
- RMAN> backup incremental level 1
- 2> format '/u01/backup/inr1_db_%U' tag 'inr_1'
- 3> database plus archivelog;
- [oracle@orcl ~]$ rman target /
- RMAN> backup incremental level 1
- 2> format '/u01/backup/inr1_db_%U' tag 'inr_1'
- 3> database plus archivelog;
- RMAN> backup current controlfile format '/u01/backup/control02.bak';
- [oracle@orcl ~]$ ls -lh /u01/backup/inr1_db_1*
- -rw-r----- 1 oracle oinstall 53M Sep 8 16:34 /u01/backup/inr1_db_1omm1ud0_1_1
- -rw-r----- 1 oracle oinstall 51M Sep 8 16:35 /u01/backup/inr1_db_1pmm1udk_1_1
- -rw-r----- 1 oracle oinstall 6.9M Sep 8 16:35 /u01/backup/inr1_db_1qmm1uf2_1_1
- -rw-r----- 1 oracle oinstall 11K Sep 8 16:35 /u01/backup/inr1_db_1rmm1uf5_1_1
- [oracle@orcl ~]$ scp /u01/backup/inr1_db_1* 192.168.227.30:/u01/backup/
- [oracle@orcl ~]$ scp /u01/backup/control02.bak 192.168.227.30:/u01/backup/
2:目标服务器
- [oracle@orcl ~]$ sqlplus /nolog
- SQL> conn /as sysdba
- Connected.
- SQL> shutdown immediate;
- RMAN> set dbid=1287906064;
- RMAN> startup nomount;
- RMAN> restore controlfile from '/u01/backup/control02.bak';
- RMAN> startup mount force;
- RMAN> restore database;
- RMAN> recover database;
- RMAN-03002: failure of recover command at 09/08/2011 16:46:44
- RMAN-06054: media recovery requesting unknown log: thread 1 seq 45 lowscn 598452
- RMAN> exit
- [oracle@orcl ~]$ sqlplus /nolog
- SQL> conn /as sysdba
- SQL> recover database using backup controlfile until cancel;
- ORA-00279: change 598452 generated at 09/08/2011 16:35:49 needed for thread 1
- ORA-00289: suggestion : /u01/arch/orcl/1_45_760125331.arc
- ORA-00280: change 598452 for thread 1 is in sequence #45
- Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
- cancel
- Media recovery cancelled.
- SQL> alter database open resetlogs;
- Database altered.
3:测试
- SQL> conn rman_inr/123456
- Connected
- SQL> select count(*) from test;
- COUNT(*)
- ----------
- 292428
本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/659104如需转载请自行联系原作者
ylw6006