一、将RAC切换成归档模式
1. 修改数据库的归档模式,通常在安装RAC的时候都会配置归档并且使用闪回区,已经配置过归档下面的方式可以略过。
SQL> alter system set cluster_database=false scope=spfile sid='*';
2. 关闭所有实例(两边都要shutdown)
SQL> shutdown immediate
或直接关闭所有实例
$ srvctl stop database -d orcl
3. 在任意一个实例上将数据库启动到mount状态,修改数据库归档模式
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter system set cluster_database=true scope=spfile sid='*';
SQL> shutdown immediate;
4. 启动所有实例
$ srvctl start database -d orcl
5. 验证归档模式开启
SQL> archive log list;
二、配置NFS共享目录,用于存储RMAN备份数据
1. 配置nfs服务,确保备份目录两边都可以访问,这里测试,使用节点1提供nfs服务。
node1配置:
# cat /etc/exports
#说明节点二同时也挂载节点的RMAN备份目录。
/data/rman_bak db2(rw,no_root_squash)
2. node2配置,节点2做为nfs客户端挂载,两目录保持一致。
# 手动挂载
# mount -t nfs db1:/data/rman_bak /data/rman_bak
# 配置开机自动挂载
# cat /etc/fstab
db1:/data/rman_bak /data/rman_bak nfs defaults 0 0
三、Oracle 11g RAC数据库参数修改
1. 修改控制文件的保存备份时间
说明:默认7天,根据情况修改。
SQL> show parameter control;
SQL> alter system set control_file_record_keep_time=40 scope=both;
2. RMAN 配置参数
开启控制文件的自动备份,开启之后在数据库备份或者数据文件(比如添加数据文件)有修改的时候都会自动备份控制文件和spfile文件。
RMAN> configure controlfile autobackup on;
RMAN> configure retention policy to recovery window of 30 days;
3. 备份策略
确定数据库运行在归档模式,一天一次对数据库做一次备份,可以根据备份服务器上磁盘空间以及自定策略来决定存储备份的时间。
每周日 做 Level 0 级备份
每周一,二,三,四,五,六 做 Level 1 级备份
四、 RMAN备份脚本配置
1. 准备目录
# su – oracle
说明:可以根据实际情况创建相关目录,注意目录权限。
$ mkdir -p /u01/app/oracle/rman_bak/scripts
$ mkdir -p /data/rman_bak/data
$ mkdir -p /data/rman_bak/logs
说明: RAC的备份如果采用ASM的话,备份只在一个节点进行就可以了。也就是说这个备份存储到了其中的一个节点上了,其它节点如果采用NFS的方式也是可以实现恢复的。
2. 创建脚本内容
$ vi /u01/app/oracle/rman_bak/scripts/rman_bak.sh
$ chmod u+x /u01/app/oracle/rman_bak/scripts/rman_bak.sh
3. 添加计划任务
$ crontab -e
# RMAN
00 1 * * 0 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0
00 1 * * 1,2,3,4,5,6 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 1
4. 手动测试通道
手动添加db1,db2本地服务名配置,11g rac默认只有scan ip的服务器,本地服务名需要手动添加如下:
# su - oracle
$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = scan-cluster)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db1-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(INSTANCE_NAME = orcl1)
)
)
ORCL2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db2-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(INSTANCE_NAME = orcl2)
)
)
手动测试通道
rman target /
configure channel 1 device type disk connect 'sys/oracle123@orcl1';
configure channel 2 device type disk connect 'sys/oracle123@orcl2';
4. 脚本步署方案
$ vi /u01/app/oracle/rman_bak/scripts/rman_bak.sh
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl1
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
LEVEL=$@
DATE=`date +%w`
DATE_2=`date +%Y%m%d`
BACKUP_PATH="/data/rman_bak"
BIN=$ORACLE_HOME/bin
if [ $# != 1 ]; then
echo "usage: rman_bak.sh n
where n is the rman backup level(Only 0,1 is permitted)."
exit 1
fi
if [ $@ -ne 0 -a $@ -ne 1 ]; then
echo "usage: rman_bak.sh n
where n is the rman backup level(Only 0,1 is permitted)."
exit 2
fi
if [[ $LEVEL = 0 ]]; then connect target /; run{ else $BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log < connect target /; run{ exit; fi $ /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0 测试注意细节: 1)观察rman log日志有无异常错误。
$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <
run{
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
crosscheck backupset of archivelog all;
backup archivelog all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T' delete all input;
delete noprompt expired backupset of archivelog all;
release channel c1;
release channel c2;
}
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
crosscheck backupset of database;
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T';
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';
delete noprompt expired backupset of database;
delete noprompt obsolete;
release channel c1;
release channel c2;
}
exit;
EOF
run{
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
crosscheck backupset of archivelog all;
backup archivelog all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T' delete all input;
delete noprompt expired backupset of archivelog all;
release channel c1;
release channel c2;
}
allocate channel c1 device type disk connect 'sys/oracle@orcl1';
allocate channel c2 device type disk connect 'sys/oracle@orcl2';
crosscheck backupset of database ;
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T';
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';
delete noprompt expired backupset of database ;
delete noprompt obsolete ;
release channel c1;
release channel c2;
}
EOF5. 手动执行测试
2)观察archivelog是否有备份与删除。