RAC环境下的备份与恢复

RAC环境下的备份与恢复(一)
2011-12-13 09:13:31
标签: backup  recover  restore  asm  rac
版权声明:原创作品,谢绝转载!否则将追究法律责任。

  本节中将演示下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


本节将简要的介绍下,rac环境下将归档日志存放到集群文件系统场景下的备份和恢复操作,集群文件系统采用oracle的ocfs2;
一:环境介绍
节点1 IP:192.168.1.41/24
操作系统:centos4.8 64位 (kvm虚拟机)
主机名:  rac1.yang.com

节点2 IP:192.168.1.42/24
操作系统: centos4.8 64位 (kvm虚拟机)
主机名:  rac2.yang.com

共享存储IP:192.168.1.100/24
操作系统: rhel6.0 64位
主机名:   rhel6.yang.com

二:安装和配置ocfs2集群文件系统

 [root@rac1 ~]# wget http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.EL-debuginfo-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.ELlargesmp-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.ELsmp-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-debuginfo-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-devel-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2console-1.2.7-1.el4.x86_64.rpm

[root@rac1 ~]# rpm -ivh *.rpm  (在节点2上也需要安装这些rpm包)
準備中...                ########################################### [100%]
   1:ocfs2-tools            ########################################### [ 13%]
   2:ocfs2-2.6.9-89.EL      ########################################### [ 25%]
   3:ocfs2-2.6.9-89.EL-debug########################################### [ 38%]
   4:ocfs2-2.6.9-89.ELlarges########################################### [ 50%]
   5:ocfs2-2.6.9-89.ELsmp   ########################################### [ 63%]
   6:ocfs2console           ########################################### [ 75%]
   7:ocfs2-tools-debuginfo  ########################################### [ 88%]
   8:ocfs2-tools-devel      ########################################### [100%]

利用ocfs2console工具创建配置文件,并复制到节点2上
[root@rac1 ~]# ocfs2console

 

[root@rac2 ~]# cat /etc/ocfs2/cluster.conf 
node:
        ip_port = 7777
        ip_address = 192.168.1.41
        number = 0
        name = rac1
        cluster = ocfs2

node:
        ip_port = 7777
        ip_address = 192.168.1.42
        number = 1
        name = rac2
        cluster = ocfs2

cluster:
        node_count = 2
        name = ocfs2

初始化o2cb,两个节点都需要如下操作
[root@rac1 ~]# /etc/init.d/o2cb unload
Stopping O2CB cluster ocfs2: OK
Unmounting ocfs2_dlmfs filesystem: OK
Unloading module "ocfs2_dlmfs": OK
Unmounting configfs filesystem: OK
Unloading module "configfs": OK

[root@rac1 ~]# /etc/init.d/o2cb configure
Configuring the O2CB driver.

This will configure the on-boot properties of the O2CB driver.
The following questions will determine whether the driver is loaded on
boot.  The current values will be shown in brackets ('[]').  Hitting
<ENTER> without typing an answer will keep that current value.  Ctrl-C
will abort.

Load O2CB driver on boot (y/n) [n]: y
Cluster to start on boot (Enter "none" to clear) [ocfs2]: 
Specify heartbeat dead threshold (>=7) [31]: 61  
Specify network idle timeout in ms (>=5000) [30000]: 
Specify network keepalive delay in ms (>=1000) [2000]: 
Specify network reconnect delay in ms (>=2000) [2000]: 
Writing O2CB configuration: OK
Loading module "configfs": OK
Mounting configfs filesystem at /config: OK
Loading module "ocfs2_nodemanager": OK
Loading module "ocfs2_dlm": OK
Loading module "ocfs2_dlmfs": OK
Mounting ocfs2_dlmfs filesystem at /dlm: OK
Starting O2CB cluster ocfs2: OK

[root@rac1 ~]# /etc/init.d/o2cb status
Module "configfs": Loaded
Filesystem "configfs": Mounted
Module "ocfs2_nodemanager": Loaded
Module "ocfs2_dlm": Loaded
Module "ocfs2_dlmfs": Loaded
Filesystem "ocfs2_dlmfs": Mounted
Checking O2CB cluster ocfs2: Online
  Heartbeat dead threshold: 61
  Network idle timeout: 30000
  Network keepalive delay: 2000
  Network reconnect delay: 2000
Checking O2CB heartbeat: Not active

三:对共享存储进行分区
[root@rac1 ~]# fdisk -l /dev/sda
Disk /dev/sda: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       10240    10485744   83  Linux

四:利用o2fsconsole工具格式化共享存储,并在各个节点进行挂载
[root@rac1 ~]# ocfs2console

[root@rac1 ~]# mkdir /u01/app/oracle/rac_archivelog
[root@rac1 ~]# mount -t ocfs2 -o datavolume,nointr /dev/sda1 /u01/app/oracle/rac_archivelog/
[root@rac1 ~]# mount |grep sda
/dev/sda1 on /u01/app/oracle/rac_archivelog type ocfs2 (rw,_netdev,datavolume,nointr,heartbeat=local)

[root@rac2 ~]# tail -1 /etc/fstab  (开机自动挂载配置)
/dev/sda1               /u01/app/oracle/rac_archivelog ocfs2 datavolume,nointr 0 0
[root@rac2 ~]# mount -a
[root@rac1 ~]# chown -R oracle.oinstall /u01/app/oracle/rac_archivelog/

五:修改归档路径到集群文件系统上

[oracle@rac1 ~]$ crs_stat -t -v
Name           Type           R/RA   F/FT   Target    State     Host        
----------------------------------------------------------------------
ora....SM1.asm application    0/5    0/0    ONLINE    ONLINE    rac1        
ora....C1.lsnr application    0/5    0/0    ONLINE    ONLINE    rac1        
ora.rac1.gsd   application    0/5    0/0    ONLINE    ONLINE    rac1        
ora.rac1.ons   application    0/3    0/0    ONLINE    ONLINE    rac1        
ora.rac1.vip   application    0/0    0/0    ONLINE    ONLINE    rac1        
ora....SM2.asm application    0/5    0/0    ONLINE    ONLINE    rac2        
ora....C2.lsnr application    0/5    0/0    ONLINE    ONLINE    rac2        
ora.rac2.gsd   application    0/5    0/0    ONLINE    ONLINE    rac2        
ora.rac2.ons   application    0/3    0/0    ONLINE    ONLINE    rac2        
ora.rac2.vip   application    0/0    0/0    ONLINE    ONLINE    rac2        
ora.racdb.db   application    0/0    0/1    ONLINE    ONLINE    rac1        
ora....b1.inst application    0/5    0/0    ONLINE    ONLINE    rac1        
ora....b2.inst application    0/5    0/0    ONLINE    ONLINE    rac2    

[oracle@rac1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:29:44 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     42
Next log sequence to archive   43
Current log sequence           43
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     18
Next log sequence to archive   19
Current log sequence           19

SQL> conn /as sysdba
Connected.
SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/rac_archivelog';
System altered.

SQL> conn sys/123456@racdb2 as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/rac_archivelog
Oldest online log sequence     18
Next log sequence to archive   19
Current log sequence           19
SQL> alter system archive log current;
System altered.

[root@rac2 ~]# ls /u01/app/oracle/rac_archivelog/
1_43_769205632.dbf  2_19_769205632.dbf  lost+found

六:测试数据库的恢复

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 test/hr@racdb2 
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:38:43 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> create table t2 as select * from t1;
Table created.

SQL> insert into t2 select * from t2;
1 row created.

SQL> /
2 rows created.

SQL> /
4 rows created.

SQL> commit;
Commit complete.

SQL> conn /as sysdba
Connected.
SQL> alter system archive log current;
System altered.

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

FILE_NAME
----------------------------------------
+DATA/racdb/datafile/users.259.769728851

[oracle@rac1 ~]$ srvctl stop database -d racdb -o immediate
[oracle@rac1 ~]$ export ORACLE_SID=+ASM1
[oracle@rac1 ~]$ asmcmd rm -rf +DATA/racdb/datafile/users.259.769728851

[oracle@rac1 ~]$ 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
ALTER DATABASE OPEN
This instance was first to open
Thu Dec 15 13:52:03 CST 2011
Errors in file /u01/app/oracle/admin/racdb/bdump/racdb1_dbw0_23072.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '+DATA/racdb/datafile/users.259.769728851'
ORA-17503: ksfdopn:2 Failed to open file +DATA/racdb/datafile/users.259.769728851
ORA-15012: ASM file '+DATA/racdb/datafile/users.259.769728851' does not exist
ORA-1157 signalled during: ALTER DATABASE OPEN...
Thu Dec 15 13:52:05 CST 2011
Shutting down instance (abort)
License high water mark = 1
Instance terminated by USER, pid = 23262

[oracle@rac1 ~]$ srvctl start  database -d racdb -o mount
[oracle@rac1 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Thu Dec 15 13:54:43 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: RACDB (DBID=766822397, not open)

RMAN> restore datafile 4;
RMAN> recover datafile 4;
RMAN> alter database open;
database opened
RMAN> exit

[oracle@rac1 ~]$ sqlplus sys/123456@racdb2 as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:57:18 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 name,open_mode from v$database;

NAME                        OPEN_MODE
--------------------------- ------------------------------
RACDB                       MOUNTED

SQL> alter database open;
Database altered.

SQL> select * from test.t2;

         A
----------
         1
         1
         1
         1
         1
         1
         1
         1

8 rows selected.

前面两节中介绍了rac环境下归档日志存储在ASM磁盘和集群文件系统环境下的备份和恢复操作,本节中将简要的介绍下当归档日志存储在本地文件系统环境下的备份和恢复,一般来讲,如果条件允许,应当尽可能将归档日志存储在共享存储上,或者设置多路归档日志,其中一路存储在共享存储上

一:配置归档日志存储在本地文件系统上

[root@rac1 ~]# su - oracle
[oracle@rac1 ~]$ mkdir -p /u01/app/oracle/rac1_archivelog/
[oracle@rac2 ~]$ mkdir -p /u01/app/oracle/rac2_archivelog/
[oracle@rac2 ~]$ tnsping racdb
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 18-DEC-2011 13:57:13
Copyright (c) 1997,  2010, Oracle.  All rights reserved.

Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip.yang.com)(PORT = 1521)) (ADDRESS =

(PROTOCOL = TCP)(HOST = rac2-vip.yang.com)(PORT = 1521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED)

(SERVICE_NAME = racdb.yang.com)))
OK (260 msec)

[oracle@rac2 ~]$ sqlplus sys/123456@racdb as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sun Dec 18 13:57:57 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> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/rac1_archivelog' sid='racdb1';
System altered.

SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/rac2_archivelog' sid='racdb2';
System altered.

SQL> alter system archive log current;
System altered.

[oracle@rac1 ~]$ ls /u01/app/oracle/rac1_archivelog/
1_45_769205632.dbf
[oracle@rac1 ~]$ ssh rac2 "ls /u01/app/oracle/rac2_archivelog/"
2_21_769205632.dbf

二:备份数据库

[oracle@rac2 ~]$ rman target sys/123456@racdb
Recovery Manager: Release 10.2.0.5.0 - Production on Sun Dec 18 14:01:30 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: RACDB (DBID=766822397)
System altered.

RMAN> delete noprompt backupset;
RMAN> delete noprompt copy;

RMAN> list copy;
specification does not match any archive log in the recovery catalog

RMAN> list backupset;

RMAN> backup incremental level 0
2> tag 'db_full_bak_20111218' 
3> database plus archivelog
4> delete all input;

Starting backup at 2011-12-18 14:09:05
current log archived
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup plus archivelog command at 12/18/2011 14:09:11
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /u01/app/oracle/rac1_archivelog/1_46_769205632.dbf
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

需要分配通道,否则会备份失败,这里将备份存储在闪回区内!
RMAN> run {
2> allocate channel c1 device type disk connect 
sys/123456@racdb1;
3> allocate channel c2 device type disk connect 
sys/123456@racdb2
;
4> backup incremental level 0
5> tag 'db_full_bak_20111218'
6> database plus archivelog
7> delete all input;
8> }


RMAN> list backup of database summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
16      B  0  A DISK        2011-12-18 14:16:12 1       1       NO         DB_FULL_BAK_20111218
17      B  0  A DISK        2011-12-18 14:16:39 1       1       NO         DB_FULL_BAK_20111218

[oracle@rac2 ~]$ sqlplus sys/123456@racdb as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sun Dec 18 14:30:55 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> create table test.t3 as select * from dba_source;
Table created.

SQL> select count(*) from test.t3;

  COUNT(*)
----------
    296337

SQL> alter system archive log current;
System altered.

SQL> /
System altered.

SQL> /
System altered.

SQL> select file_name from dba_data_files where tablespace_name in('SYSTEM','SYSAUX');

FILE_NAME
-----------------------------------------
+DATA/racdb/datafile/sysaux.257.769205539
+DATA/racdb/datafile/system.256.769205539

四:模拟数据库崩溃

[oracle@rac2 ~]$ srvctl stop database -d racdb -o immediate 
[oracle@rac2 ~]$ export ORACLE_SID=+ASM2
[oracle@rac2 ~]$ asmcmd rm -rf +DATA/racdb/datafile/sysaux.257.769205539
[oracle@rac2 ~]$ asmcmd rm -rf +DATA/racdb/datafile/system.256.769205539

[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@rac2 ~]$ tail -f /u01/app/oracle/admin/racdb/bdump/alert_racdb2.log 
Errors in file /u01/app/oracle/admin/racdb/bdump/racdb2_dbw0_30112.trc:
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '+DATA/racdb/datafile/sysaux.257.769205539'
ORA-17503: ksfdopn:2 Failed to open file +DATA/racdb/datafile/sysaux.257.769205539
ORA-15012: ASM file '+DATA/racdb/datafile/sysaux.257.769205539' does not exist
ORA-1157 signalled during: ALTER DATABASE OPEN...
Sun Dec 18 14:38:43 CST 2011
Shutting down instance (abort)
License high water mark = 1
Instance terminated by USER, pid = 30350

五:进行数据库恢复操作

[oracle@rac2 ~]$ srvctl start database -d racdb -o mount
[oracle@rac2 ~]$ rman target 
sys/123456@racdb

Recovery Manager: Release 10.2.0.5.0 - Production on Sun Dec 18 14:41:03 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: RACDB (DBID=766822397, not open)
RMAN> restore database;
RMAN> recover database;

Starting recover at 2011-12-18 14:45:05
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 50 is already on disk as file /u01/app/oracle/rac1_archivelog/1_50_769205632.dbf
archive log thread 1 sequence 51 is already on disk as file /u01/app/oracle/rac1_archivelog/1_51_769205632.dbf
archive log thread 1 sequence 52 is already on disk as file /u01/app/oracle/rac1_archivelog/1_52_769205632.dbf
archive log thread 1 sequence 53 is already on disk as file /u01/app/oracle/rac1_archivelog/1_53_769205632.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/18/2011 14:45:07
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 2 seq 28 lowscn 1018689 found to restore
RMAN-06025: no backup of log thread 2 seq 27 lowscn 1018577 found to restore
RMAN-06025: no backup of log thread 2 seq 26 lowscn 1016111 found to restore

这里就算定义了通道进行恢复,一样会报错如下
[oracle@rac2 ~]$ rman target 
sys/123456@racdb 
Recovery Manager: Release 10.2.0.5.0 - Production on Sun Dec 18 15:07:17 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.

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

RMAN> run {
2> allocate channel c1 device type disk connect 
sys/123456@racdb1;
3> allocate channel c2 device type disk connect 
sys/123456@racdb2
;
4> restore database;
5> recover database;
6> };

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=152 instance=racdb1 devtype=DISK

allocated channel: c2
channel c2: sid=148 instance=racdb2 devtype=DISK

Starting restore at 2011-12-18 15:07:39

skipping datafile 2; already restored to file +DATA/racdb/datafile/undotbs1.258.769205541
skipping datafile 5; already restored to file +DATA/racdb/datafile/example.264.769205649
skipping datafile 6; already restored to file +DATA/racdb/datafile/undotbs2.265.769205765
skipping datafile 1; already restored to file +DATA/racdb/datafile/system.256.770222569
skipping datafile 3; already restored to file +DATA/racdb/datafile/sysaux.257.770222575
skipping datafile 4; already restored to file +DATA/racdb/datafile/users.259.769960507
Finished restore at 2011-12-18 15:07:40

Starting recover at 2011-12-18 15:07:40

starting media recovery

archive log thread 1 sequence 50 is already on disk as file /u01/app/oracle/rac1_archivelog/1_50_769205632.dbf
archive log thread 1 sequence 51 is already on disk as file /u01/app/oracle/rac1_archivelog/1_51_769205632.dbf
archive log thread 1 sequence 52 is already on disk as file /u01/app/oracle/rac1_archivelog/1_52_769205632.dbf
archive log thread 1 sequence 53 is already on disk as file /u01/app/oracle/rac1_archivelog/1_53_769205632.dbf
released channel: c1
released channel: c2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/18/2011 15:07:42
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of log thread 2 seq 28 lowscn 1018689 found to restore
RMAN-06025: no backup of log thread 2 seq 27 lowscn 1018577 found to restore
RMAN-06025: no backup of log thread 2 seq 26 lowscn 1016111 found to restore

需要将归档日志复制到执行恢复操作的节点上,在本例中:将rac2的归档日志复制到rac1上,在rac1上面执行恢复操作
[oracle@rac2 ~]$ scp -rp /u01/app/oracle/rac2_archivelog rac1:/u01/app/oracle/
[oracle@rac1 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Mon Dec 19 11:18:58 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: RACDB (DBID=766822397, not open)

RMAN> restore database;
Starting restore at 2011-12-19 11:19:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 instance=racdb1 devtype=DISK

skipping datafile 2; already restored to file +DATA/racdb/datafile/undotbs1.258.769205541
skipping datafile 5; already restored to file +DATA/racdb/datafile/example.264.769205649
skipping datafile 6; already restored to file +DATA/racdb/datafile/undotbs2.265.769205765
skipping datafile 1; already restored to file +DATA/racdb/datafile/system.256.770222569
skipping datafile 3; already restored to file +DATA/racdb/datafile/sysaux.257.770222575
skipping datafile 4; already restored to file +DATA/racdb/datafile/users.259.769960507
restore not done; all files readonly, offline, or already restored
Finished restore at 2011-12-19 11:19:20

RMAN> recover database;
Starting recover at 2011-12-19 11:22:17
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 50 is already on disk as file /u01/app/oracle/rac1_archivelog/1_50_769205632.dbf
archive log thread 1 sequence 51 is already on disk as file /u01/app/oracle/rac1_archivelog/1_51_769205632.dbf
archive log thread 1 sequence 52 is already on disk as file /u01/app/oracle/rac1_archivelog/1_52_769205632.dbf
archive log thread 1 sequence 53 is already on disk as file /u01/app/oracle/rac1_archivelog/1_53_769205632.dbf
archive log thread 2 sequence 26 is already on disk as file /u01/app/oracle/rac2_archivelog/2_26_769205632.dbf
archive log thread 2 sequence 27 is already on disk as file /u01/app/oracle/rac2_archivelog/2_27_769205632.dbf
archive log thread 2 sequence 28 is already on disk as file /u01/app/oracle/rac2_archivelog/2_28_769205632.dbf
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=49
channel ORA_DISK_1: reading from backup piece

+FRA/racdb/backupset/2011_12_18/annnf0_db_full_bak_20111218_0.268.770221011
channel ORA_DISK_1: restored backup piece 1
piece handle=+FRA/racdb/backupset/2011_12_18/annnf0_db_full_bak_20111218_0.268.770221011 tag=DB_FULL_BAK_20111218
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/rac1_archivelog/1_49_769205632.dbf thread=1 sequence=49
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=2 sequence=25
channel ORA_DISK_1: reading from backup piece

+FRA/racdb/backupset/2011_12_18/annnf0_db_full_bak_20111218_0.269.770221009
channel ORA_DISK_1: restored backup piece 1
piece handle=+FRA/racdb/backupset/2011_12_18/annnf0_db_full_bak_20111218_0.269.770221009 tag=DB_FULL_BAK_20111218
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/rac1_archivelog/2_25_769205632.dbf thread=2 sequence=25
archive log filename=/u01/app/oracle/rac2_archivelog/2_26_769205632.dbf thread=2 sequence=26
archive log filename=/u01/app/oracle/rac1_archivelog/1_50_769205632.dbf thread=1 sequence=50
archive log filename=/u01/app/oracle/rac1_archivelog/1_51_769205632.dbf thread=1 sequence=51
archive log filename=/u01/app/oracle/rac1_archivelog/1_52_769205632.dbf thread=1 sequence=52
archive log filename=/u01/app/oracle/rac2_archivelog/2_27_769205632.dbf thread=2 sequence=27
media recovery complete, elapsed time: 00:00:24
Finished recover at 2011-12-19 11:22:45

六:验证

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

[oracle@rac1 ~]$ sqlplus sys/123456@racdb as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Mon Dec 19 11:26:12 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 count(*) from test.t3;

  COUNT(*)
----------
    296337

总结:rac环境下将归档存储在本地文件系统上的时候,执行恢复的时候,需要在执行恢复操作的节点能读取全部的归档日志,如果在生产环境下,会造成恢复时间的延长和难度的增加,可选的解决方案有NFS和多路归档以及设置standby_archive_dest


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值