10g RAC环境下的备份与恢复(三)

 前面两节中介绍了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

你可能感兴趣的:(oracle,职场,休闲)