Oracle RAC RMAN自动备份与恢复

Oracle环境:

Oracle 11gR2 RAC

备份要求:

1、在节点1每晚定时进行全量备份,同时删除过期备份和归档日志文件;

2、本地节点1发生故障时,节点2可以接管备份操作,在节点2上生成全备。

配置步骤:

一、配置rman自动备份:

1、打开归档模式并修改归档路径:

具体步骤参考以下链接:

https://blog.csdn.net/xiezuoyong/article/details/82907336

归档模式配置结果如下:

Oracle RAC RMAN自动备份与恢复_第1张图片

2、创建本地rman备份存储目录:

mkdir /rmanbak
cd /rmanbak
mkdir datafile
mkdir controlfile
mkdir log
chown -R oracle:oinstall datafile
chown -R oracle:oinstall controlfile
chown -R oracle:oinstall log

3、配置rman备份参数:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/rmanbak/controlfile/%F';

 Oracle RAC RMAN自动备份与恢复_第2张图片

4、编写脚本:

节点1:

#/bin/bash
source /home/oracle/.bash_profile
backtime=`date +%Y%m%d`
rman target /  log=/rmanbak/log/node1_backupall_$backtime.log <

节点2:

#/bin/bash
source /home/oracle/.bash_profile
backtime=`date +%Y%m%d`
if [ -f /rmanbak/log/node1_backupall_$backtime.log ]
then
echo "node1 backup have been success!"
exit
else
echo "node1 backup have been filed,start node2 backup!"
fi
rman target /  log=/rmanbak/log/node2_backupall_$backtime.log <

5、给脚本设置权限:

chown -R oracle:oinstall bak.sh
chmod 744 bak.sh

6、在oracle用户下添加定时任务脚本:

节点1:

su - oracle
crontab -e
0 1 * * * /rmanbak/bak.sh >> /rmanbak/log/node1_rmanbak.log

节点2:

su - oracle
crontab -e
0 2 * * * /rmanbak/bak.sh >> /rmanbak/log/node2_rmanbak.log

重启crond服务并设置开机自启动:

service crond restart
chkconfig crond on

7、备份结果如下:

Oracle RAC RMAN自动备份与恢复_第3张图片

二、rman恢复过程:

 1、关闭两节点的数据库:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

2、 删除一个数据文件:

[grid@rac1 ~]$ asmcmd
ASMCMD> ls
CRS/
DATA/
ASMCMD> cd data
ASMCMD> ls
RACDB/
ASMCMD> cd racdb
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
archivelog/
spfileracdb.ora
ASMCMD> cd datafile
ASMCMD> ls
DB_TEST.273.987873993
SYSAUX.257.987768217
SYSAUX.261.987768549
SYSTEM.260.987768549
UNDOTBS1.258.987768219
UNDOTBS1.262.987768549
UNDOTBS2.268.987768711
USERS.259.987768219
USERS.263.987768549
db_test.dbf
ASMCMD> rm -fr SYSTEM.260.987768549
ASMCMD> ls
DB_TEST.273.987873993
SYSAUX.257.987768217
SYSAUX.261.987768549
UNDOTBS1.258.987768219
UNDOTBS1.262.987768549
UNDOTBS2.268.987768711
USERS.259.987768219
USERS.263.987768549
db_test.dbf

3、 启动数据库发现报错:

SQL> startup;
ORACLE instance started.

Total System Global Area 1653518336 bytes
Fixed Size            2213896 bytes
Variable Size         1174407160 bytes
Database Buffers      469762048 bytes
Redo Buffers            7135232 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '+DATA/racdb/datafile/system.260.987768549'

SQL> select status from v$instance;

STATUS
------------
MOUNTED

 4、进入rman模式进行恢复:

[oracle@rac1 rmanbak]$ rman target/

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Oct 8 14:31:50 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: RACDB (DBID=985385379, not open)

RMAN> restore database;

Starting restore at 08-OCT-2018 14:31:58
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=194 instance=racdb1 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to +DATA/racdb/datafile/system.260.987768549
channel ORA_DISK_1: restoring datafile 00003 to +DATA/racdb/datafile/undotbs1.262.987768549
channel ORA_DISK_1: restoring datafile 00006 to +DATA/racdb/datafile/db_test.dbf
channel ORA_DISK_1: reading from backup piece /rmanbak/datafile/rac1_RACDB_20181008_0itf5eud_1_1
channel ORA_DISK_1: piece handle=/rmanbak/datafile/rac1_RACDB_20181008_0itf5eud_1_1 tag=TAG20181008T142517
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to +DATA/racdb/datafile/sysaux.261.987768549
channel ORA_DISK_1: restoring datafile 00004 to +DATA/racdb/datafile/users.263.987768549
channel ORA_DISK_1: restoring datafile 00005 to +DATA/racdb/datafile/undotbs2.268.987768711
channel ORA_DISK_1: reading from backup piece /rmanbak/datafile/rac1_RACDB_20181008_0htf5eud_1_1
channel ORA_DISK_1: piece handle=/rmanbak/datafile/rac1_RACDB_20181008_0htf5eud_1_1 tag=TAG20181008T142517
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 08-OCT-2018 14:32:49

RMAN> recover database;

Starting recover at 08-OCT-2018 14:33:35
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 32 is already on disk as file +DATA/racdb/archivelog/1_32_987768613.dbf
archived log for thread 1 with sequence 33 is already on disk as file +DATA/racdb/archivelog/1_33_987768613.dbf
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=31
channel ORA_DISK_1: reading from backup piece /rmanbak/datafile/rac1_arch_988986348_19_1
channel ORA_DISK_1: piece handle=/rmanbak/datafile/rac1_arch_988986348_19_1 tag=TAG20181008T142548
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=+DATA/racdb/archivelog/1_31_987768613.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=40
channel ORA_DISK_1: reading from backup piece /rmanbak/datafile/rac1_arch_988986348_20_1
channel ORA_DISK_1: piece handle=/rmanbak/datafile/rac1_arch_988986348_20_1 tag=TAG20181008T142548
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished recover at 08-OCT-2018 14:33:39

5、打开数据库成功:

SQL> alter database open;

Database altered.

SQL> select status from v$instance;

STATUS
------------
OPEN

6、查看数据文件已恢复:

 ASMCMD> ls
DB_TEST.273.987873993
SYSAUX.257.987768217
SYSAUX.261.987768549
SYSTEM.260.988986719
UNDOTBS1.258.987768219
UNDOTBS1.262.987768549
UNDOTBS2.268.987768711
USERS.259.987768219
USERS.263.987768549
db_test.dbf

本文脚本参考以下博客:https://blog.csdn.net/moscot_wu/article/details/77877188  

你可能感兴趣的:(Oracle)