Oracle RAC RMAN自动备份与恢复

Oracle 专栏收录该内容
39 篇文章 8 订阅

Oracle环境:

Oracle 11gR2 RAC

备份要求:

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

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

配置步骤:

一、配置rman自动备份:

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

具体步骤参考以下链接:

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

归档模式配置结果如下:

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';

 

4、编写脚本:

节点1:

#/bin/bash
source /home/oracle/.bash_profile
backtime=`date +%Y%m%d`
rman target /  log=/rmanbak/log/node1_backupall_$backtime.log <<EOF
run{ 
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
backup database format '/rmanbak/datafile/rac1_%d_%T_%U';
backup archivelog all format '/rmanbak/datafile/rac1_arch_%t_%s_%c' delete input;
report obsolete; 
delete noprompt  obsolete; 
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
release channel ch1;
release channel ch2;
}
EOF
echo "backup complete!"
scp /rmanbak/log/node1_backupall_$backtime.log oracle@rac2:/rmanbak/log/
exit

节点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 <<EOF
run{ 
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
backup database format '/rmanbak/datafile/rac2_%d_%T_%U';
backup archivelog all format '/rmanbak/datafile/rac2_arch_%t_%s_%c' delete input;
report obsolete; 
delete noprompt  obsolete; 
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
release channel ch1;
release channel ch2;
}
EOF
echo "backup complete!"
exit

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、备份结果如下:

二、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  

  • 7
    点赞
  • 3
    评论
  • 28
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值