Oracle DataGuard数据备份方案详解
http://database.51cto.com 2009-07-03 09:44 vfast_chenxy 追求 我要评论(0)
• 摘要:本文介绍如何使用RMAN备份创建备库(dataguard)。Oracle DataGuard是一种数据库级别的HA方案,最主要功能是冗灾、数据保护、故障恢复等。
• 标签:Oracle DataGuard
•
限时报名参加“甲骨文全球大会•2010•北京”及“JavaOne和甲骨文开发者大会2010”
Oracle DataGuard是一种数据库级别的HA方案,最主要功能是冗灾、数据保护、故障恢复等。
在生产数据库的"事务一致性"时,使用生产库的物理全备份(或物理COPY)创建备库,备库会通过生产库传输过来的归档日志(或重做条目)自动维护备用数据库。将重做数据应用到备用库。本文介绍使用RMAN备份创建备库(dataguard).
一:Oracle DataGuard环境概述
1.软件环境
操作系统Red Linux Enterprise as 5
数据库版本Oracle 10g release 2
2.primary databae
IP:192.168.18.1
ORACLE_SID=db1
db_unique_name=db1
3.standby database
IP:192.168.18.2
ORACLE_SID=standby
db_unique_name=standby
二,主数据库(db1)做准备
1.设置主数据库为Force logging
1. SQL> alter database force logging;
2.创建密码文件
1. cd $ORACLE_HOME/dbs/
2. orapwdfile=orapwdb1 password=123456 force=y
3.修改主库的初始化参数
1. alter system set log_archive_config='dg_config=(db1,standby)' scope=both;
2. alter system set log_archive_dest_1='location=/u01/db1/arch' scope=both;
3. alter system set db_unique_name='db1' scope=both;
4.生成数据库备份
1. RMAN> connect target sys/123456
2. RMAN> backup database format='/oracle/rmanback/%d_%s.dbf' plus archivelog;
3. [oracle@oracle rmanback]$ ls
4. DB1_1.dbfDB1_2.dbf
5.生成备库的control file
1. SQL>alter database create standby controlfile as '/oracle/rmanback/ctontrl01.ctl
6.配置listener.ora 和tnsnames.ora文件
启动lintener.ora,
1. [oracle@oracle dbs]$ lsnrctl status
2. LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 14-JUN-2009 02:54:29
3. Service "db1" has 1 instance(s).
4. Instance "db1", status READY, has 1 handler(s) for this service...
5. Service "db1_XPT" has 1 instance(s).
6. Instance "db1", status READY, has 1 handler(s) for this service...
7. The command completed successfully
配置rnsnames.ora
1. vi $ORACLE_HOME/network/admin/tnsnames.ora
2. db1 =
3. (DESCRIPTION =
4. (ADDRESS_LIST =
5. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.1)(PORT = 1521))
6. )
7. (CONNECT_DATA =
8. (SERVICE_NAME = db1)
9. standby =
10. (DESCRIPTION =
11. (ADDRESS_LIST =
12. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.2)(PORT = 1521))
13. )
14. (CONNECT_DATA =
15. (SERVICE_NAME = standby)
16. )
17. )
三.创建standby database
1.设置环境变量并安装oracle软件
1. #环境变量设成与主库一样
2. #只安装软件不安装库
3. ./runInstaller –silent –responseFile /tmp/installoracle.rsp
2.建立相关的目录
1. cd $ORACLE_HOME/dbs/
2. orapwdfile=orapwSID password=123456 force=y
3. #注要密码要与主库的一样, 否则会归档失败
3.建立密码文件
1. cd $ORACLE_HOME/dbs/
2. orapwd file=orapwSID password=123456 force=y
3. #注要密码要与主库的一样, 否则会归档失败
3.建立参数文件(pfile)
1. db_name = standby
2. shared_pool_size = 120M
3. undo_management = AUTO
4. undo_tablespace = undotbs
5. sga_max_size = 200M
6. sga_target = 160M
7. db_2k_cache_size = 4M
8.
9. standby_file_management=AUTO
10. fal_server='db1'
11. fal_client='standby'
12. log_archive_dest_1='location=/u01/app/oracle/product/10.2.0/dbs/arch'
13. log_archive_dest_2='SERVICE=db1 REOPEN=300'
14. log_archive_dest_state_1='ENABLE'
15. log_archive_dest_state_2='ENABLE'
4.CP主数据库RMAN备份及控制文件到备库
注意:备份存放位置要与primary database RMAN备份文件的位置相同. 控制文件存放位置要与生成standby database controlfile的位置相同
1. scp /oracle/rmanback/*.dbf
[email protected]:/oracle/rmanback/
2. scp /oracle/rmanback/*.ctl
[email protected]:/oracle/oracle/oradata/standby/
5.利用备用的控制文件,把备用数据库启到mount
1. SQL>connect / as sysdba
2. connnpcted to an idle instance.
3. SQL>startup nomount pfile=$ORACLE_HOME/dbs/initstandby.ora
4. SQL>alter database mount standby database
6. 配置listener.ora 和tnsnames.ora文件.
与主库相同启动listener,tnsnames.ora也与主库配置的一样,
当主备库的监听都启动后,进行测试,以例下面能顺利进行
1. tnsping db1
2. tnsping standby
3. SQL> sqlplus sys/123456@db1
4. SQL> sqlplus sys/123456@standby
7.转储数据库
1. RMAN>connect target /
2. connected to target database:TEST(DBID=788075692)
3. RMAN> restore database
8.恢复数据库。
1. SQL>recover managed standby database disconnect from session;
2. #如果有需要应用的日志并想手工应用,可以运行如下命令
3. SQL>recover automatic standby database;
9.检查standby database是否创建成功
a.在primary database 上切换日志
1. SQL> alter system switch logfile
b.在primary database上运行下面的语句
1. SQL> select max(sequence#) from v$archived_log;
2. MAX(SEQUENCE#)
3. --------------
4. 17
c. 在standby database上运行下面的语句
1. SQL> select sequence# ,applied from v$archived_log order by sequence#;
2. SEQUENCE# APP
3. --------------------- ---
4. 15YES
5. 16YES
6. 17YES
若在上步中的max sequence#在的的app状态为YES说明standby database 成功创建.
10. 以spfile启动并设为只读
1. SQL> create spfile from pfile;
2. SQL> shutdown immedaite
3. SQL> startup mount
4. SQL> alter database recover managed standby database disconnect from session;
5. SQL> alter database open read only;
以上就是Oracle DataGuard数据备份的操作流程。本文出自 “追求” 博客。