为了账号安全,请及时绑定邮箱和手机立即绑定

RAC环境下的备份与恢复(一)

标签:
Oracle

  本节中将演示下rac环境下的数据的备份和完全恢复,rac的备份和恢复同单实例数据库对比,只是在处理归档日志上有些扩展,一般来讲,可以将归档日志存储在ASM磁盘组中,或者存储在集群文件系统上,NFS以及本地文件系统上,当归档日志存储在ASM,集群文件系统或者NFS上的时候,rac备份和恢复和单实例下的操作基本一致,下面的场景归档日志存储在ASM上!

一:查看rac归档的设置

[oracle@rac1 ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Mon Dec 12 20:09:56 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn /as sysdba

Connected.

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            +FRA

Oldest online log sequence     38

Next log sequence to archive   39

Current log sequence           39

SQL> alter system switch logfile;

System altered.

SQL> conn sys/123456@racdb2 as sysdba

Connected.

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            +FRA

Oldest online log sequence     14

Next log sequence to archive   15

Current log sequence           15

SQL> alter system switch logfile;

System altered.

二:查看ASM磁盘组中的归档日志

[oracle@rac1 ~]$ export ORACLE_SID=+ASM1

[oracle@rac1 ~]$ asmcmd

ASMCMD> cd FRA

ASMCMD> ls

RACDB/

ASMCMD> cd racdb

ASMCMD> ls  

ARCHIVELOG/

BACKUPSET/

CONTROLFILE/

ONLINELOG/

ASMCMD> ls archivelog

2011_12_12/

ASMCMD> ls archivelog/2011_12_12/

thread_1_seq_39.261.769724057

thread_2_seq_15.265.769695387

三:使用rman备份数据库

[oracle@rac1 ~]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Dec 12 20:17:53 2011

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

connected to target database: RACDB (DBID=766822397)

RMAN> delete noprompt backupset;

RMAN> delete noprompt archivelog all;

RMAN> run {

2> allocate channel c1 device type disk;

3> allocate channel c2 device type disk;

4> backup incremental level 0 

5> tag 'racdb_bak_20121212'

6> format '/home/oracle/backup/racdb%U'

7> database plus archivelog

8> delete all input;

9> release channel c1;

10> release channel c2;

11> }

RMAN> list backup of database summary;

List of Backups

===============

Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag

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

7       B  0  A DISK        2011-12-12 20:34:22 1       1       NO         RACDB_BAK_20121212

8       B  0  A DISK        2011-12-12 20:34:22 1       1       NO         RACDB_BAK_20121212

四:创建基础数据

[oracle@rac1 ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Mon Dec 12 20:57:01 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn /as sysdba

Connected.

SQL> create user test identified by hr account unlock 

  2  default tablespace users;

User created.

SQL> grant connect,resource to test;

Grant succeeded.

SQL> conn test/hr@racdb2 

Connected.

SQL> show user;

USER is "TEST"

SQL> create table t1 (a number);

Table created.

SQL> insert into t1 values (1);

1 row created.

SQL> commit;

Commit complete.

SQL> conn /as sysdba

Connected.

SQL> select file_name from dba_data_files where tablespace_name='USERS';

FILE_NAME

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

+DATA/racdb/datafile/users.259.769205541

五:删除users表空间数据文件

[oracle@rac2 ~]$ export ORACLE_SID=+ASM2

[oracle@rac2 ~]$ asmcmd rm -rf +DATA/RACDB/datafile/USERS.259.769205541

ORA-15032: not all alterations performed

ORA-15028: ASM file '+DATA/RACDB/datafile/USERS.259.769205541' not dropped; currently being accessed (DBD ERROR: OCIStmtExecute)

上面的错误,据说是oracle的bug,很遗憾的是在10.2.0.5的版本中,这个问题没能解决,只能停止rac实例后删除数据文件

[oracle@rac2 ~]$ srvctl stop database -d racdb

[oracle@rac2 ~]$ srvctl status database -d racdb

Instance racdb1 is not running on node rac1

Instance racdb2 is not running on node rac2

[oracle@rac2 ~]$ asmcmd rm -rf +DATA/RACDB/datafile/USERS.259.769205541

六:进行恢复

在接下来的启动数据库操作将会失败,日志里面明显的告诉我们4号数据文件不存在

[oracle@rac2 ~]$ srvctl  start database -d racdb

PRKP-1001 : Error starting instance racdb1 on node rac1

CRS-0215: Could not start resource 'ora.racdb.racdb1.inst'.

PRKP-1001 : Error starting instance racdb2 on node rac2

CRS-0215: Could not start resource 'ora.racdb.racdb2.inst'.

[oracle@rac1 ~]$ tail -f /u01/app/oracle/admin/racdb/bdump/alert_racdb1.log 

Errors in file /u01/app/oracle/admin/racdb/bdump/racdb1_dbw0_18977.trc:

ORA-01157: cannot identify/lock data file 4 - see DBWR trace file

ORA-01110: data file 4: '+DATA/racdb/datafile/users.259.769205541'

ORA-17503: ksfdopn:2 Failed to open file +DATA/racdb/datafile/users.259.769205541

ORA-15012: ASM file '+DATA/racdb/datafile/users.259.769205541' does not exist

ORA-1157 signalled during: ALTER DATABASE OPEN...

Mon Dec 12 21:31:41 CST 2011

Shutting down instance (abort)

License high water mark = 1

Instance terminated by USER, pid = 19192

将数据库启动到mount状态,利用rman进行还原和恢复

[oracle@rac2 ~]$ srvctl start database -d racdb -o mount

[oracle@rac1 ~]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Dec 12 21:33:17 2011

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

connected to target database: RACDB (DBID=766822397, not open)

RMAN> restore datafile 4;

Starting restore at 2011-12-12 21:34:08

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=145 instance=racdb1 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore

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

restoring datafile 00004 to +DATA/racdb/datafile/users.259.769205541

channel ORA_DISK_1: reading from backup piece /home/oracle/backup/racdb07mu24a1_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/backup/racdb07mu24a1_1_1 tag=RACDB_BAK_20121212

channel ORA_DISK_1: restore complete, elapsed time: 00:00:04

Finished restore at 2011-12-12 21:34:14

RMAN> recover datafile 4;

Starting recover at 2011-12-12 21:34:41

using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 42 is already on disk as file +FRA/racdb/archivelog/2011_12_12/thread_1_seq_42.265.769726867

archive log thread 2 sequence 18 is already on disk as file +FRA/racdb/archivelog/2011_12_12/thread_2_seq_18.261.769725271

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=1 sequence=41

channel ORA_DISK_1: reading from backup piece /home/oracle/backup/racdb0bmu24qo_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/backup/racdb0bmu24qo_1_1 tag=RACDB_BAK_20121212

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

archive log filename=+FRA/racdb/archivelog/2011_12_12/thread_1_seq_41.266.769728883 thread=1 sequence=41

channel ORA_DISK_1: starting archive log restore to default destination

channel ORA_DISK_1: restoring archive log

archive log thread=2 sequence=17

channel ORA_DISK_1: reading from backup piece /home/oracle/backup/racdb0cmu24qo_1_1

channel ORA_DISK_1: restored backup piece 1

piece handle=/home/oracle/backup/racdb0cmu24qo_1_1 tag=RACDB_BAK_20121212

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archive log filename=+FRA/racdb/archivelog/2011_12_12/thread_2_seq_17.262.769728885 thread=2 sequence=17

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

Finished recover at 2011-12-12 21:34:46

七:验证

[oracle@rac2 ~]$ srvctl stop database -d racdb -o immediate

[oracle@rac2 ~]$ srvctl start database -d racdb

[oracle@rac2 ~]$ srvctl status database -d racdb

Instance racdb1 is running on node rac1

Instance racdb2 is running on node rac2

[oracle@rac2 ~]$ sqlplus sys/123456@racdb2 as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Mon Dec 12 13:37:07 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production

With the Partitioning, Real Application Clusters, OLAP, Data Mining

and Real Application Testing options

SQL> select * from test.t1;

         A

----------

         1

八:表决盘和ocr的备份

[oracle@rac1 ~]$ crsctl query css votedisk

 0.     0    /dev/raw/raw7

 1.     0    /dev/raw/raw8

 2.     0    /dev/raw/raw9

located 3 votedisk(s).

[oracle@rac1 ~]$ dd if=/dev/raw/raw7 of=vote.dbf

587744+0 records in

587744+0 records out

[oracle@rac1 ~]$ file vote.dbf 

vote.dbf: binary Computer Graphics Metafile

[oracle@rac1 ~]$ ocrcheck

Status of Oracle Cluster Registry is as follows :

         Version                  :          2

         Total space (kbytes)     :     293624

         Used space (kbytes)      :       3824

         Available space (kbytes) :     289800

         ID                       :    7468264

         Device/File Name         : /dev/raw/raw5

                                    Device/File integrity check succeeded

         Device/File Name         : /dev/raw/raw6

                                    Device/File integrity check succeeded

         Cluster registry integrity check succeeded

         Cluster registry integrity check succeeded

导出ocr,需要使用root用户

[oracle@rac1 ~]$  /u01/app/oracle/product/10.2.0/crs_1/bin/ocrconfig -export 1.ocr

PROT-20: Insufficient permission to proceed. Require privileged user

[root@rac1 ~]# /u01/app/oracle/product/10.2.0/crs_1/bin/ocrconfig -export 1.ocr

[root@rac1 ~]# file 1.ocr 

1.ocr: data

©著作权归作者所有:来自51CTO博客作者ylw6006的原创作品,谢绝转载,否则将追究法律责任

backuprecoverrestoreRAC


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消