概述
本篇主要对RMAN进行一个粗略的演示,通过本篇的介绍,希望大家可以对RMAN有个初步的了解和认识。
一 RMAN环境
RMAN是一个Oracle数据库客户端,它执行备份和恢复任务,并实现备份策略的自动化管理,它极大简化了备份、还原和恢复数据库文件。
RMAN环境主要包含以下:
- target database:目标数据库,即RMAN使用target关键字连接的数据库,也是RMAN在其上执行备份和恢复操作的数据库,RMAN在该数据库的控制文件中维护备份和恢复操作的元数据信息,RMAN元数据也成为RMAN信息库(RMAN repository);
- RMAN client:执行RMAN命令的客户端软件,位于$ORACLE_HOME/bin下面;
- fast recovery area:快速恢复区,在该位置存储和管理与备份和恢复相关的文件,通过初始化参数db_recovery_file_dest和db_recovery_file_dest_size设置;
- media manager:介质管理器;
- recovery catalog:恢复目录,一个单独的数据库schema,用来记录target database的RMAN活动,可以实现元数据的集中管理,相比于控制文件,它可以永久的保存元数据信息。
二 启用RMAN连接数据库
--方法一
[oracle@strong ~]$ rman
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Apr 19 15:39:23 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates.
All rights reserved.
--连接target或auxiliary需要sysdba权限,as sysdba隐式指定,不能显式指定
RMAN> connect target /
connected to target database: ORCL (DBID=1500705231)
--方法二
[oracle@strong ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Apr 19 15:41:44 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates.
All rights reserved.
connected to target database: ORCL (DBID=1500705231)
RMAN>
三 RMAN默认配置
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # 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 ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default
四 备份数据库
1 数据库处于归档模式
当数据库处于归档模式,可以在其打开的情况下进行备份,此时的备份是非一致性备份,因为需要使用redo将数据库恢复到一致性状态。
--查看数据库归档模式
SQL> archive log list;
Database log mode
Archive Mode
Automatic archival
Enabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence
19
Next log sequence to archive
21
Current log sequence
21
--备份数据库及归档日志
RMAN> backup database plus archivelog;
Starting backup at 19-APR-18
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=1 STAMP=973649838
input archived log thread=1 sequence=14 RECID=2 STAMP=973703816
input archived log thread=1 sequence=15 RECID=3 STAMP=973721553
input archived log thread=1 sequence=16 RECID=4 STAMP=973778469
input archived log thread=1 sequence=17 RECID=5 STAMP=973814457
input archived log thread=1 sequence=18 RECID=6 STAMP=973855617
input archived log thread=1 sequence=19 RECID=7 STAMP=973855618
input archived log thread=1 sequence=20 RECID=8 STAMP=973855662
input archived log thread=1 sequence=21 RECID=9 STAMP=973871345
channel ORA_DISK_1: starting piece 1 at 19-APR-18
channel ORA_DISK_1: finished piece 1 at 19-APR-18
piece handle=+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t154907_0.261.973871349 tag=TAG20180419T154907 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:56
Finished backup at 19-APR-18
Starting backup at 19-APR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/orcl/datafile/system.256.972924187
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux.257.972924189
input datafile file number=00005 name=+DATA/orcl/datafile/example.265.972924601
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs1.258.972924189
input datafile file number=00004 name=+DATA/orcl/datafile/users.259.972924191
channel ORA_DISK_1: starting piece 1 at 19-APR-18
channel ORA_DISK_1: finished piece 1 at 19-APR-18
piece handle=+FRA/orcl/backupset/2018_04_19/nnndf0_tag20180419t155005_0.262.973871407 tag=TAG20180419T155005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:06
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 19-APR-18
channel ORA_DISK_1: finished piece 1 at 19-APR-18
piece handle=+FRA/orcl/backupset/2018_04_19/ncsnf0_tag20180419t155005_0.263.973871535 tag=TAG20180419T155005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 19-APR-18
Starting backup at 19-APR-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=10 STAMP=973871541
channel ORA_DISK_1: starting piece 1 at 19-APR-18
channel ORA_DISK_1: finished piece 1 at 19-APR-18
piece handle=+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t155221_0.265.973871541 tag=TAG20180419T155221 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 19-APR-18
2 数据库处于非归档模式
当数据库处于非归档模式时,此时的备份是一致性备份。非归档模式的备份,数据库必须在一致性关闭后处于mounted状态才可以执行,还原备份时不需要执行恢复操作。
--查看数据库归档模式
SQL> archive log list;
Database log mode
No Archive Mode
Automatic archival
Disabled
Archive destination
USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence
21
Current log sequence
23
--执行备份
RMAN> shutdown immediate
--关闭数据库
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount
--启动数据库至mount状态
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area
521936896 bytes
Fixed Size
2254824 bytes
Variable Size
364906520 bytes
Database Buffers
150994944 bytes
Redo Buffers
3780608 bytes
RMAN> backup database;
--备份数据库
3 典型的备份选项
3.1 Format选项
1)选项格式
用于指定备份片和备份拷贝的位置和名称,必须使用替代变量产生唯一的文件名称。
使用FORMAT参数时可使用的各种替换变量,如下(注意大小写)所示:
%a:Oracle数据库的activation ID即RESETLOG_ID。
%c:备份片段的复制数(从1开始编号,最大不超过256)。
%d:Oracle数据库名称。
%D:当前时间中的日,格式为DD。
%e:归档序号。
%f:绝对文件编号。
%F:基于"DBID+时间"确定的唯一名称,格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII 为该数据库的DBID,YYYYMMDD为日期,QQ是一个1~256的序列。
%h:归档日志线程号。
%I:Oracle数据库的DBID。
%M:当前时间中的月,格式为MM。
%N:表空间名称。
%n:数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8。比如数据库名ORCL,则生成的名称则是ORCLx。
%p:备份集中备份片段的编号,从1开始。
%s:备份集号。
%t:备份集时间戳。
%T:当前时间的年月日格式(YYYYMMDD)。
%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称。
%U:默认是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式,执行不同备份操作时,生成的规则也不同,如下所示:
生成备份片段时,%U=%u_%p_%c;
生成数据文件镜像复制时,%U=data-D-%d_id-%I_TS-%N_FNO-%f_%u;
生成归档文件镜像复制时,%U=arch-D_%d-id-%I_S-%e_T-%h_A-%a_%u;
生成控制文件镜像复制时,%U=cf-D_%d-id-%I_%u。
%Y:当前时间中的年,格式为YYYY。
注:如果在BACKUP命令中没有指定FORMAT选项,则RMAN默认使用%U为备份片段命名。
2)示例
RMAN> backup datafile 5 format 'EXP_%d_%t_%s_%p';
3.2 Tag选项
该选项用于指定备份一个用户定义的名称,未指定Tag,RMAN默认的Tag是日期和时间的组合。Tag以大写形式存储于RMAN信息库。
示例:
RMAN> backup datafile 5 tag 'example_bak';
4 增量备份
如果指定BACKUP incremental,那么RMAN将创建增量备份,增量备份会捕获自上次增量备份之后数据块级别的变化,相比较完全数据块备份,增量备份通常更小,而且更快。增量备份的恢复会比单独使用redo日志要快。
增量备份是基于0级增量备份(level 0 incremental backup),0级增量备份和完全数据库备份一样,它备份了所有数据块。1级增量备份仅仅包含上次增量备份之后更改的数据块,如果0级备份不存在,当运行1级备份时,RMAN会自动执行0级别的备份。
1级备份可以是累积增量备份(cumulative incremental backup),它包含自最近0级备份以来所有更改的数据块;也可以是差异增量备份(differential incremental backup),它仅仅包含自最近的增量备份以来更改的数据块,默认使用差异增量备份。
在恢复增量备份时,RMAN使用0级备份作为起始点,然后根据1级备份更新已更改的块,如果增量备份可用,那么RMAN在恢复期间将会使用它们。
4.1 执行增量备份
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--创建0级增量备份
RMAN> backup incremental level 0 database;
--创建1级累积增量备份
RMAN> backup incremental level 1 cumulative database;
--创建1级差异增量备份
RMAN> backup incremental level 1 database;
4.2 执行增量更新备份
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--运行以下命令
RMAN> recover copy of database with tag 'incr_update' ;
Starting recover at 19-APR-18
using channel ORA_DISK_1
no copy of datafile 1 found to recover
no copy of datafile 2 found to recover
no copy of datafile 3 found to recover
no copy of datafile 4 found to recover
no copy of datafile 5 found to recover
Finished recover at 19-APR-18
RMAN> backup incremental level 1 for recover of copy with tag 'incr_update' database;
Starting backup at 19-APR-18
using channel ORA_DISK_1
no parent backup or copy of datafile 1 found
no parent backup or copy of datafile 2 found
no parent backup or copy of datafile 5 found
no parent backup or copy of datafile 3 found
no parent backup or copy of datafile 4 found
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+DATA/orcl/datafile/system.256.972924187
output file name=+FRA/orcl/datafile/system.263.973877657 tag=INCR_UPDATE RECID=2 STAMP=973877701
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:46
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux.257.972924189
output file name=+FRA/orcl/datafile/sysaux.265.973877703 tag=INCR_UPDATE RECID=3 STAMP=973877736
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:36
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=+DATA/orcl/datafile/example.265.972924601
output file name=+FRA/orcl/datafile/example.267.973877739 tag=INCR_UPDATE RECID=4 STAMP=973877755
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs1.258.972924189
output file name=+FRA/orcl/datafile/undotbs1.266.973877765 tag=INCR_UPDATE RECID=5 STAMP=973877769
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 19-APR-18
channel ORA_DISK_1: finished piece 1 at 19-APR-18
piece handle=+FRA/orcl/backupset/2018_04_19/ncsnn1_incr_update_0.262.973877775 tag=INCR_UPDATE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA/orcl/datafile/users.259.972924191
output file name=+FRA/orcl/datafile/users.261.973877777 tag=INCR_UPDATE RECID=6 STAMP=973877776
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 19-APR-18
RMAN>
5 校验数据文件和备份
可以使用validate命令确认数据文件是否存在、是否在正确的位置以及是否损坏。
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--校验数据文件是否损坏
RMAN> backup validate check logical database;
Starting backup at 19-APR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/orcl/datafile/system.256.972924187
input datafile file number=00002 name=+DATA/orcl/datafile/sysaux.257.972924189
input datafile file number=00005 name=+DATA/orcl/datafile/example.265.972924601
input datafile file number=00003 name=+DATA/orcl/datafile/undotbs1.258.972924189
input datafile file number=00004 name=+DATA/orcl/datafile/users.259.972924191
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
1
OK
0
15330
96071
1326728
File Name: +DATA/orcl/datafile/system.256.972924187
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
63528
Index
0
13173
Other
0
3969
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2
OK
0
22321
78129
1326537
File Name: +DATA/orcl/datafile/sysaux.257.972924189
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
15593
Index
0
11245
Other
0
28921
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
3
OK
0
1
11520
1326726
File Name: +DATA/orcl/datafile/undotbs1.258.972924189
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
0
Index
0
0
Other
0
11519
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4
OK
0
18
667
952794
File Name: +DATA/orcl/datafile/users.259.972924191
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
91
Index
0
39
Other
0
492
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5
OK
0
31439
40083
987188
File Name: +DATA/orcl/datafile/example.265.972924601
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
4432
Index
0
1159
Other
0
3050
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type
Status Blocks Failing Blocks Examined
------------ ------ -------------- ---------------
SPFILE
OK
0
2
Control File OK
0
594
Finished backup at 19-APR-18
RMAN>
--校验数据文件
RMAN> validate datafile 5;
Starting validate at 19-APR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00005 name=+DATA/orcl/datafile/example.265.972924601
channel ORA_DISK_1: validation complete, elapsed time: 00:00:07
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5
OK
0
31439
40083
987188
File Name: +DATA/orcl/datafile/example.265.972924601
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data
0
4432
Index
0
1159
Other
0
3050
Finished validate at 19-APR-18
--校验备份集
RMAN> validate backupset 20;
Starting validate at 19-APR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece +FRA/orcl/backupset/2018_04_19/ncsnn1_incr_update_0.262.973877775
channel ORA_DISK_1: piece handle=+FRA/orcl/backupset/2018_04_19/ncsnn1_incr_update_0.262.973877775 tag=INCR_UPDATE
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:02
Finished validate at 19-APR-18
6 脚本化RMAN
可以创建RMAN脚本实现自动化操作,也可以使用RMAN的脚本功能。
--创建脚本
[oracle@strong ~]$ cat rman_test.txt
connect target /
backup database plus archivelog;
list backup;
exit;
--执行脚本
RMAN> @rman_test.txt
五 报告展示RMAN操作
可以使用RMAN的List和Report命令基于RMAN信息库产生备份活动的报告,使用Show all命令可以显示RMAN当前的配置。
1 列出备份信息
运行List backup和List copy命令,可以展示信息库中的备份、数据文件拷贝信息。对于备份,可以使用选项控制List输出的格式。
对于备份和拷贝,可以使用下面的选项:
示例:
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--RMAN下运行List命令
RMAN> list backup of database;
using target database control file instead of recovery catalog
specification does not match any backup in the repository
RMAN> list copy of datafile 1,2;
List of Datafile Copies
=======================
Key
File S Completion Time Ckp SCN
Ckp Time
------- ---- - --------------- ---------- ---------------
2
1
A 19-APR-18
1326732
19-APR-18
Name: +FRA/orcl/datafile/system.263.973877657
Tag: INCR_UPDATE
3
2
A 19-APR-18
1326732
19-APR-18
Name: +FRA/orcl/datafile/sysaux.265.973877703
Tag: INCR_UPDATE
RMAN> list backup of archivelog from sequence 10;
List of Backup Sets
===================
BS Key
Size
Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
21
165.86M
DISK
00:00:23
19-APR-18
BP Key: 21
Status: AVAILABLE
Compressed: NO
Tag: TAG20180419T174940
Piece Name: +FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t174940_0.262.973878581
List of Archived Logs in backup set 21
Thrd Seq
Low SCN
Low Time
Next SCN
Next Time
---- ------- ---------- --------- ---------- ---------
1
13
1144519
16-APR-18 1178751
17-APR-18
1
14
1178751
17-APR-18 1213547
17-APR-18
1
15
1213547
17-APR-18 1225051
17-APR-18
1
16
1225051
17-APR-18 1261927
18-APR-18
1
22
1325021
19-APR-18 1325188
19-APR-18
RMAN> list backupset of datafile 1;
specification does not match any backup in the repository
2 报告数据文件和备份
Report命令可以执行比List命令更复杂的分析。
Report选项有:
示例:
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--运行Report命令
RMAN> report obsolete;
--根据当前备份保留策略,列出过期的备份
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type
Key
Completion Time
Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log
1
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_972924505.dbf
Archive Log
2
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_14_972924505.dbf
Archive Log
3
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_972924505.dbf
Archive Log
4
18-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_972924505.dbf
Archive Log
10
19-APR-18
+FRA/orcl/archivelog/2018_04_19/thread_1_seq_22.264.973871539
Backup Set
21
19-APR-18
Backup Piece
21
19-APR-18
+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t174940_0.262.973878581
RMAN> report schema;
--列出数据库的数据文件和临时文件
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace
RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1
750
SYSTEM
***
+DATA/orcl/datafile/system.256.972924187
2
610
SYSAUX
***
+DATA/orcl/datafile/sysaux.257.972924189
3
90
UNDOTBS1
***
+DATA/orcl/datafile/undotbs1.258.972924189
4
5
USERS
***
+DATA/orcl/datafile/users.259.972924191
5
313
EXAMPLE
***
+DATA/orcl/datafile/example.265.972924601
List of Temporary Files
=======================
File Size(MB) Tablespace
Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1
29
TEMP
32767
+DATA/orcl/tempfile/temp.264.972924547
RMAN>
六 维护RMAN备份
RMAN信息库元数据总是存储在Target数据库的控制文件中,RMAN维护命令使用这些元数据对备份进行管理。
1 CROSSCHECK备份
CROSSCHECK命令将RMAN备份和拷贝的逻辑记录与存储介质上的文件同步,如果备份在磁盘上,那么CROSSCHECK将确定文件头是否有效;如果备份在磁带上,那么RMAN将查询RAMN信息库,以查找备份片的名称和位置。删除备份和拷贝前,使用CROSSCHECK命令校验下是个不错的主意。
示例:
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--运行CROSSCHECK命令
RMAN> crosscheck backup;
--校验备份
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t174940_0.262.973878581 RECID=21 STAMP=973878580
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=+FRA/orcl/backupset/2018_04_19/ncsnf0_tag20180419t175005_0.260.973878625 RECID=22 STAMP=973878624
Crosschecked 2 objects
RMAN> crosscheck copy;
--校验拷贝
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK
specification does not match any control file copy in the repository
validation succeeded for datafile copy
datafile copy file name=+FRA/orcl/datafile/system.263.973877657 RECID=2 STAMP=973877701
validation succeeded for datafile copy
datafile copy file name=+FRA/orcl/datafile/sysaux.265.973877703 RECID=3 STAMP=973877736
validation succeeded for datafile copy
datafile copy file name=+FRA/orcl/datafile/undotbs1.266.973877765 RECID=5 STAMP=973877769
validation succeeded for datafile copy
datafile copy file name=+FRA/orcl/datafile/users.261.973877777 RECID=6 STAMP=973877776
validation succeeded for datafile copy
datafile copy file name=+FRA/orcl/datafile/example.267.973877739 RECID=4 STAMP=973877755
validation succeeded for archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_972924505.dbf RECID=1 STAMP=973649838
validation succeeded for archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_14_972924505.dbf RECID=2 STAMP=973703816
validation succeeded for archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_972924505.dbf RECID=3 STAMP=973721553
validation succeeded for archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_972924505.dbf RECID=4 STAMP=973778469
validation succeeded for archived log
archived log file name=+FRA/orcl/archivelog/2018_04_19/thread_1_seq_22.264.973871539 RECID=10 STAMP=973871541
Crosschecked 10 objects
2 删除过期(obsolete)的备份
Delete命令可以从磁盘或磁带移除RMAN备份和拷贝、更新控制文件信息库中文件的状态为DELETED,如果使用恢复目录的话,会移除恢复目录中对应的记录。如果交互式使用RMAN,不必指定NOPROMPT选项,Delete将会展示文件的清单并在删除之前提示确认是否删除。
示例:
--启动RMAN
[oracle@strong ~]$ rman target sys/system@orcl
--运行Delete obsolete命令
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type
Key
Completion Time
Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log
1
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_972924505.dbf
Archive Log
2
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_14_972924505.dbf
Archive Log
3
17-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_972924505.dbf
Archive Log
4
18-APR-18
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_972924505.dbf
Archive Log
10
19-APR-18
+FRA/orcl/archivelog/2018_04_19/thread_1_seq_22.264.973871539
Backup Set
21
19-APR-18
Backup Piece
21
19-APR-18
+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t174940_0.262.973878581
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_972924505.dbf RECID=1 STAMP=973649838
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_14_972924505.dbf RECID=2 STAMP=973703816
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_972924505.dbf RECID=3 STAMP=973721553
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_972924505.dbf RECID=4 STAMP=973778469
deleted archived log
archived log file name=+FRA/orcl/archivelog/2018_04_19/thread_1_seq_22.264.973871539 RECID=10 STAMP=973871541
deleted backup piece
backup piece handle=+FRA/orcl/backupset/2018_04_19/annnf0_tag20180419t174940_0.262.973878581 RECID=21 STAMP=973878580
Deleted 6 objects
七 使用数据恢复顾问(Data Recovery Advisor)诊断和修复故障
诊断和修复数据库问题的最简单的方式是使用数据恢复顾问,该Oracle数据库工具提供了一个用于诊断持久数据故障的基础设施,并为用户提供修复选项,并且自动执行修复。
1 列出故障和确定修复选项
故障(Failure)是有健康监视器(Health Monitor)检测到的持久数据损坏,包括物理和逻辑的数据块损坏,以及数据文件丢失。每个故障都有一个故障优先级和故障状态,优先级可以是Critical、high或者low,状态可以是open或closed。
可以使用LIST Failure命令显示所有已知的故障,如果故障存在,然后运行advise failure命令确定手动和自动修复选项,下面进行演示:
[oracle@strong ~]$ rman target sys/system@orcl
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Apr 20 10:57:30 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates.
All rights reserved.
connected to target database: ORCL (DBID=1500705231, not open)
RMAN> list failure;
--列出故障
using target database control file instead of recovery catalog
List of Database Failures
=========================
Failure ID Priority Status
Time Detected Summary
---------- -------- --------- ------------- -------
1062
HIGH
OPEN
20-APR-18
One or more non-system datafiles are missing
RMAN> advise failure
--建议
2> ;
List of Database Failures
=========================
Failure ID Priority Status
Time Detected Summary
---------- -------- --------- ------------- -------
1062
HIGH
OPEN
20-APR-18
One or more non-system datafiles are missing
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=25 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file +DATA/orcl/datafile/example.265.972924601 was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1
Restore and recover datafile 5
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_2406716080.hm
RMAN>
2 修复故障
在RMAN会话运行List Failure和advise failure后,使用repair failure执行修复选项。如果在没有其他命令选项的情况下执行repar failure,那么RMAN将使用当前会话中最接近advise failure的第一个修复选项,或者,指定从最近的advise failure包含的修复选项号。
示例:
RMAN> repair failure;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/orcl/orcl/hm/reco_2406716080.hm
contents of repair script:
# restore and recover datafile
restore datafile 5;
recover datafile 5;
sql 'alter database datafile 5 online';
Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script
Starting restore at 20-APR-18
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 00005 to +DATA/orcl/datafile/example.265.972924601
channel ORA_DISK_1: reading from backup piece +FRA/orcl/backupset/2018_04_20/nnndf0_tag20180420t104215_0.266.973939345
channel ORA_DISK_1: piece handle=+FRA/orcl/backupset/2018_04_20/nnndf0_tag20180420t104215_0.266.973939345 tag=TAG20180420T104215
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 20-APR-18
Starting recover at 20-APR-18
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 20-APR-18
sql statement: alter database datafile 5 online
repair failure complete
Do you want to open the database (enter YES or NO)? yes
database opened
八 使用闪回回退数据库
可以使用Oracle Flashback Database将整个数据库回退到过去某个时间,和介质恢复不同,它不必还原数据文件。使用RMAN Flashback Database命令,数据库必须配置为可产生闪回日志(默认不启用闪回),执行该命令时,数据库必须处于Mounted状态。
参考:Oracle Flashback技术
九 恢复和还原数据文件
对于RMAN,可以使用RESTORE和recover命令进行还原和恢复物理数据库文件。恢复数据文件是从备份中检索它们,以进行恢复操作。
1 准备还原和恢复数据库文件
[oracle@strong ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Apr 20 11:59:25 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates.
All rights reserved.
connected to target database: ORCL (DBID=1500705231)
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace
RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1
750
SYSTEM
***
+DATA/orcl/datafile/system.256.972924187
2
610
SYSAUX
***
+DATA/orcl/datafile/sysaux.257.972924189
3
90
UNDOTBS1
***
+DATA/orcl/datafile/undotbs1.258.972924189
4
5
USERS
***
+DATA/orcl/datafile/users.259.972924191
5
313
EXAMPLE
***
+DATA/orcl/datafile/example.265.973940423
List of Temporary Files
=======================
File Size(MB) Tablespace
Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1
29
TEMP
32767
+DATA/orcl/tempfile/temp.264.972924547
RMAN> restore database preview summary;
Starting restore at 20-APR-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
List of Backups
===============
Key
TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
24
B
F
A DISK
20-APR-18
1
1
NO
TAG20180420T104215
using channel ORA_DISK_1
List of Archived Log Copies for database with db_unique_name ORCL
=====================================================================
Key
Thrd Seq
S Low Time
------- ---- ------- - ---------
15
1
24
A 20-APR-18
Name: +FRA/orcl/archivelog/2018_04_20/thread_1_seq_24.256.973943355
13
1
25
A 20-APR-18
Name: +FRA/orcl/archivelog/2018_04_20/thread_1_seq_25.259.973943353
Media recovery start SCN is 1327367
Recovery must be done beyond SCN 1327367 to clear datafile fuzziness
Finished restore at 20-APR-18
RMAN>
2 恢复整个数据库
RMAN> shutdown immediate
RMAN> startup mount
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open;
3 恢复表空间
RMAN> sql 'alter tablespace users offline';
RMAN> restore tablespace users;
RMAN> recover tablespace users;
RMAN> sql 'alter tablespace users online';
4 恢复单个数据块
--查询表
SELECT * FROM V$DATABASE_BLOCK_CORRUPTION;
--执行恢复命令
RMAN> recover corruption list;
--或者恢复数据文件
RMAN> recover datafile 1 block 233;
最后
以上就是大气酸奶为你收集整理的【RMAN】RMAN初探的全部内容,希望文章能够帮你解决【RMAN】RMAN初探所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复