ITPub博客

首页 > Linux操作系统 > Linux操作系统 > rman异地备份与恢复测试

rman异地备份与恢复测试

原创 Linux操作系统 作者:Coast_lichao 时间:2011-01-24 08:52:58 0 删除 编辑

一. 分析:RMAN并不支持客户端连接服务器进行备份,所以仍然需要在服务器上使用RMAN备份,客户要求备份至异地;

二. 环境:

1.       两台win2003 Enterprise edition:主机名si_vm_w2k3ip:192.168.2.204;备机名PC2 ip:192.168.2.205

2.       si_vm_w2k3上和PC2上同时安装oracle 10.2.0.1.0;

3.       ORACLE_HOME=C:\oracle\product\10.2.0\db_1.ORADATA=C:\oracle\product\10.2.0\oradata\lichao;

三. 操作步骤:

1, PC2上创建共享目录RMAN,在RMAN目录里建子目录logs,并授予administrator权限,保证administrator具备口令为Root1!口令不能为空;

2,si_vm_w2k3确保administrator的口令与PC2administrator口令相同且为Root1!;

3,si_vm_w2k3映射\\PC2\RMAN目录为Z盘,并明确登录用户为administrator及口令;

 

4,si_vm_w2k3机器修改ORACLE的两个服务OracleTNSListernerOracleServiceLICHAO为账户登录:用户名为administrator,口令为Root1!;

5,重启si_vm_w2k3机器的两个服务;

备份可以备份在本地,有必要时再传到PC2上。

创建复制数据库:

1,创建口令文件 orapwd file=c:\oracle\product\10.2.0\db_1\database\pwdlichao.ora password=admin entries=10

2,创建辅助数据库实例:

Oradim –new –sid test

4.       配置监听程序

在这里我们需要配置的监听有两个分别是原数据库和复制数据库的监听

TEST实例的监听

Listener.ora

SID_LIST_LISTENER =

  (SID_LIST =

     (SID_DESC =

      (GLOBAL_DBNAME = test)

      (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)

      (SID_NAME = test))

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))

     

    )

  )

Tnsname.ora

lichao =

(DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = lichao))

  )

 

test =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = test))

  )

lichao实例监听配置:

Listener.ora

SID_LIST_LISTENER =

  (SID_LIST =

     (SID_DESC =

      (GLOBAL_DBNAME = test)

      (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)

      (SID_NAME = lichao))

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))

     

    )

  )

 

 

Tnsname.ora

lichao =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.204)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = lichao))

  )

 

test =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.205)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SID = test))

  )

 

配置完监听记得重新启动监听的服务进程,并使用lsnrctl stoplsnrctl start来重新启动监听

 

 

5,创建辅助(复制)数据库的目录

6,创建辅助(复制)数据库的参数文件

主库执行Create pfile from spfile

复制pfile到复制数据库,修改相关参数:

Adumpbdumpcdumpudumpddumpdb_name和控制文件路径。

还需要添加两个参数:

db_file_name_convert=(¨c:\oracle\product\10.2.0\oradata\lichao¨,¨c:\oracle\product\10.2.0\oradata\lichao¨)

log_file_name_convert=(¨c:\oracle\product\10.2.0\oradata\lichao¨,¨c:\oracle\product\10.2.0\oradata\lichao¨)

完成以上步骤后我们可以开始创建我们真正想要的参数文件:

7,SQL>create spfile=’c:\oracle\product\10.2.0\db_1\database\spfilelichao.ora’ from pfile=’c:\abc.ora

使用RMAN完全备份原数据库

 

导入数据:

创建表空间lnxh_v2 Create tablespace lnxh_v2 datafile’ C:\oracle\product\10.2.0\oradata\tom\lnxh_v2.dbf’ size 30000m;

创建用户:lnxh_v2:create user lnxh_v2 identified by lnxh_v2 default tablespace

Lnxh_v2;

导入数据 imp userid=lnxh_v2/lnxh_v2 file=c.\xx\lnxh.dmp log=imp.log fromuser=lnxh_v2 touser=lnxh_v2

查看lnxh_v2用户表:

SQL> select count(table_name) from dba_tables where wner='LNXH_V2';

 

COUNT(TABLE_NAME)                                                              

-----------------                                                              

              858                      

SQL> select current_scn from v$database;

 

CURRENT_SCN                                                                    

-----------                                                                    

     820841     

Run{

Backup full database format ‘\\192.168.2.205/rman /%U.bak';

Backup archivelog all format ‘\\192.168.2.205/rman /arc_%U.bak’;

Copy current controlfile to ‘\\192.168.2.205/rman /control_bak.ctl’;

}

                             

8复制库处于nomount状态。

9. 创建备份

Rman target /

Run{

Backup full database format ‘\\192.168.2.205/rman /%U.bak';

Backup archivelog all format ‘\\192.168.2.205/rman /arc_%U.bak’;

Copy current controlfile to ‘\\192.168.2.205/rman /control_bak.ctl’;

}

 

10.使用rman复制数据库

rman target /  AUXILIARY sys/admin@test

DUPLICATE TARGET DATABASE TO “test” nofilenamecheck

查看复制库lnxh_v2用户表:

SQL> select count(table_name) from dba_tables where wner='LNXH_V2';

 

COUNT(TABLE_NAME)                                                               

-----------------                                                              

              858   

SQL> select current_scn from v$database;

 

CURRENT_SCN                                                                    

-----------                                                                     

     820859

启用主库块跟踪:alter database enable block change tracking

建立0级备份

Run{

Allocate channel d1 device type disk format ‘\\192.168.2.205/rman/DB_LV_0_%T_%t.rbf’;

Backup

Incremental level 0 database tag ‘LV_0’;

SQL ‘ALTER SYSTEM ARCHIVE LOG CURRENT’;

Release channel d1;

}

建立一个1级备份

Run{

Allocate channel d1 type disk;

Backup

Incremental level 1

Format ‘\\192.168.2.205/rman/%U’

(database);

Release channel d1;

}                  

主库:restore database preview

还原恢复数据库

Rman target /

Startup nomount

Restore controlfile from ‘\\192.168.2.205/rman/auto_sp_%F.rbf’;

Restore database;

Recover database until sequence xx;

Alter database open resetlogs;

 

 

 

复制库上创建恢复目录数据库

Create tablespace rman datafileC:\oracle\product\10.2.0\oradata\tom\rman.dbf’ size 50m;

Create user rman_user identified by rman_user default tablespace rman temporary tablespace temp;

Rman>connect catalog rman_user/rman_user

Rman>create catalog tablespace rman;

Rman>register database;

登记备份文件和归档日志到RMAN仓库

Rman>catalog start with’c:\rman’(如果复制过来的备份文件的路径和主库不同,要让RMAN知道这些文件在哪里。

Rman> restore database

           Recovery database until scn ****

经测试恢复后数据正常;

 

 

 

迁移业务数据到metarnet表空间;

Create tablespace metarnet datafile’Y:\oracle\oradata\metarnet.dbf’ size 4000m;

迁移脚本见lnxh.sql

Conn lnxh_v2/lnxh_v2

Start lnxh.sql

alter                                                                              table CONF_NE_IP2PORT_P                                                                                                            move   tablespace  metarnet;

alter                                                                              table CONF_NE_IP2PORT_V                                                                                                            move   tablespace  metarnet;

alter                                                                              table CONF_NE_IPMACTABLE                                                                                                           move   tablespace  metarnet;

alter                                                                              table CONF_NE_P                                                                                                                    move   tablespace  metarnet;

alter                                                                              table CONF_NE_PORT                                                                                                                 move   tablespace  metarnet;

alter                                                                              table CONF_NE_PORT_P                                                                                                               move   tablespace  metarnet;

alter                                                                              table CONF_NE_PORT_V                                                                                                               move   tablespace  metarnet;

alter                                                                              table CONF_NE_PROBE                                                                                                                move   tablespace  metarnet;

………………………………

迁移完后验证:

Lnxh_v2用户登录查询:select distinct(tablespace_name) from user_tables;

SQL> select distinct(tablespace_name) from user_tables;

 

TABLESPACE_NAME                                                      

------------------------------                                       

                                                                     

LNXH_V2                                                               

METARNET                                                             

(由于表空间大小受限,所以部分表迁移未成功,但此操作可以实现业务表从lnxh_v2迁移到metarnet表空间)

再次复制数据库到异地机;

建立测试数据:

主库做一个基于业务表空间metarnet的备份:

Run{

        Backup tablesapce metarnet format’\\192.168.2.205/rman/metarnet_%U.bak’;

}

复制库上执行:

Catalog start withc:\rman’;

报错了无法在目录表空间注册备份文件如下:

为做尝试,我在复制库nomount状态下还原控制文件:

启动到mount状态:

Restore tablespace metarnet

这里提示redolog不同。

再次注册备份文件:

Catalog start with ‘c:\rman’;

注册成功

试着恢复metarnet表空间

用备份再次还原;

Restore controlfile from’c:\rman\AUTO_SP_C-18308577735-20110120-03.RBF

 

基于表空间的恢复还有问题,有待于进一步确定;

继续测试:

Run{

 Backup tablesapce metarnet format’\\192.168.2.205/rman/tablespace_metarnet_%U.bak’;

Run{

Allocate channel d1 device type disk format’\\192.168.2.205/rman/archive_%U.bak’;

Backup archivelog all;

Release channel d1;

}

 

Catalog start withc:/rman’;

Sqlalter tablespae metarnet offlien’;

这属于介质恢复,如果原表空间存在并且正常时无法进行介质恢复的,系统会报错。以下是删除metarnet数据文件后进行的还原。

其实这个是失败的,为啥呢,因为抽取的归档文件是复制库本身的归档文件,并不是主库备份过来的归档文件。

所以恢复表面成功,其实是数据没有恢复过来。所以不还原控制文件,这个即使在恢复目录中注册了备份的归档,也是无法使用的,因为两个库的线程是不一致的。那如果为了还原和恢复一个表空间,需要还原控制文件了,显然这样是行不通的,整个数据库的状态就会处于不一致,无法打开。

综合所做实验:如果要使用rman来做方案,那么就要还原控制文件,还原整个数据库,然后再恢复才会有效果。不能够还原和恢复某个表空间。

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

请登录后发表评论 登录
全部评论

注册时间:2009-04-26

  • 博文量
    19
  • 访问量
    66966