RAC 和 单实例数据库备份机制是一样的,有两点需要注意:
(1) RMAN 要连接到集群中的某个实例,而不是连接到整个集
(2) 备份归档日志时,必须保证在备份实例上能够访问所有实例的归档日志,否则就会报错。
(3) 不要手动设置log_archive_dest ,自动放在一起的
select * from gv$parameter b where b.name like 'log_archive_dest%'
一. RAC 归档的设置
1.1 相关理论知识
RAC 在运行的时候,每个实例都会产生归档日志,所有实例的归档日志集中在一起,才能完整地代表数据库的操作历史,此外,只有进行介质恢复(Media Recovery)时,才会用到归档日志。 进行介质恢复时,才要求在执行恢复操作的那个节点访问所有实例的归档日志。
正是因为归档日志有这些特点,所以归档位置的设计也有两种方案:
(1)各节点生成的归档放到共享存储上,这样自然可以确保每个节点都能够访问到,比如将归档存放到ORACLE的ASM,或者是第三方提供的集群文件系统中。 对于这种方法,一些集群的配置比较麻烦,而且也增加了ASM的维护,出现问题也不好处理。
(2)各节点除在本地生成归档文件外,另外向其它节点或者说执行备份的节点发送归档日志,以确保执行备份的那台节点能够访问到所有的归档文件。在这种方法中,因为ORACLE 的重做日志发送机制非常灵活,在10g版本中可以同时向10个目标地写入归档(11g增加到了30个),所以利用这种特性,将各节点生成的归档发送到执行备份的节点中,来实现该节点能够访问所需的归档文件。
在第二种方案中,我们可以在每个节点建2个归档目录,分别存放本地和其他节点节点的归档日志,这里假设是2个节点的RAC.
归档位置 | 实例1 | 实例2 |
本地磁盘 | Mkdir /rac1_arch Mkdir /rac2_arch | Mkdir /rac1_arch Mkdir /rac2_arch |
Log_archive_dest_1 | Location=’/rac1_arch’ | Location=’/rac2_arch’ |
Log_archive_dest_2 | Service=’rac2’ | Service=’rac1’ |
Standby_archive_dest | ‘/rac2_arch’ | ‘/rac1_arch’ |
在每个节点上建2个目录: /u02/rac1_arch, /u02/rac2_arch, 并赋予读写的权限:
[root@rac2 /]# mkdir /u02/rac1_arch
[root@rac2 /]# mkdir /u02/rac2_arch
[root@rac2 /]# chown oracle:oinstall /u02/*
[root@rac2 /]# chmod 777 /u02/*
1.2 RAC 设置成归档模式
RAC的归档设置和单实例归档设置差不多。 先将所有实例设置为非OPEN状态,然后在任意一个处于MOUNT状态的实例执行ALTER DATABASE命令,操作成功后,再正常启动其它实例即可。
之前整理的一篇RAC 归档切换的文档,不过和今天这个实验不太匹配,就重新在整理下。
Oracle RAC 归档 与 非归档 切换
Oracle RAC 归档 与 非归档 切换_Dave的博客-CSDN博客
1.2.1 设置归档参数
1.2.1.1 设置实例orcl1的参数:
SQL> alter system set log_archive_dest_1 = 'LOCATION=/u02/rac1_arch' scope=both sid='orcl1';
System altered.
SQL> alter system set log_archive_dest_2 = 'service=orcl2' scope=both sid='orcl1';
System altered.
SQL> alter system set standby_archive_dest = '/u02/rac2_arch' scope=both sid='orcl1';
System altered.
1.2.1.2 设置实例orcl2的参数:
SQL> alter system set log_archive_dest_1 = 'LOCATION=/u02/rac2_arch' scope=both sid='orcl2';
System altered.
SQL> alter system set log_archive_dest_2= 'SERVICE=orcl1' scope=both sid='orcl2';
System altered.
SQL> alter system set standby_archive_dest = '/u02/rac1_arch' scope=both sid='orcl2';
System altered.
1.2.1.3 在2个节点上分别验证参数的状态:
SQL> set wrap off
SQL> col dest_name format a20
SQL> select dest_name,status,error from v$archive_dest;
DEST_NAME STATUS ERROR
-------------------- --------- -------------------------------------------------
LOG_ARCHIVE_DEST_1 VALID
LOG_ARCHIVE_DEST_2 VALID
LOG_ARCHIVE_DEST_3 INACTIVE
LOG_ARCHIVE_DEST_4 INACTIVE
LOG_ARCHIVE_DEST_5 INACTIVE
LOG_ARCHIVE_DEST_6 INACTIVE
LOG_ARCHIVE_DEST_7 INACTIVE
LOG_ARCHIVE_DEST_8 INACTIVE
LOG_ARCHIVE_DEST_9 INACTIVE
LOG_ARCHIVE_DEST_10 INACTIVE
10 rows selected.
1.2.2 将RAC 切换成归档模式
1.2.2.1 修改数据库的归档模式
SQL> alter system set cluster_database=false scope=spfile sid='*';
System altered.
1.2.2.2 关闭所有实例
SQL> shutdown immediate
1.2.2.3 在任意一个实例上将数据库启动到mount状态,修改数据库归档模式
SQL> startup mount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1266392 bytes
Variable Size 117443880 bytes
Database Buffers 46137344 bytes
Redo Buffers 2924544 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter system set cluster_database=true scope=spfile sid='*';
System altered.
SQL> shutdown immediate
1.2.2.4 重启数据库,确定归档生效
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/rac1_arch
Oldest online log sequence 54
Next log sequence to archive 55
Current log sequence 55
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/rac2_arch
Oldest online log sequence 26
Next log sequence to archive 27
Current log sequence 27
1.2.2.5 在两个节点分别切换归档日志,并检查对应的目录是否产生归档日志
SQL> alter system switch logfile;
System altered.
SQL> select inst_id,recid,dest_id,name from gv$archived_log ;
INST_ID RECID DEST_ID NAME
---------- ---------- ---------- -----------------------------------------------
2 12 1 /u02/rac1_arch/1_5_730181171.dbf
2 13 2 /u01/rac1_arch1_5_730181171.dbf
2 14 2 /u02/rac2_arch/2_3_730181171.dbf
2 15 1 /u02/rac1_arch/1_6_730181171.dbf
2 16 2 /u02/rac1_arch/1_6_730181171.dbf
2 17 1 /u02/rac1_arch/1_7_730181171.dbf
……
1 12 1 /u02/rac1_arch/1_5_730181171.dbf
1 13 2 /u01/rac1_arch1_5_730181171.dbf
1 14 2 /u02/rac2_arch/2_3_730181171.dbf
1 15 1 /u02/rac1_arch/1_6_730181171.dbf
1 16 2 /u02/rac1_arch/1_6_730181171.dbf
提示:RAC 数据库各实例拥有各自的REDO线程,归档文件名的生成规则由LOG_ARCHIVE_FORMAT初始化参数控制,默认情况下是 %t_%s_%r.dbf ,所以不会导致重复的发生。
注意一个参数:LOG_ARCHIVE_LOCAL_FIRST,用来设置是否首先归档文件到本地,默认为true.
LOG_ARCHIVE_LOCAL_FIRST 这个参数是Oracle 10g 新增的,它主要针对Standby环境退出,在Oracle 10g 以前的Standby中,本地和远程的归档都完成后,联机日志文件才可以被重用,在网络速度慢的环境中,远程归档的配置会很大程度的影响节点的处理能力。而设置LOG_ARCHIVE_LOCAL_FIRST=true,Oracle 会先进行本地归档,本地归档结束后在进行远程传递,同时使联机日志可以重用,从而减少了网络环境对本地的影响。 如果把这个参数设置为FALSE, 则相当于Oracle 10g 之前的方式,这个参数默认是True,如果在应用中遇到找不到归档日志的问题,就可以把这个参数改成FALSE.
二、RAC数据库的RMAN备份
RAC 和 单实例数据库备份机制是一样的,有两点需要注意:
(1) RMAN 要连接到集群中的某个实例,而不是连接到整个集群
(2) 备份归档日志时,必须保证在备份实例上能够访问所有实例的归档日志,否则就会报错。
2.1 先看一个归档日志不一致的问题
在这种情况下备份是会报错的。 之前启动归档之后,2个节点的归档目录文件是相同的,现在我们模拟归档日志不一致的情况。
先关闭两个节点的归档位置2。 此时归档日志都不能传递到对方的归档的目录下。
SQL> alter system set log_archive_dest_state_2 =defer scope=both sid='*';
System altered.
在手动档产生归档日志:
SQL> alter system switch logfile;
System altered.
此时两个节点归档目录下文件不一致。我们连接到rac1节点,然后用rman 备份一下,看报什么错
RMAN> backup database plus archivelog;
Starting backup at 20-SEP-10
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 09/20/2010 14:13:32
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /u02/rac2_arch/2_11_730181171.dbf
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
这里报错了。 现在我们手动把缺失的日志从rac2节点copy到节点1. 然后启用归档位置2.
SQL> alter system set log_archive_dest_state_2 =enable scope=both sid='*';
System altered.
然后在备份一下看看。
RMAN> backup database plus archivelog;
Starting backup at 20-SEP-10
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=29 stamp=730213616
input archive log thread=1 sequence=15 recid=36 stamp=730217603
input archive log thread=1 sequence=16 recid=40 stamp=730221061
input archive log thread=1 sequence=17 recid=45 stamp=730222093
input archive log thread=2 sequence=1 recid=3 stamp=730194853
input archive log thread=2 sequence=2 recid=4 stamp=730194856
input archive log thread=2 sequence=3 recid=14 stamp=730195685
input archive log thread=2 sequence=4 recid=20 stamp=730196124
input archive log thread=2 sequence=5 recid=23 stamp=730204019
input archive log thread=2 sequence=6 recid=25 stamp=730205106
input archive log thread=2 sequence=7 recid=27 stamp=730206847
input archive log thread=2 sequence=8 recid=28 stamp=730213614
input archive log thread=2 sequence=11 recid=37 stamp=730217603
input archive log thread=2 sequence=12 recid=41 stamp=730221072
input archive log thread=2 sequence=13 recid=44 stamp=730222092
channel ORA_DISK_1: starting piece 1 at 20-SEP-10
channel ORA_DISK_1: finished piece 1 at 20-SEP-10
piece handle=+FLASH_RECOVERY_AREA/orcl/backupset/2010_09_20/annnf0_tag20100920t152820_0.265.730222103 tag=TAG20100920T152820 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:37
Finished backup at 20-SEP-10
Starting backup at 20-SEP-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=+DATA/orcl/datafile/system.276.730181051
input datafile fno=00003 name=+DATA/orcl/datafile/sysaux.277.730181053
input datafile fno=00002 name=+DATA/orcl/datafile/undotbs1.278.730181053
input datafile fno=00005 name=+DATA/orcl/datafile/undotbs2.284.730181347
input datafile fno=00004 name=+DATA/orcl/datafile/users.279.730181053
channel ORA_DISK_1: starting piece 1 at 20-SEP-10
channel ORA_DISK_1: finished piece 1 at 20-SEP-10
piece handle=+FLASH_RECOVERY_AREA/orcl/backupset/2010_09_20/nnndf0_tag20100920t152900_0.266.730222143 tag=TAG20100920T152900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:28
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 20-SEP-10
channel ORA_DISK_1: finished piece 1 at 20-SEP-10
piece handle=+FLASH_RECOVERY_AREA/orcl/backupset/2010_09_20/ncsnf0_tag20100920t152900_0.267.730222301 tag=TAG20100920T152900 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 20-SEP-10
Starting backup at 20-SEP-10
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=18 recid=49 stamp=730222306
input archive log thread=2 sequence=14 recid=48 stamp=730222306
channel ORA_DISK_1: starting piece 1 at 20-SEP-10
channel ORA_DISK_1: finished piece 1 at 20-SEP-10
piece handle=+FLASH_RECOVERY_AREA/orcl/backupset/2010_09_20/annnf0_tag20100920t153150_0.268.730222313 tag=TAG20100920T153150 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 20-SEP-10
RMAN>
2.2 归档文件的删除问题
在上面备份成功后,这里有一个新问题,就是对归档文件的删除。通常我们习惯于在备份完归档之后删除原归档文件,以释放相应的磁盘空间,不过在RAC环境下,只能删除节点1上的归档文件,节点2上的无法删除。因为在节点1上操作不了节点2上的归档文件。
这个问题我们可以通过配置通道来解决。一般有几个实例,我们就配置几个通道。 配置通道命令如下:
RMAN> configure channel 1 device type disk connect 'sys/oracle@orcl1';
new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK CONNECT 'sys/oracle@orcl1';
new RMAN configuration parameters are successfully stored
RMAN> configure channel 2 device type disk connect 'sys/oracle@orcl2';
new RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK CONNECT 'sys/oracle@orcl2';
new RMAN configuration parameters are successfully stored
RMAN>
查看通道情况:
RMAN> show channel;
RMAN configuration parameters are:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK CONNECT 'sys/oracle@orcl1';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK CONNECT 'sys/oracle@orcl2';
关于RMAN 通道,在我blog:
RMAN 系列(二) ---- RMAN 设置和配置
RMAN 系列(二) ---- RMAN 设置和配置_Dave的博客-CSDN博客
中的3.4节: 配置RMAN默认设置 中有介绍。
这样设置通道除了能删除其他节点的归档日志外, RMAN还能够智能的对备份中出现"问题"的任务进行再分配,比如说通道1和通道2同时执行备份,其中通道1备份数据文件1,3,4,通道2备份数据文件2和5,假如通道2执行过程中由于某些原因崩溃,RMAN可以自动将任务放回到通道1上执行。
刚才已经配置过2个不同的通道,现在我们来删除归档文件试试:
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=130 instance=orcl1 devtype=DISK
validation failed for archived log
archive log filename=/u02/rac1_arch/1_16_730181171.dbf recid=38 stamp=730221051
validation failed for archived log
archive log filename=/u02/rac1_arch/1_17_730181171.dbf recid=42 stamp=730222091
validation failed for archived log
archive log filename=/u02/rac1_arch/1_18_730181171.dbf recid=46 stamp=730222305
validation failed for archived log
archive log filename=/u02/rac2_arch/2_1_730181171.dbf recid=1 stamp=730194852
validation failed for archived log
archive log filename=/u02/rac2_arch/2_2_730181171.dbf recid=4 stamp=730194856
validation failed for archived log
archive log filename=/u02/rac2_arch/2_3_730181171.dbf recid=11 stamp=730195680
validation failed for archived log
archive log filename=/u02/rac2_arch/2_4_730181171.dbf recid=19 stamp=730196123
validation failed for archived log
archive log filename=/u02/rac2_arch/2_12_730181171.dbf recid=39 stamp=730221056
validation failed for archived log
archive log filename=/u02/rac2_arch/2_13_730181171.dbf recid=43 stamp=730222091
validation failed for archived log
archive log filename=/u02/rac2_arch/2_14_730181171.dbf recid=47 stamp=730222304
Crosschecked 10 objects
RMAN> delete archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=130 instance=orcl1 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
38 1 16 X 20-SEP-10 /u02/rac1_arch/1_16_730181171.dbf
42 1 17 X 20-SEP-10 /u02/rac1_arch/1_17_730181171.dbf
46 1 18 X 20-SEP-10 /u02/rac1_arch/1_18_730181171.dbf
1 2 1 X 20-SEP-10 /u02/rac2_arch/2_1_730181171.dbf
4 2 2 X 20-SEP-10 /u02/rac2_arch/2_2_730181171.dbf
11 2 3 X 20-SEP-10 /u02/rac2_arch/2_3_730181171.dbf
19 2 4 X 20-SEP-10 /u02/rac2_arch/2_4_730181171.dbf
39 2 12 X 20-SEP-10 /u02/rac2_arch/2_12_730181171.dbf
43 2 13 X 20-SEP-10 /u02/rac2_arch/2_13_730181171.dbf
47 2 14 X 20-SEP-10 /u02/rac2_arch/2_14_730181171.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/u02/rac1_arch/1_16_730181171.dbf recid=38 stamp=730221051
deleted archive log
archive log filename=/u02/rac1_arch/1_17_730181171.dbf recid=42 stamp=730222091
deleted archive log
archive log filename=/u02/rac1_arch/1_18_730181171.dbf recid=46 stamp=730222305
deleted archive log
archive log filename=/u02/rac2_arch/2_1_730181171.dbf recid=1 stamp=730194852
deleted archive log
archive log filename=/u02/rac2_arch/2_2_730181171.dbf recid=4 stamp=730194856
deleted archive log
archive log filename=/u02/rac2_arch/2_3_730181171.dbf recid=11 stamp=730195680
deleted archive log
archive log filename=/u02/rac2_arch/2_4_730181171.dbf recid=19 stamp=730196123
deleted archive log
archive log filename=/u02/rac2_arch/2_12_730181171.dbf recid=39 stamp=730221056
deleted archive log
archive log filename=/u02/rac2_arch/2_13_730181171.dbf recid=43 stamp=730222091
deleted archive log
archive log filename=/u02/rac2_arch/2_14_730181171.dbf recid=47 stamp=730222304
Deleted 10 objects
2.3 RMAN 备份的一个完整实例
关于搭建RMAN 备份平台的其他相关操作参考Blog:
如何 搭建 RMAN 备份平台
如何 搭建 RMAN 备份平台_Dave的博客-CSDN博客
RMAN 备份的脚本参考Blog:
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本_Dave的博客-CSDN博客
这里我们用nocatalog 模式下的全备备份为例,在运行这个脚本之前需要配置好归档。 具体参考前面的说明。
Shell 脚本如下:
########################################################################
## RAC_hot_database_backup.sh ##
## created by Tianlesoftware ##
## 2010-9-21 ##
#########################################################################
#!/bin/sh
# ---------------------------------------------------------------------------
# Determine the user which is executing this script.
# ---------------------------------------------------------------------------
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
# ---------------------------------------------------------------------------
# Put output in <this file name>.out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------
RMAN_LOG_FILE=${0}.out
# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
# -----------------------------------------------------------------
# Initialize the log file.
# -----------------------------------------------------------------
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Log the start of this script.
# ---------------------------------------------------------------------------
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Oracle home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
ORACLE_SID=orcl1 -- 注意,这里需要连接任意节点就可以
export ORACLE_SID
# ---------------------------------------------------------------------------
# The Oracle DBA user id (account).
# ---------------------------------------------------------------------------
ORACLE_USER=oracle
export ORACLE_USER
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------
#echo >> $RMAN_LOG_FILE
#echo "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
#echo "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
#echo "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
#echo "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
#echo "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# NOTE: This script assumes that the database is properly opened. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup.
# ---------------------------------------------------------------------------
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog target sys/oracle msglog $RMAN_LOG_FILE append << EOF
RUN {
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';
release channel c1;
release channel c2;
}
allocate channel for maintenance device type disk connect 'sys/oracle@orcl1';
allocate channel for maintenance device type disk connect 'sys/oracle@orcl2';
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
release channel;
#EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
/bin/mailx -s "RMAN Backup SID " tianlesoftware@vip.qq.com < $RMAN_LOG_FILE
exit $RSTAT
脚本中有指定备份文件的位置。 这里要注意,如果是直接备份到硬盘上,那么在两个节点上都要创建对应的备份目录。 因为节点1通道的备份文件会放在节点1上。节点2的备份文件会放在节点2上。 这种把备份文件分开存放,当然不方便我们恢复。
开始在这个问题上,也是碰了钉子,后来才弄明白:
RAC RMAN 备份 RMAN-03009 ORA-19504 channel c3 not allocated 错误分析
RAC RMAN 备份 RMAN-03009 ORA-19504 ORA-27040 RMAN-06012 channel c3 not allocated 错误分析_Dave的博客-CSDN博客
所以,我们可以通过NFS mount 把备份文件放在一个节点。 或者直接把备份文件直接存放在存储上。
关于NFS mount的配置,参考我的Blog:
Linux NFS 和 Samba 共享配置
Linux NFS 和 Samba 共享配置_Dave的博客-CSDN博客
这里只是测试,所以采用的是NFS方式。 当然在实际RAC环境下,是放在存储上的。
这里面有2个注意事项:
1. 执行恢复的节点要能看到所有节点的归档文件。 这个在RAC 备份那篇里已经讲了方法,就是把归档文件传送到其他节点,这样就能够看到所有节点的归档文件了。
2. 备份集的存放问题。 如果我们放在共享设备上,那么节点可以访问所有的备份文件,那么就可以直接进行恢复操作。 如果不是放在共享设备,可以通过NFS mount来挂载,或者设置2个通道。 分别指向多个实例。
示例:
1.1 先停止数据库
[oracle@rac1 bin]$ srvctl stop db -d orcl
[oracle@rac1 bin]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.orcl.db application OFFLINE OFFLINE
ora....oltp.cs application OFFLINE OFFLINE
ora....cl1.srv application OFFLINE OFFLINE
ora....cl2.srv application OFFLINE OFFLINE
ora....l1.inst application OFFLINE OFFLINE
ora....l2.inst application OFFLINE OFFLINE
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
1.2 将节点启动到mount 状态:
备份集存在在2个节点的情况(2个节点的RAC),在这种情况下,需要分配2个通道分别连接对应的节点。 每个节点都需要启动到mount状态。 因为每个节点都有备份文件,所以在每个节点都需要执行restore,如果没有启动的话,就会报错,对于备份集存放在共享设备的就不用这么麻烦。
[oracle@rac1 bin]$ export ORACLE_SID=orcl1
[oracle@rac1 bin]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Sep 27 02:56:55 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup mount;
Oracle instance started
database mounted
Total System Global Area 180355072 bytes
Fixed Size 1218388 bytes
Variable Size 100665516 bytes
Database Buffers 75497472 bytes
Redo Buffers 2973696 bytes
[oracle@rac2 bin]$ export ORACLE_SID=orcl2
[oracle@rac2 bin]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Sep 27 02:57:44 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup mount;
Oracle instance started
database mounted
Total System Global Area 180355072 bytes
Fixed Size 1218388 bytes
Variable Size 83888300 bytes
Database Buffers 92274688 bytes
Redo Buffers 2973696 bytes
1.3 完全恢复
在任意一个节点上执行:
RMAN> RUN {
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
restore database;
recover database;
}
2> 3> 4> 5> 6>
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=146 instance=orcl1 devtype=DISK
allocated channel: c2
channel c2: sid=146 instance=orcl2 devtype=DISK
Starting restore at 27-SEP-10
skipping datafile 2; already restored to file +DATA/orcl/datafile/undotbs1.278.730181053
skipping datafile 3; already restored to file +DATA/orcl/datafile/sysaux.277.730181053
skipping datafile 5; already restored to file +DATA/orcl/datafile/undotbs2.284.730181347
skipping datafile 1; already restored to file +DATA/orcl/datafile/system.276.730181051
skipping datafile 4; already restored to file +DATA/orcl/datafile/users.279.730181053
skipping datafile 7; already restored to file +DATA/orcl/datafile/anhuianqing.dbf
Finished restore at 27-SEP-10
Starting recover at 27-SEP-10
starting media recovery
media recovery complete, elapsed time: 00:00:04
Finished recover at 27-SEP-10
released channel: c1
released channel: c2
RMAN> sql 'alter database open';
sql statement: alter database open
1.4 不完全恢复
1.4.1基于时间点的恢复
RMAN> RUN {
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
set until time "to_date('2010/9/27 03:30:00','yyyy/mm/dd hh24:mi:ss')";
restore database;
recover database;
}
2> 3> 4> 5> 6> 7> 8>
allocated channel: c1
channel c1: sid=143 instance=orcl1 devtype=DISK
allocated channel: c2
channel c2: sid=146 instance=orcl2 devtype=DISK
executing command: SET until clause
Starting restore at 27-SEP-10
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/orcl/datafile/system.276.730181051
restoring datafile 00004 to +DATA/orcl/datafile/users.279.730181053
restoring datafile 00007 to +DATA/orcl/datafile/anhuianqing.dbf
channel c1: reading from backup piece /u01/backup/orcl_2blotmnp_1_1_20100927
channel c2: starting datafile backupset restore -- 这里使用了2个通道,因为这个测试的备份集是放在2个节点的。
channel c2: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +DATA/orcl/datafile/undotbs1.278.730181053
restoring datafile 00003 to +DATA/orcl/datafile/sysaux.277.730181053
restoring datafile 00005 to +DATA/orcl/datafile/undotbs2.284.730181347
channel c2: reading from backup piece /u01/backup/orcl_2clotmno_1_1_20100927
channel c2: restored backup piece 1
piece handle=/u01/backup/orcl_2clotmno_1_1_20100927 tag=ORCL_HOT_DB_BK
channel c2: restore complete, elapsed time: 00:01:21
channel c1: restored backup piece 1
piece handle=/u01/backup/orcl_2blotmnp_1_1_20100927 tag=ORCL_HOT_DB_BK
channel c1: restore complete, elapsed time: 00:02:48
Finished restore at 27-SEP-10
Starting recover at 27-SEP-10
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 27-SEP-10
released channel: c1
released channel: c2
RMAN>
恢复完成之后,在两个节点执行:
alter database open resetlogs;
打开数据即可。
1.4.2 基于SCN的恢复
当前SCN 查看方法:
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
1118216
RMAN> RUN {
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
restore database until scn 1118215 ;
recover database until scn 1118215 ;
}
2> 3> 4> 5> 6>
using target database control file instead of recovery catalog -- 非catalog 模式, 这种模式备份控制文件非常重要
allocated channel: c1
channel c1: sid=142 instance=orcl1 devtype=DISK
allocated channel: c2
channel c2: sid=151 instance=orcl2 devtype=DISK
Starting restore at 27-SEP-10
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/orcl/datafile/system.276.730181051
restoring datafile 00004 to +DATA/orcl/datafile/users.279.730181053
restoring datafile 00007 to +DATA/orcl/datafile/anhuianqing.dbf
channel c1: reading from backup piece /u01/backup/orcl_2blotmnp_1_1_20100927
channel c2: starting datafile backupset restore
channel c2: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +DATA/orcl/datafile/undotbs1.278.730181053
restoring datafile 00003 to +DATA/orcl/datafile/sysaux.277.730181053
restoring datafile 00005 to +DATA/orcl/datafile/undotbs2.284.730181347
channel c2: reading from backup piece /u01/backup/orcl_2clotmno_1_1_20100927
channel c2: restored backup piece 1
piece handle=/u01/backup/orcl_2clotmno_1_1_20100927 tag=ORCL_HOT_DB_BK
channel c2: restore complete, elapsed time: 00:03:58
channel c1: restored backup piece 1
piece handle=/u01/backup/orcl_2blotmnp_1_1_20100927 tag=ORCL_HOT_DB_BK
channel c1: restore complete, elapsed time: 00:05:47
Finished restore at 27-SEP-10
Starting recover at 27-SEP-10
starting media recovery
archive log thread 1 sequence 44 is already on disk as file /u02/rac1_arch/1_44_730181171.dbf
archive log thread 2 sequence 38 is already on disk as file /u02/rac1_arch/2_38_730181171.dbf
archive log thread 1 sequence 1 is already on disk as file /u02/rac1_arch/1_1_730784806.dbf
archive log thread 2 sequence 1 is already on disk as file /u02/rac2_arch/2_1_730784806.dbf
archive log filename=/u02/rac1_arch/1_44_730181171.dbf thread=1 sequence=44
archive log filename=/u02/rac1_arch/2_38_730181171.dbf thread=2 sequence=38
archive log filename=/u02/rac2_arch/2_1_730784806.dbf thread=2 sequence=1
media recovery complete, elapsed time: 00:00:09
Finished recover at 27-SEP-10
released channel: c1
released channel: c2
恢复结束,用 alter database open resetlogs 打开数据库。
-----
RAC RMAN 备份 RMAN-03009 ORA-19504 ORA-27040 RMAN-06012 channel c3 not allocated 错误分析
Dave
于 2010-09-22 18:57:00 发布
12230
收藏 1
分类专栏: Oracle Troubleshooting Oracle RAC oracle常见故障解决方案 文章标签: c oracle file command delete
版权
Oracle Troubleshooting
同时被 3 个专栏收录
193 篇文章3 订阅
订阅专栏
Oracle RAC
111 篇文章1 订阅
订阅专栏
oracle常见故障解决方案
113 篇文章131 订阅
订阅专栏
把之前的RMAN 单实例的备份脚本修改了一下,用来备份RAC 系统。
Linux 平台下 RMAN 全备 和 增量备份 shell 脚本
http://www.cndba.cn/Dave/article/1060
修改之后的备份Shell 脚本如下:
########################################################################
## RAC_hot_database_backup.sh ##
## created by Tianlesoftware ##
## 2010-9-21 ##
#########################################################################
#!/bin/sh
# ---------------------------------------------------------------------------
# Determine the user which is executing this script.
# ---------------------------------------------------------------------------
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
# ---------------------------------------------------------------------------
# Put output in <this file name>.out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------
RMAN_LOG_FILE=${0}.out
# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
# -----------------------------------------------------------------
# Initialize the log file.
# -----------------------------------------------------------------
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Log the start of this script.
# ---------------------------------------------------------------------------
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Oracle home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
ORACLE_SID=orcl1 -- 注意,这里需要连接任意节点就可以
export ORACLE_SID
# ---------------------------------------------------------------------------
# The Oracle DBA user id (account).
# ---------------------------------------------------------------------------
ORACLE_USER=oracle
export ORACLE_USER
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------
#echo >> $RMAN_LOG_FILE
#echo "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
#echo "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
#echo "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
#echo "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
#echo "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# NOTE: This script assumes that the database is properly opened. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup.
# ---------------------------------------------------------------------------
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog target sys/oracle msglog $RMAN_LOG_FILE append << EOF
RUN {
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';
release channel c1;
release channel c2;
}
allocate channel for maintenance device type disk connect 'sys/oracle@orcl1';
allocate channel for maintenance device type disk connect 'sys/oracle@orcl2';
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
release channel;
#EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
/bin/mailx -s "RMAN Backup SID " tianlesoftware@vip.qq.com < $RMAN_LOG_FILE
exit $RSTAT
但是,运行该备份脚本报错。 部分运行日志如下:
…
allocated channel: c1
channel c1: sid=129 instance=orcl1 devtype=DISK
allocated channel: c3
channel c3: sid=131 instance=orcl2 devtype=DISK
Starting backup at 22-SEP-10
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00001 name=+DATA/orcl/datafile/system.276.730181051
input datafile fno=00004 name=+DATA/orcl/datafile/users.279.730181053
channel c1: starting piece 1 at 22-SEP-10
channel c3: starting full datafile backupset
channel c3: specifying datafile(s) in backupset
input datafile fno=00003 name=+DATA/orcl/datafile/sysaux.277.730181053
input datafile fno=00002 name=+DATA/orcl/datafile/undotbs1.278.730181053
input datafile fno=00005 name=+DATA/orcl/datafile/undotbs2.284.730181347
channel c3: starting piece 1 at 22-SEP-10
RMAN-03009: failure of backup command on c3 channel at 09/22/2010 05:11:10
ORA-19504: failed to create file "/u01/backup/orcl_19logo39_1_1_20100922"
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
channel c3 disabled, job failed on it will be run on another channel
channel c1: finished piece 1 at 22-SEP-10
piece handle=/u01/backup/orcl_18logo39_1_1_20100922 tag=ORCL_HOT_DB_BK comment=N
ONE
channel c1: backup set complete, elapsed time: 00:01:02
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00003 name=+DATA/orcl/datafile/sysaux.277.730181053
input datafile fno=00002 name=+DATA/orcl/datafile/undotbs1.278.730181053
input datafile fno=00005 name=+DATA/orcl/datafile/undotbs2.284.730181347
channel c1: starting piece 1 at 22-SEP-10
channel c1: finished piece 1 at 22-SEP-10
piece handle=/u01/backup/orcl_1alogo57_1_1_20100922 tag=ORCL_HOT_DB_BK comment=N
ONE
...
released channel: c1
released channel: c3
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of release command at 09/22/2010 05:14:03
RMAN-06012: channel: c3 not allocated
对这个错误的分析过程如下:
1. 日志有c3 通道不能释放的问题。
C3 通道是节点2上的通道,非本地通道。 怀疑是这个地方有问题,单独做一个简单的测试:
RMAN> run
{
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
delete expired archivelog all;
release channel c1;
release channel c2;
}
2> 3> 4> 5> 6> 7> 8>
allocated channel: c2
channel c2: sid=147 instance=orcl2 devtype=DISK
allocated channel: c1
channel c1: sid=147 instance=orcl1 devtype=DISK
specification does not match any archive log in the recovery catalog
released channel: c1
released channel: c2
这个实验结果证明,报错和通道没有关系。
2. 备份目录的权限问题
allocated channel: c3
channel c3: sid=131 instance=orcl2 devtype=DISK
RMAN-03009: failure of backup command on c3 channel at 09/22/2010 05:11:10
ORA-19504: failed to create file "/u01/backup/orcl_19logo39_1_1_20100922"
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
channel c3 disabled, job failed on it will be run on another channel
从这里我们可以看出,通道c3 是创建成功了的。 但是在通道上c3上不能创建备份集的文件。
因为我实在节点1上做的RMAN 备份。 开始以为全部的备份文件都会放在节点1上。 所以只在节点1上创建了备份目录。 即/u01/backup目录。 在节点2上没有创建。 问题就出在这个地方。 我在就节点2上创建了/u01/backup目录,并赋予了777权限后,备份成功。
最后检查2个备份文件。 发现一个问题orcl1通道的备份集文件会存放在节点1的备份目录上(/u01/backup),orcl2通道的备份文件会放在orcl2的备份目录上(/u01/backup). 因为它的备份文件存放在2个地方,所以恢复的时候会很麻烦。 最理解的状态,是所有的备份文件都存放在一个节点,或者共享设备上。
所以,要解决这个有2种方法:
(1) 使用NFS。 在一个节点上共享备份目录,在另一个节点挂载这个共享。 这个所有的文件就会在一个节点上了。
关于NFS 的配置,参考Blog:
Linux NFS 和 Samba 共享配置
http://www.cndba.cn/Dave/article/682
(2) 使用存储。
对于NFS mount, 存在着一个比较严重的问题。就是NFS mount在一个节点没有启动的情况下,会极大的影响另一个节点的性能。也就是说,如果RAC一个节点出现故障,导致机器无法正常启动的话,另一个节点不但要承担全部的数据库压力,而且还会受到nfs mount带来的性能负载,基本上导致这个节点无法正常工作。所以从性能上的考虑,使用NFS mount的时候一定要慎重。所以对于RAC 的RMAN 备份文件,最好还是存放在存储上。
————————————————
版权声明:本文为CSDN博主「Dave」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tianlesoftware/article/details/5901031