SQL> alter system set cluster_database=false scope=spfile sid='*';
SQL> shutdown immediate
或直接关闭所有实例
$ srvctl stop database -d orcl
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter system set cluster_database=true scope=spfile sid='*';
SQL> shutdown immediate;
$ srvctl start database -d orcl
SQL> archive log list;
node1配置:
# cat /etc/exports
#说明节点二同时也挂载节点的RMAN备份目录。
/data/rman_bak db2(rw,no_root_squash)
# 手动挂载
# mount -t nfs db1:/data/rman_bak /data/rman_bak
# 配置开机自动挂载
# cat /etc/fstab
db1:/data/rman_bak /data/rman_bak nfs defaults 0 0
说明:默认7天,根据情况修改。
SQL> show parameter control;
SQL> alter system set control_file_record_keep_time=40 scope=both;
开启控制文件的自动备份,开启之后在数据库备份或者数据文件(比如添加数据文件)有修改的时候都会自动备份控制文件和spfile文件。
RMAN> configure controlfile autobackup on;
RMAN> configure retention policy to recovery window of 30 days;
确定数据库运行在归档模式,一天一次对数据库做一次备份,可以根据备份服务器上磁盘空间以及自定策略来决定存储备份的时间。
每周日 做 Level 0 级备份
每周一,二,三,四,五,六 做 Level 1 级备份
# su �C oracle
说明:可以根据实际情况创建相关目录,注意目录权限。
$ mkdir -p /u01/app/oracle/rman_bak/scripts
$ mkdir -p /data/rman_bak/data
$ mkdir -p /data/rman_bak/logs
说明: RAC的备份如果采用ASM的话,备份只在一个节点进行就可以了。也就是说这个备份存储到了其中的一个节点上了,其它节点如果采用NFS的方式也是可以实现恢复的。
$ vi /u01/app/oracle/rman_bak/scripts/rman_bak.sh
$ chmod u+x /u01/app/oracle/rman_bak/scripts/rman_bak.sh
$ 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
手动添加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';
$ 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
$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF
connect target /;
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;
}
run{
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
else
$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF
connect target /;
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;
}
run{
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
fi
$ /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0
测试注意细节:
1)观察rman log日志有无异常错误。
2)观察archivelog是否有备份与删除。