myguangzhou
作者myguangzhou·2012-06-26 18:12
技术经理·Uniwise

使用nbu进行基于时间点的oracle不完全恢复测试一例

字数 7714阅读 5549评论 1赞 1
这些天刚好在客户现场做nbu的备份项目,客户提出需要测试恢复oracle,于是自己做了个基于时间点的不完全恢复测试;记录如下
一、安装nbu agent for oracle_solaris
自从nbu7.0以来,agent代理就包含了oracledb2sap等数据库代理软件,无需单独安装了;
二、链接oracle库文件
用oracle用户登录系统,执行oracle_link

$ cd /usr/openv/netbackup/bin

$ ./oracle_link

Tue Jun 26 15:53:04 CST 2012

All Oracle instances should be shutdown before running this script.

 Please log into the Unix system as the Oracle owner for running this script

 Do you want to continue? (y/n) [n] y

 LIBOBK path: /usr/openv/netbackup/bin

ORACLE_HOME: /oracle/product/11.2.0

Oracle version: 11.2.0.3.0

Platform type: sparc

Linking LIBOBK:

ln -s /usr/openv/netbackup/bin/libobk.so64.1 /oracle/product/11.2.0/lib/libobk.so

Done

Please check the trace file located in /tmp/make_trace.6091

to make sure the linking process was successful.

 

注意这个提醒关机的警告可以忽略,9I中才需要关闭oracle实例。

三、创建备份脚本

将模板脚本编辑如下

ORACLE_HOME=/oracle/product/11.2.0
export ORACLE_HOME
ORACLE_SID=kbankdb
export ORACLE_SID
TARGET_CONNECT_STR=/

$RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF
RUN {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
BACKUP
    $BACKUP_TYPE
    SKIP INACCESSIBLE
    TAG hot_db_bk_level0
    FILESPERSET 5
    # recommended format
    FORMAT 'bk_%s_%p_%t'
    DATABASE;
    sql 'alter system archive log current';
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
# backup all archive logs
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
BACKUP
BACKUP
   filesperset 20
   FORMAT 'al_%s_%p_%t'
   ARCHIVELOG ALL;
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
#
# Note: During the process of backing up the database, RMAN also backs up the
# control file.  This version of the control file does not contain the
# information about the current backup because "nocatalog" has been specified.
# To include the information about the current backup, the control file should
# be backed up as the last step of the RMAN section.  This step would not be
# necessary if we were using a recovery catalog or auto control file backups.
#
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
BACKUP
    # recommended format
    FORMAT 'cntrl_%s_%p_%t'
    CURRENT CONTROLFILE;
RELEASE CHANNEL ch00;
}

四、创建表并插入记录

SQL> create table mytable(id number(4),name varchar2(14)) tablespace users;

 

Table created.

 

SQL> insert into mytable values(01,'kbank');

 1 row created.

 SQL> commit;

 Commit complete.

SQL> select * from mytable;

        ID NAME

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

         1 kbank 

SQL>

 

记录当前时间

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered. 

SQL> select sysdate from dual;

SYSDATE

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

2012-06-26 17:02:02 

SQL>

 

再插入记录,并记录时间

SQL> insert into mytable values(02,'china');

1 row created. 

SQL> commit;

Commit complete. 

SQL> select sysdate from dual;

SYSDATE

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

2012-06-26 17:03:33

 SQL>

 


五、发起备份

确保备份成功。

 

六、执行不完全恢复

1.先关闭实例

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

2.加载到mount状态

SQL> startup mount;

ORACLE instance started. 

Total System Global Area 2004860928 bytes

Fixed Size                  2160696 bytes

Variable Size             587204552 bytes

Database Buffers         1409286144 bytes

Redo Buffers                6209536 bytes

Database mounted.

SQL>

 

3.执行恢复脚本,将数据库恢复到'2012/06/26 17:02:02'时刻

$ rman target /

 

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Jun 26 17:19:37 2012

 

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

 

connected to target database: KBANKDB (DBID=4053543997, not open)

 

RMAN> run {

2> allocate channel ch1 type 'sbt_tape';

3> allocate channel ch2 type 'sbt_tape';

4> set until time "to_date('2012/06/26 17:02:02','yyyy/mm/dd hh24:mi:ss')";

5> restore database;

6> recover database;

7> release channel ch1;

8> release channel ch2;

9> }

 

using target database control file instead of recovery catalog

allocated channel: ch1

channel ch1: SID=96 device type=SBT_TAPE

channel ch1: Veritas NetBackup for Oracle - Release 7.1 (2012031623)

 

allocated channel: ch2

channel ch2: SID=127 device type=SBT_TAPE

channel ch2: Veritas NetBackup for Oracle - Release 7.1 (2012031623)

executing command: SET until clause 

Starting restore at 26-JUN-12

channel ch1: starting datafile backup set restore

channel ch1: specifying datafile(s) to restore from backup set

channel ch1: restoring datafile 00001 to /oracle/TPGISOFTDB/sys/system01.dbf

channel ch1: restoring datafile 00003 to /oracle/TPGISOFTDB/undo/undotbs01.dbf

channel ch1: reading from backup piece bk_3_1_786988494

channel ch2: starting datafile backup set restore

channel ch2: specifying datafile(s) to restore from backup set

channel ch2: restoring datafile 00002 to /oracle/TPGISOFTDB/sys/sysaux01.dbf

channel ch2: restoring datafile 00004 to /oracle/TPGISOFTDB/data/users01.dbf

channel ch2: reading from backup piece bk_4_1_786988494

channel ch1: piece handle=bk_3_1_786988494 tag=HOT_DB_BK_LEVEL0

channel ch1: restored backup piece 1

channel ch1: restore complete, elapsed time: 00:04:25

channel ch2: piece handle=bk_4_1_786988494 tag=HOT_DB_BK_LEVEL0

channel ch2: restored backup piece 1

channel ch2: restore complete, elapsed time: 00:05:15

Finished restore at 26-JUN-12

 

Starting recover at 26-JUN-12

 

starting media recovery

 

archived log for thread 1 with sequence 2 is already on disk as file /oracle/product/11.2.0/dbs/arch1_2_786977585.dbf

archived log for thread 1 with sequence 3 is already on disk as file /oracle/product/11.2.0/dbs/arch1_3_786977585.dbf

archived log for thread 1 with sequence 4 is already on disk as file /oracle/product/11.2.0/dbs/arch1_4_786977585.dbf

archived log file name=/oracle/product/11.2.0/dbs/arch1_2_786977585.dbf thread=1 sequence=2

archived log file name=/oracle/product/11.2.0/dbs/arch1_3_786977585.dbf thread=1 sequence=3

media recovery complete, elapsed time: 00:00:15

Finished recover at 26-JUN-12

 released channel: ch1

released channel: ch2 

RMAN>

 

4.以resetlogs打开实例

RMAN> alter database open resetlogs; 

database opened

RMAN> 

RMAN> exit

 

5.检查表记录是否已经恢复到到'2012/06/26 17:02:02'时刻

$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jun 26 17:35:01 2012 

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

 Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining,

Oracle Database Vault and Real Application Testing options

 

SQL> select * from mytable; 

        ID NAME

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

         1 kbank

SQL>

 

 

 

 

 

 

 

 

 

 

 

 

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论1 条评论

dx_958dx_958系统运维工程师银行保险业
2015-11-05 16:20
点赞
Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广