转 RMAN: RAC Backup, Restore and Recovery using RMAN
PURPOSE
The purpose of this document is to give a quick guide for using RMAN on RAC databases. We will follow this points:
1. Verify the database mode and archive destination.
2. Verify connectivity using sqlnet for target and catalog.
3. Determine the backup device.
4. Understand how to create an RMAN persistent configuration for a RAC env.
5. Create backups to disk using the new persistent configuration parameters.
6. Backupset maintenance using the configured retention policy.
7. Restore and Recover
a. Complete
b. Incomplete
8. Review and understand the impact of resetlogs on the catalog.
9. RMAN Sample Commands.
SCOPE
- This discussion is for a 2-node Oracle RAC Cluster.
- The logs are being archived to their respective node.
- We are allocating channels to each node to enable the autolocate feature of RMAN in a RAC env.
DETAILS
1. Verify the databases are in archivelog mode and archive destination.
a. NODE 1: thread 1
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/app/oracle/product/11.2.0/dbs/arch
Oldest online log sequence 20
Next log sequence to archive 21
Current log sequence 21
b. NODE 2: thread 2
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/app/oracle/product/11.2.0/dbs/arch
Oldest online log sequence 8
Next log sequence to archive 9
Current log sequence 9
2. Verify connectivity to the target nodes and catalog if used.
$ sqlplus /nolog
SQL> connect sys/pwd@node1 as sysdba
SQL> connect sys/pwd@node2 as sysdba
SQL> connect rman/rman@rcat
3. Set your testing areas.
Testing HOME for logs: /u02/home/usupport/rman
Backups HOME Location: /rman/V112
4. Connect using RMAN to verify and set the controlfile persistent configuration.
* Always note the target DBID
connected to target database: V112 (DBID=228033884)
* Default Configuration
RMAN> SHOW ALL;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u02/app/oracle/product/11.2.0/dbs/snapcf_V11201.f'; # default
* Configuring Channels to Use a Specific Node
To configure one RMAN channel for each policy-managed Oracle RAC database instance, use the following syntax:
CONFIGURE CHANNEL DEVICE TYPE disk CONNECT 'SYS/RAC@NODE1';'
CONFIGURE CHANNEL DEVICE TYPE disk CONNECT ''SYS/RAC@NODE2';
* Configure parallelism and use dynamic channel allocation. Review the following for details:
How To Use RMAN Dynamic Channel Allocation For RAC Environments (Note 1100443.1)
* Make changes to other configurations to fit your business requirements. Review the following for details:
Getting Started with Recovery Manager (RMAN) Note 360416.1
In 11.2, there is a new requirement for snapshot controlfile to reside on a shared location, see:
In RAC environment from 11.2 onwards Backup Or Snapshot controlfile needs to be in shared location Note 1472171.1
5. Make a backup using the new persistent configuration parameters.
BACKUP INCREMENTAL LEVEL 0 FORMAT '/rman/V112/%d_LVL0_%T_%u_s%s_p%p' DATABASE;
BACKUP ARCHIVELOG ALL FORMAT '/rman/V112/%d_AL_%T_%u_s%s_p%p'DELETE INPUT;
* Backup again using differential incremental level 1
BACKUP INCREMENTAL LEVEL 1 FORMAT '/rman/V112/%d_LVL1_%T_%u_s%s_p%p' DATABASE;
BACKUP ARCHIVELOG ALL FORMAT '/rman/V112/%d_AL_%T_%u_s%s_p%p' DELETE INPUT;
* To simplify this you can also use PLUS ARCHIVELOG
BACKUP INCREMENTAL LEVEL 0 FORMAT '/rman/V112/%d_LVL0_%T_%u_s%s_p%p'
DATABASE PLUS ARCHIVELOG FORMAT '/rman/V112/%d_AL_%T_%u_s%s_p%p' DELETE INPUT;
This uses a different algorithm than backup database and backup archivelog in separate commands, the algorithm for PLUS ARCHIVELOG is:
1. Archive log current
2. Backup archived logs
3. Backup database level 0
4. Archive log current
5. Backup any remaining archived log created during backup
6. Backupset maintenance using the configured retention policy
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST BACKUP BY DATAFILE;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF ARCHIVELOG ALL;
RMAN> LIST BACKUP OF CONTROLFILE;
These above can be enhanced with the "until time" clause as well as the archivelog backups using "not backed up x times" to cut down on many copies of a log in several backup sets.
Then continuing with SMR Server Managed Recovery use the change archivelog from...until...delete to remove old logs no longer needed on disk.
To check/delete obsolete backups or archivelogs we use:
RMAN> REPORT OBSOLETE;
RMAN> DELETE OBSOLETE;
or
RMAN> DELETE NOPROMPT OBSOLETE;
To check the database files:
RMAN> REPORT SCHEMA;
7. Restore and Recover
Complete Recovery
With the database mounted on the node1 and no-mount on node2 connect to the target and catalog using RMAN.
rman target / catalog rman/rman@rcat
This script will restore and recover the database completely and open the database in read/write mode.
run {
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN;
}
Incomplete Recovery
1. Shutdown node1 and node2
2. Startup no-mount node2 and node1
3. Start rman and restore the controlfile from autobackup:
rman trace reco1.log
RMAN> CONNECT CATALOG rman/rman@rcat
RMAN> SET DBID=228033884;
RMAN> CONNECT TARGET
RMAN> restore controlfile;
4. If no catalog is used, you can restore the controlfile from autobackup
% rman trace recocf.log
RMAN> SET DBID=228033884;
RMAN> CONNECT TARGET /
RMAN> RUN
{
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE disk TO '/rman/V112/%F';
ALLOCATE CHANNEL d1 DEVICE TYPE disk;
RESTORE CONTROLFILE FROM AUTOBACKUP
MAXSEQ 5 # start at sequence 5 and count down (optional)
MAXDAYS 5; # start at UNTIL TIME and search back 5 days (optional)
MOUNT DATABASE;
}
See Note 372996.1 and/or Note 403883.1 for more options for restoring a controlfile.
5. Verify what is available for incomplete recovery.
We will recover with the highest available redo information. In a RAC database, both thread must be considered to determine highest available redo. The options are "until time", "until scn", or "until sequence". We will use the log sequence in this case.
a. First we need to find the highest sequence of each thread:
SQL> select max(sequence#) from v$archived_log L, v$database D
where L.resetlogs_change# = D.resetlogs_change# and
thread#=1;
MAX(SEQUENCE#)
--------------
25
SQL> select max(sequence#) from v$archived_log L, v$database D
where L.resetlogs_change# = D.resetlogs_change# and
thread#=2;
MAX(SEQUENCE#)
--------------
13
b. Next is to find the thread with lowest NEXT_CHANGE# scn.
SQL> select sequence#, thread#, first_change#, next_change#
from v$archived_log L, v$database D
where L.resetlogs_change# = D.resetlogs_change# and
sequence# in (13,25);
SEQUENCE# THREAD# FIRST_CHANGE# NEXT_CHANGE#
-------------------- -------------- ------------------------- -------------------------
25 1 1744432 1744802
13 2 1744429 1744805
SQL> select sequence#, thread#, first_change#, next_change#
from v$backup_redolog
where sequence# in (13,25);
SEQUENCE# THREAD# FIRST_CHANGE# NEXT_CHANGE#
-------------------- -------------- ------------------------- -------------------------
25 1 1744432 1744802
13 2 1744429 1744805
In this case the next_change# SCN in thread 1 sequence 25 is lower than sequence 13 thread 2. In a RAC environment, we use the lower to ensure we have the redo required from BOTH threads. In other words, we use the lower (thread# 1) to ensure that ALL scn (s) in thread #1 exist in the available sequence for thread #2.
So we will set sequence 26 for thread 1 for RMAN 'until sequence' recovery, because RMAN stops the recovery before applying the indicated sequence. Log sequence for recovery needs always be sequence+1 to end at +1 after applying the prior sequence. I.e.:
SET UNTIL SEQUENCE 26 THREAD 1;
6. Get the command to add TEMPFILES after opening DB.
Locally Managed Temporary Tablespaces are not restored by RESTORE command, we need to create them manually after recovery is complete.
If using LMT Temporary tablespace the controlfile will have the syntax to add the tempfile after recovery is complete. The following command will give us the create controlfile statement:
SQL> alter database backup controlfile to trace;
Example:
# Commands to add tempfiles to temporary tablespaces.
# Online tempfiles have complete space information.
# Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/dev/db/temp_01.dbf' SIZE 41943040 REUSE AUTOEXTEND OFF;
# End of tempfile additions.
#
NOTE: In newer versions, the tempfiles are added automatically.
7. Run the rman script
Since log sequence 13 thread 2 next_change# is 3 changes ahead of thread 1 sequence 25 we are using sequence 26 (25+1) to stop recovery. This will restore the data files and recover them applying all of sequence #25 of thread 1 and stopping at sequence #26.
run {
SET UNTIL SEQUENCE 26 THREAD 1;
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;
}
8. Review and understand the impact of resetlogs on the catalog.
After resetlogs a new incarnation for the database is recorded in the RMAN catalog and database controlfile. Only one incarnation can be current and any need to restore from a previous incarnation requires you to "reset database to incarnation...".
For example:
RMAN> LIST INCARNATION OF DATABASE V112;
List of Database Incarnations
DB Key Inc Key DB Name DB ID CUR Reset SCN Reset Time
----------- ----------- ------------ ---------------- ------- -------------- ---------------
2656 2657 V112 228033884 NO 1 29-MAY-13
2656 3132 V112 228033884 YES 1744806 13-JUN-13
We see that an "open resetlogs" was executed against this database on 13-JUN-2013.
9. RMAN Sample Commands
* With a dedicated listener (not using instance registration) restoring the controlfile.
run {
ALLOCATE CHANNEL D1 TYPE DISK CONNECT 'SYS/RAC@NODE1';
ALLOCATE CHANNEL D2 TYPE DISK CONNECT 'SYS/RAC@NODE2';
SET UNTIL SEQUENCE 14 THREAD 2;
RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;
RELEASE CHANNEL D1;
RELEASE CHANNEL D2;
}
* Backup Archivelog
BACKUP ARCHIVELOG ALL NOT BACKED UP 3 TIMES;
BACKUP ARCHIVELOG UNTIL TIME 'SYSDATE-2' NOT BACKED UP 2 TIMES;
#####
compress resotre优化
在之前的blog中我提到可以使用rman的多通道进行compress 备份,相应的在restore期间也可以使用多个通道,这样每个通道进程会被os放到不同的cpu上运行
从而加快restore过程,特别是在compress 的restore时候,这时候uncompress占用了很大一部分时间,使用多通道加速恢复的过程
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
set until sequence 26747 thread 1;
set until sequence 13743 thread 2;
restore database;
recover database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
试图分配五个通道进行restore,看结果
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup
XXXXXXXXXXXX
channel c1: reading from backup piece XXXXXXXXXXX
channel c2: starting datafile backup set restore
XXXXXXXXXXXXX
channel c2: reading from backup piece XXXXXXXXXX
channel c3: starting datafile backup set restore
channel c3: specifying datafile(s) to restore from backup set
XXXXXXXXXXXXXX
channel c3: reading from backup piece XXXXXXXXXXX
从输出中可以看出,rman 只使用了三个通道。这是为什么呢?原因是RMAN在进行restore的时候,只能是每个通道读一个backuppiece,虽然分配了五个道通,但实际上是三个通道在进行
restore操作,再然后就是在备份的时候,根据io能力,可以适当设置每个piece大小,形成多个piece,这样在resotre的时候可以使用多通道来加速,,再然后.......就没有了...............
转 RMAN: RAC Backup, Restore and Recovery using RMAN的更多相关文章
- Oracle 基于 RMAN 的不完全恢复(incomplete recovery by RMAN)
Oracle 数据库可以实现数据库不完全恢复与完全恢复.完全恢复是将数据库恢复到最新时刻,也就是无损恢复,保证数据库无丢失的恢复.而不完全恢复则是根据需要特意将数据库恢复到某个过去的特定时间点或特定的 ...
- 基于RMAN从活动数据库异机克隆(rman duplicate from active DB)
Oracle 11g RMAN能够实现基于活动数据库进行异机克隆,从而省去需要先备份再ftp到辅助服务器的过程.这一切可以全部交给Oracle来搞定.在克隆期间,Oracle会读取Target DB的 ...
- 如何将RAC数据库的 RMAN Disk 备份 Restore 到另一个节点上的单个实例 (Doc ID 415579.1)
HowTo Restore RMAN Disk backups of RAC Database to Single Instance On Another Node (Doc ID 415579.1) ...
- Performing a full database disaster recovery with RMAN
Performing a full database disaster recovery with RMAN1. Make the RMAN backup set pieces available.2 ...
- Oracle中Restore和Recovery的区别
一.参考解释一 在Oracle的备份与恢复的知识点中,经常会出现Restore 和 Recovery两个词. 由于这两个词在字典中的解释很接近,困扰了我很久.直到我在Oracle的官方文档中看到了以下 ...
- Getting Started with Recovery Manager (RMAN) (文档 ID 360416.1)
In this Document Purpose Scope Details Overview of the RMAN EnvironmentDeciding Whether to Use a Fla ...
- INFORMATICA 的部署实施之 BACKUP&RESTORE
当一套BI 解决方案成熟运行后,公司会快速扩大客户群,这时快速的将开发出来的SOLUTION 应用到全新的生产环境中就很重要了,下面谈谈我做这样项目(INFORMATICA BACKUP&RE ...
- 如何利用RMAN Debug和10046 Trace来诊断RMAN问题?
学习转摘:https://blogs.oracle.com/Database4CN/entry/%E5%A6%82%E4%BD%95%E5%88%A9%E7%94%A8rman_debug%E5%92 ...
- 如何利用RMAN Debug和10046 Trace来诊断RMAN问题?
在做Support的这些年,我很大的收获是掌握了许多troubleshooting问题的方法和工具,对于每一类问题,都可以大体归类出一些诊断方法.无论问题多么复杂,像扒洋葱一样,一层层去掉无 ...
随机推荐
- loadFileSystems error & ExceptionUtils错误原因分析
loadFileSystems error & ExceptionUtils错误原因分析 一见 2014/5/7 C/C++程序通过hdfs.h访问HDFS,运行时遇到如下错误,会是什么原因了 ...
- SpringMVC源码解读 - HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化
AbstractDetectingUrlHandlerMapping是通过扫描方式注册Handler,收到请求时由AbstractUrlHandlerMapping的getHandlerInterna ...
- 20169214 2016-2017-2 《网络攻防实践》第十一周实验 SQL注入
20169214 2016-2017-2 <网络攻防实践>SQL注入实验 SQL注入技术是利用web应用程序和数据库服务器之间的接口来篡改网站内容的攻击技术.通过把SQL命令插入到Web表 ...
- mybatis 基础教程
1.引用mybatis.jar包,以后依赖包. 2.配置映射文件(一个是主配置文件,一个是sql映射文件),注意,mapper.xml 文件必须和dao放在一起. 3.mybatis.xml文件说明 ...
- Backup--压缩备份和数据库压缩
1> 即使数据库启用了页压缩或行压缩,压缩备份也可以有效减小备份的大小,压缩备份的压缩效率取决于表中的数据类型 2> 数据库压缩有利于降低备份时间(因为数据库变小) 3> 对已启用压 ...
- CentOS关机命令
Linux centos关机与重启命令详解与实战 Linux centos重启命令: 1.reboot 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 1 ...
- 算法 UVA 11729
例2:假设当前小光有n个部下,每个部下需要完成一项任务.第i个部下需要小光花Bi分钟交代任务,然后他会立刻独立地.无间断地执行Ji分钟后完成任务.小光需要选择交代任务的顺序,使得所有任务尽早执行完毕 ...
- Mysql数据操作《三》多表查询
多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table department( id int, name varchar(20) ); create table employ ...
- [agc004e]Salvage Robots dp
Description 蛤蟆国的领土我们可以抽象为H*W的笼子,在这片蛤土上,有若干个机器人和一个出口,其余都是空地,每次蛤蟆会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被蛤蟆活摘出 ...
- 洛谷P2462 [SDOI2007]游戏(哈希+最长路)
题面 传送门 题解 我们把字符的出现次数哈希起来,然后把每个点向能在它之后的点连边.那么这显然是一个\(DAG\),直接求最长路就行了 //minamoto #include<bits/stdc ...