当前位置:Gxlcms > mysql > RAC环境下的备份与恢复

RAC环境下的备份与恢复

时间:2021-07-01 10:21:17 帮助过:30人阅读

本节将简要的介绍下,rac环境下将归档日志存放到集群文件系统场景下的备份和恢复操作,集群文件系统采用oracle的ocfs2;

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

二:查看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> 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

七:验证

人气教程排行