RMAN恢复
<p>[TOC]</p>
<h2>恢复的前提</h2>
<p>归档模式
存在备份
实现完全恢复,需要自备份以来的归档日志和当前日志文件完整,保证日志的连续性。</p>
<h2>创建备份</h2>
<pre><code>- 归档模式创建备份
$ vim /backup/script/rman_hot.sql
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup database format '/backup/rman/rmanhotdb_%d_%T_%U.bak'
plus archivelog format '/backup/rman/rmanhotar_%d_%T_%U.bak';
backup current controlfile format '/backup/rman/rmanhotctl_%d_%T_%U.bak';
release channel c1;
release channel c2;
}
- 执行备份脚本
RMAN> @/backup/script/rman_hot.sql
RMAN> run{
2> allocate channel c1 device type disk;
3> allocate channel c2 device type disk;
4> backup database format '/backup/rman/rmanhotdb_%d_%T_%U.bak'
5> plus archivelog format '/backup/rman/rmanhotar_%d_%T_%U.bak';
6> backup current controlfile format '/backup/rman/rmanhotctl_%d_%T_%U.bak';
7> release channel c1;
8> release channel c2;
9> }
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=42 device type=DISK
allocated channel: c2
channel c2: SID=50 device type=DISK
Starting backup at 25-NOV-21
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=28 RECID=13 STAMP=1089574138
channel c1: starting piece 1 at 25-NOV-21
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=29 RECID=14 STAMP=1089574147
input archived log thread=1 sequence=30 RECID=15 STAMP=1089575433
channel c2: starting piece 1 at 25-NOV-21
channel c1: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotar_RACDB_20211125_180f36ni_1_1.bak tag=TAG20211125T195426 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=31 RECID=16 STAMP=1089575666
channel c1: starting piece 1 at 25-NOV-21
channel c2: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotar_RACDB_20211125_190f36ni_1_1.bak tag=TAG20211125T195426 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:02
channel c1: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotar_RACDB_20211125_1a0f36nj_1_1.bak tag=TAG20211125T195426 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-NOV-21
Starting backup at 25-NOV-21
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/RACDB/DATAFILE/system.256.1089477103
input datafile file number=00002 name=+DATA/RACDB/DATAFILE/tjdata.261.1089483283
input datafile file number=00005 name=+DATA/RACDB/DATAFILE/tjdata.262.1089483247
channel c1: starting piece 1 at 25-NOV-21
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00003 name=+DATA/RACDB/DATAFILE/sysaux.257.1089477137
input datafile file number=00004 name=+DATA/RACDB/DATAFILE/undotbs1.258.1089477153
input datafile file number=00007 name=+DATA/RACDB/DATAFILE/users.259.1089477153
channel c2: starting piece 1 at 25-NOV-21
channel c2: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotdb_RACDB_20211125_1c0f36nl_1_1.bak tag=TAG20211125T195429 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:03
channel c1: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotdb_RACDB_20211125_1b0f36nl_1_1.bak tag=TAG20211125T195429 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:07
Finished backup at 25-NOV-21
Starting backup at 25-NOV-21
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=32 RECID=17 STAMP=1089575676
channel c1: starting piece 1 at 25-NOV-21
channel c1: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotar_RACDB_20211125_1d0f36ns_1_1.bak tag=TAG20211125T195436 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-NOV-21
Starting backup at 25-NOV-21
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 25-NOV-21
channel c1: finished piece 1 at 25-NOV-21
piece handle=/backup/rman/rmanhotctl_RACDB_20211125_1e0f36nt_1_1.bak tag=TAG20211125T195437 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-NOV-21
Starting Control File and SPFILE Autobackup at 25-NOV-21
piece handle=+ARCH/RACDB/AUTOBACKUP/2021_11_25/s_1089575679.274.1089575679 comment=NONE
Finished Control File and SPFILE Autobackup at 25-NOV-21
released channel: c1
released channel: c2
RMAN> **end-of-file**</code></pre>
<h2>故障场景1(关键数据文件)</h2>
<h3>system表空间数据文件损坏</h3>
<ul>
<li>system.256.1089477103 文件丢失</li>
</ul>
<pre><code>RMAN> report schema;
Report of database schema for database with db_unique_name RACDB
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 910 SYSTEM YES +DATA/RACDB/DATAFILE/system.256.1089477103</code></pre>
<ul>
<li>断电死机</li>
</ul>
<pre><code>SQL> shutdown abort
ORACLE instance shut down.</code></pre>
<ul>
<li>丢失文件</li>
</ul>
<pre><code>ASMCMD> cd +data/racdb/datafile
rm SYSTEM.256.1089477103</code></pre>
<ul>
<li>无法开启实例</li>
</ul>
<pre><code>SQL> startup
ORACLE instance started.
Total System Global Area 5251267320 bytes
Fixed Size 8907512 bytes
Variable Size 939524096 bytes
Database Buffers 4294967296 bytes
Redo Buffers 7868416 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '+DATA/RACDB/DATAFILE/system.256.1089477103'</code></pre>
<h3>恢复故障场景1</h3>
<ul>
<li>rman恢复:列出错误、分析恢复方案、执行恢复</li>
</ul>
<pre><code>[oracle@abcprod2 ~]$ rman target /
connected to target database: RACDB (DBID=1087093976, not open)
## 列出错误
RMAN> list failure;
using target database control file instead of recovery catalog
Database Role: PRIMARY
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
962 CRITICAL OPEN 25-NOV-21 System datafile 1: '+DATA/RACDB/DATAFILE/system.256.1089477103' is missing
## 分析恢复方案
RMAN> advise failure;
Database Role: PRIMARY
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
962 CRITICAL OPEN 25-NOV-21 System datafile 1: '+DATA/RACDB/DATAFILE/system.256.1089477103' is missing
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=56 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file +DATA/RACDB/DATAFILE/system.256.1089477103 was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 1
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/racdb/racdb/hm/reco_1597510278.hm
## 执行恢复操作
RMAN> repair failure;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/racdb/racdb/hm/reco_3057619119.hm
contents of repair script:
# restore and recover datafile
restore ( datafile 1 );
recover datafile 1;
sql 'alter database datafile 1 online';
Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script
Starting restore at 25-NOV-21
using channel ORA_DISK_1
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.256.1089477103
channel ORA_DISK_1: reading from backup piece /backup/rman/rmanhotdb_RACDB_20211125_1b0f36nl_1_1.bak
channel ORA_DISK_1: piece handle=/backup/rman/rmanhotdb_RACDB_20211125_1b0f36nl_1_1.bak tag=TAG20211125T195429
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 25-NOV-21
Starting recover at 25-NOV-21
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 25-NOV-21
sql statement: alter database datafile 1 online
repair failure complete
Do you want to open the database (enter YES or NO)? yes
database opened</code></pre>
<h2>故障场景2(非关键数据文件损坏)</h2>
<h3></h3>
<h3></h3>
<h2>故障场景2(非关键数据文件损坏)</h2>
<h3></h3>
<h3></h3>
<h2>故障场景2(非关键数据文件损坏)</h2>
<h3></h3>
<h3></h3>