Oracle RMAN备份与还原

本文转自:https://www.cnblogs.com/Latiny/p/6920428.html html


对于Rman有了很深入的认识,很是感谢博主算法


RMAN在数据库服务器的帮助下实现数据库文件、控制文件、数据库文件与控制文件的映像副本、归档日志文件、数据库服务器参数文件的备份。数据库

  RMAN的特色:服务器

(1) 支持增量备份:传统的exp与expdp备份工具,只能实现一个完整备份而不能增量备份,RMAN采用备份级别实现增量备份,在一个完整的备份基础上采用增量备份能够大大减小备份的数量;oracle

(2) 自动管理备份文件:RMAN备份的数据是RMAN自动管理的,包括文件名字,备份文件存储目录等;app

(3) 自动化备份与恢复:在备份与恢复操做时,使用简单的指令就能够实现备份与恢复,执行过程彻底有RMAN维护。ide

(4) 不产生重作信息: RMAN联机备份不产生重作信息。工具

(5) 支持映像复制: 使用RMAN能够实现映像复制,映像以操做系统的文件格式存在,这种复制相似于用户管理的脱机备份方式。测试

(6) 备份的数据文件压缩处理: RMAN提供一个参数,说明是否对备份文件进行压缩,压缩的备份文件以二进制文件格式存在,能够减小备份文件的存储空间。优化

(7) 备份文件有效性检查功能: 能够在备份以后恢复检测备份文件是否可用,避免无效恢复操做。

 

1 RMAN 脱机备份与还原

 

1.1 使用RMAN命令链接到数据库

[oracle@oracledb ~]$ rman target/

Recovery Manager: Release 11.2.0.1.0 - Production on Tue May 30 14:33:04 2017

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

connected to target database: ORCL (DBID=1452257309)

 

1.2 脱机备份以前肯定数据库处于非归档模式下,使用管理员帐号登陆到数据库查看

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Current log sequence

 

1.3 脱机备份时数据必须处于mount状态下,关机启动数据库到mount状态下

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 339740304 bytes
Database Buffers 104857600 bytes
Redo Buffers 4141056 bytes
Database mounted.

 

1.4 RMAN模式下输入脱机备份命令,系统会自动备份整个数据库到默认的目录下

RMAN> backup as compressed backupset database;

Starting backup at 30-MAY-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
input datafile file number=00007 name=/home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00009 name=/home/oracle/data/rman_ts1.dbf
input datafile file number=00006 name=/usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbf
input datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbf
input datafile file number=00008 name=/home/oracle/data/default_tablespace.dbf
input datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbf
input datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp tag=TAG20170530T105100 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
Finished backup at 30-MAY-17

 

Starting Control File and SPFILE Autobackup at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 30-MAY-17

 

以上备份信息能够看出,RMAN将数据文件备份在目录/usr/oracle/app/flash_recovery_area/ORCL/backupset/下,将控制文件与服务器参数文件备份在/usr/oracle/app/flash_recovery_area/ORCL/autobackup/下。这里须要注意若是想要RMAN在整库备份时自动备份控制文件与服务器参数文件,须要设置参数

configure controlfile autobackup的值为on: configure controlfile autobackup on;

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

 

此时使用RMAN完成了整个数据库的脱机备份。

 

备份完成以后用scott用户建立一个测试表,插入一条数据,等恢复完成以后看这个表是否还存在。

create table t_test1(id number, name varchar2(50));

insert into t_test1(id, name)
values(1,'latiny1');

commit;

 

非归档模式下实现脱机备份恢复

为了测试利用脱机备份文件彻底恢复数据库,咱们删除部分数据文件、所有控制文件模拟数据库文件丢失,而后进行恢复。

[root@oracledb orcl]# ls -l
total 4867456
-rw-r----- 1 oracle oinstall 524296192 May 30 12:12 APSALU3_DATA.dbf
-rw-r----- 1 oracle oinstall 9748480 May 30 14:48 control01.ctl
-rw-r----- 1 oracle oinstall 2147491840 May 30 12:12 CTRR_DATA.dbf
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 14:48 redo01.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo02.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo03.log
-rwxrwxr-x 1 oracle oinstall 660611072 May 30 14:48 sysaux01.dbf
-rwxrwxr-x 1 oracle oinstall 754982912 May 30 14:48 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Mar 23 10:52 temp01.dbf
-rwxrwxr-x 1 oracle oinstall 723525632 May 30 14:48 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 30 12:12 users01.dbf

 首先关闭数据库,而后删除users01.dbf、CTRR_DATA.dbf、control01.ctl、APSALU3_DATA.dbf,而后启动数据库:

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

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 339740304 bytes
Database Buffers 104857600 bytes
Redo Buffers 4141056 bytes
ORA-00205: error in identifying control file, check alert log for more info

 

因为控制文件丢失,数据库没法启动到mount状态,先恢复控制文件再启动,恢复控制文件须要指定控制文件对应的备份文件路劲,以前的备份信息里能够获取获得:

RMAN> restore controlfile from '/usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp';

Starting restore at 30-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/usr/oracle/app/oradata/orcl/control01.ctl
output file name=/usr/oracle/app/flash_recovery_area/orcl/control02.ctl
Finished restore at 30-MAY-17

 

控制文件恢复成功以后启动数据库到mount状态:

SQL> alter database mount;

Database altered.

启动到mount状态以后,在RMAN模式下恢复数据文件:

RMAN> restore database;

Starting restore at 30-MAY-17
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 30-MAY-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 11 objects
Finished implicit crosscheck backup at 30-MAY-17

Starting implicit crosscheck copy at 30-MAY-17
using channel ORA_DISK_1
Finished implicit crosscheck copy at 30-MAY-17

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945338539_dlsqp4yv_.bkp

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 /usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
channel ORA_DISK_1: ORA-19870: error while restoring backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
ORA-19502: write error on file "/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf", block number 216192 (block size=8192)
ORA-27072: File I/O error
Linux-x86_64 Error: 25: Inappropriate ioctl for device
Additional information: 4
Additional information: 216192
Additional information: 6963
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 00006 to /usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oracle/data/rman_ts1.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmdbx_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:25
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 /usr/oracle/app/oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /usr/oracle/app/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /usr/oracle/app/oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /home/oracle/data/default_tablespace.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqmfgv_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:25
failover to previous backup

creating datafile file number=5 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
Finished restore at 30-MAY-17

 

   其余文件正常恢复,CTRR_DATA.dbf数据文件时遇到错误:

ORA-19502: write error on file "/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf", block number 216192 (block size=8192)
ORA-27072: File I/O error
Linux-x86_64 Error: 25: Inappropriate ioctl for device

查了一下错误缘由,发现由于此数据文件较大恢复时致使磁盘空间不足引发的,因而删除一些文件释放磁盘从新执行命令恢复成功:

RMAN> restore database;

Starting restore at 30-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

skipping datafile 1; already restored to file /usr/oracle/app/oradata/orcl/system01.dbf
skipping datafile 2; already restored to file /usr/oracle/app/oradata/orcl/sysaux01.dbf
skipping datafile 3; already restored to file /usr/oracle/app/oradata/orcl/undotbs01.dbf
skipping datafile 4; already restored to file /usr/oracle/app/oradata/orcl/users01.dbf
skipping datafile 8; already restored to file /home/oracle/data/default_tablespace.dbf
skipping datafile 7; already restored to file /home/oracle/data/CTRR_DATA_1.dbf
skipping datafile 6; already restored to file /usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
skipping datafile 9; already restored to file /home/oracle/data/rman_ts1.dbf
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 /usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp
channel ORA_DISK_1: piece handle=/usr/oracle/app/flash_recovery_area/ORCL/backupset/2017_05_30/o1_mf_nnndf_TAG20170530T105100_dlsqjoft_.bkp tag=TAG20170530T105100
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:26
Finished restore at 30-MAY-17

 

  而后去以前存放数据文件、控制文件的目录下看一下文件是否都恢复成功:

[root@oracledb orcl]# ls -l
total 4867456
-rw-r----- 1 oracle oinstall 524296192 May 30 12:12 APSALU3_DATA.dbf
-rw-r----- 1 oracle oinstall 9748480 May 30 14:48 control01.ctl
-rw-r----- 1 oracle oinstall 2147491840 May 30 12:12 CTRR_DATA.dbf
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 14:48 redo01.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo02.log
-rwxrwxr-x 1 oracle oinstall 52429312 May 30 12:12 redo03.log
-rwxrwxr-x 1 oracle oinstall 660611072 May 30 14:48 sysaux01.dbf
-rwxrwxr-x 1 oracle oinstall 754982912 May 30 14:48 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Mar 23 10:52 temp01.dbf
-rwxrwxr-x 1 oracle oinstall 723525632 May 30 14:48 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 30 12:12 users01.dbf

 

  使用recover 命令恢复数据库,因为是脱机备份恢复不使用重作日志恢复模式:

RMAN> recover database noredo;

Starting recover at 30-MAY-17
using channel ORA_DISK_1

Finished recover at 30-MAY-17

 

  而后打开数据库到open状态:

SQL> alter database open resetlogs;

Database altered.

 

查看备份以后scott用户建立的表,已经不存在了,自备份以后的数据所有丢失。

 

2 脱机备份以后,对于RMAN备份有了初步的了解,相对于传统的用户手动管理备份文件,RMAN备份操做起来相对要简单方便的多,可是联机备份相对脱机备份操做要复杂,须要掌握的地方稍微多些。

 

2.1 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 ON;
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 '/usr/oracle/app/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default

 

CONFIGURE RETENTION POLICY TO REDUNDANCY 1: 该参数说明保留备份文件的副本数量,若是天天都备份一个数据文件,参数1说明只保留一个该数据文件的副本,而且保留最新的副本。

CONFIGURE DEFAULT DEVICE TYPE TO DISK: 该配置参数说明备份的数据文件默认备份到数据库服务器的磁盘上,该参数能够更改成备份到磁带上。 

CONFIGURE BACKUP OPTIMIZATION OFF:默认值为关闭,若是打开,rman将对备份的数据文件及归档等文件进行一种优化的算法。

CONFIGURE CONTROLFILE AUTOBACKUP ON:默认值为关闭,强制数据库在备份文件或者执行改变数据库结构的命令以后将控制文件自动备份。

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET: 配置数据库设备类型的并行度,并行的数目决定了开启通道的个数。

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F':配置控制文件的备份片的路径和格式,好比:configure controlfile autobackup format for device type disk to 'e:\backupcontrol\%F';

 

2.2 快闪恢复区

使用RMAN联机备份前,必须先设置快闪恢复区,将DB_RECOVERY_FILE_DEST参数指定的目录做为归档重作日志备份的默认路劲,而且快闪恢复区的尺寸设置足够大。

SQL> show parameter db_recovery_file_dest;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /usr/oracle/app/flash_recovery
_area
db_recovery_file_dest_size big integer 3882M

 

2.3 归档模式

RMAN联机备份须要数据库处于归档模式,关闭数据库,启动到mount状态,修改数据为归档模式

SQL> alter database archivelog;

Database altered.

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
SQL> alter database open;

Database altered.

SQL>

 

 

2.4 恢复目录

恢复目录是RMAN专用的备份信息存储地,没有恢复目录时,RMAN相关的备份信息,好比归档文件路径、备份集路径等均存储在目标数据库的控制文件中,考虑到控制文件并不能无限增加,并且控制文件也不只仅是用来存储与备份相关的信息,当待备份的数据库注册到恢复目录以后,RMAN相关的信息除了保存在控制文件中外(控制文件实际上只保存一部分),更加详细的信息就都被存储在恢复目录中。

 

(1) 恢复目录建立过程,管理员帐户登陆到数据库

create tablespace rman_ts datafile '/home/oracle/data/rman_ts1.dbf'
size 2G
autoextend on next 500M
maxsize 6G;

 

create user rman_reuser identified by 123456
default tablespace rman_ts 
temporary tablespace temp02;

 

grant connect, resource, recovery_catalog_owner to rman_reuser;

 

建立完表空间与用户以后,登陆到RMAN模式下建立恢复目录rman_ts,注意名字与表空间同样

RMAN>create catalog tablespace rman_ts;

 

注册数据库

RMAN>register database;

 

备份信息是否记入CATALOG取决于执行RMAN操做时是否链接到了CATALOG,也就是说,即便目标数据库已经注册到恢复目录中,但链接时没有以CATALOG模式链接,则备份信息仍然是只存入目标端数据库的控制文件,至关于NOCATALOG模式。

使用CATALOG模式链接RMAN:

 

[oracle@oracledb ~]$ rman target/ catalog rman_reuser/XXXXXX;

 

Recovery Manager: Release 11.2.0.1.0 - Production on Tue May 30 17:53:46 2017

 

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

 

connected to target database: ORCL (DBID=1452257309)
connected to recovery catalog database

 

 

设置备份文件保存路劲:/home/oracle/oradata/backup

RMAN> configure channel device type disk format '/home/oracle/oradata/backup/data_%d_%M_%U';

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/oradata/backup/%d_%M_%D';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/oradata/backup/data_%d_%M_%U';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

 

设置控制文件默认的存放位置:/home/oracle/oradata/backup/

RMAN> configure controlfile autobackup format for device type disk to '/home/oracle/oradata/backup/ctl_%d_%M_%F';

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/oradata/backup/ctl_%d_%M_%F';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

 

到此联机备份准备工做完成。

 

3 联机备份与恢复

   3.1 联机备份整个数据库

  默认备份,不显示指定任何参数

RMAN> backup as compressed backupset database plus archivelog delete all input;

Starting backup at 30-MAY-17
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=41 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=44 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=7 STAMP=945368451
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0es5ibcf_1_1_ORCL tag=TAG20170530T182102 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_1_dltktmly_.arc RECID=7 STAMP=945368451
Finished backup at 30-MAY-17

Starting backup at 30-MAY-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
input datafile file number=00007 name=/home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00009 name=/home/oracle/data/rman_ts1.dbf
input datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbf
input datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_2: starting piece 1 at 30-MAY-17
channel ORA_DISK_3: starting compressed full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbf
input datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbf
input datafile file number=00008 name=/home/oracle/data/default_tablespace.dbf
channel ORA_DISK_3: starting piece 1 at 30-MAY-17
channel ORA_DISK_2: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0gs5ibde_1_1_ORCL tag=TAG20170530T182130 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:06:28
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00006 name=/usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_2: starting piece 1 at 30-MAY-17
channel ORA_DISK_2: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0is5ibpk_1_1_ORCL tag=TAG20170530T182130 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_3: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0hs5ibde_1_1_ORCL tag=TAG20170530T182130 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:06:55
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0fs5ibde_1_1_ORCL tag=TAG20170530T182130 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:07:37
Finished backup at 30-MAY-17

Starting backup at 30-MAY-17
current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=8 STAMP=945368952
channel ORA_DISK_1: starting piece 1 at 30-MAY-17
channel ORA_DISK_1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/0js5ibrs_1_1_ORCL tag=TAG20170530T182916 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_2_dltlcr44_.arc RECID=8 STAMP=945368952
Finished backup at 30-MAY-17

Starting Control File and SPFILE Autobackup at 30-MAY-17
piece handle=/usr/oracle/app/flash_recovery_area/ORCL/autobackup/2017_05_30/o1_mf_s_945368958_dltlcyvy_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 30-MAY-17

 

  以上备份信息得出两个结论:数据文件备份到了RMAN 配置参数 configure channel device type disk format '/home/oracle/oradata/backup/%U_%d' 配置的路劲下,

  控制文件,归档日志文件备份到了参数db_recovery_file_dest 对应的闪回区/usr/oracle/app/flash_recovery_area/ORCL下。

 

  使用更细节的配置命令,将数据文件,控制文件,归档日志备份到同一指定的目录下: 

run
{

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

backup database format '/home/oracle/oradata/backup/Data_%d_%M_%U'

plus archivelog format '/home/oracle/oradata/backup/log_%d_%M_%U';

release channel ch1;

release channel ch2;
}

 

allocated channel: ch1
channel ch1: SID=39 device type=DISK

allocated channel: ch2
channel ch2: SID=40 device type=DISK


Starting backup at 30-MAY-17
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=9 STAMP=945378795
input archived log thread=1 sequence=4 RECID=10 STAMP=945381016
input archived log thread=1 sequence=5 RECID=11 STAMP=945381246
channel ch1: starting piece 1 at 30-MAY-17
channel ch2: starting archived log backup set
channel ch2: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=12 STAMP=945382431
channel ch2: starting piece 1 at 30-MAY-17
channel ch1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/log_ORCL_05_12s5ir4g_1_1 tag=TAG20170530T224952 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:08
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=13 STAMP=945384591
channel ch1: starting piece 1 at 30-MAY-17
channel ch2: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/log_ORCL_05_13s5ir4g_1_1 tag=TAG20170530T224952 comment=NONE
channel ch2: backup set complete, elapsed time: 00:00:07
channel ch1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/log_ORCL_05_14s5ir4o_1_1 tag=TAG20170530T224952 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-MAY-17

Starting backup at 30-MAY-17
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
input datafile file number=00007 name=/home/oracle/data/CTRR_DATA_1.dbf
channel ch1: starting piece 1 at 30-MAY-17
channel ch2: starting full datafile backup set
channel ch2: specifying datafile(s) in backup set
input datafile file number=00009 name=/home/oracle/data/rman_ts1.dbf
input datafile file number=00006 name=/usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ch2: starting piece 1 at 30-MAY-17
channel ch2: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/data_ORCL_05_16s5ir4q_1_1 tag=TAG20170530T225001 comment=NONE
channel ch2: backup set complete, elapsed time: 00:00:07
channel ch2: starting full datafile backup set
channel ch2: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbf
input datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbf
input datafile file number=00008 name=/home/oracle/data/default_tablespace.dbf
input datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbf
input datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ch2: starting piece 1 at 30-MAY-17
channel ch2: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/data_ORCL_05_17s5ir51_1_1 tag=TAG20170530T225001 comment=NONE
channel ch2: backup set complete, elapsed time: 00:05:19
channel ch1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/data_ORCL_05_15s5ir4q_1_1 tag=TAG20170530T225001 comment=NONE
channel ch1: backup set complete, elapsed time: 00:05:56
Finished backup at 30-MAY-17

Starting backup at 30-MAY-17
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=8 RECID=14 STAMP=945384958
channel ch1: starting piece 1 at 30-MAY-17
channel ch1: finished piece 1 at 30-MAY-17
piece handle=/home/oracle/oradata/backup/log_ORCL_05_18s5irg0_1_1 tag=TAG20170530T225600 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-MAY-17

Starting Control File and SPFILE Autobackup at 30-MAY-17
piece handle=/home/oracle/oradata/backup/ctl_ORCL_05_c-1452257309-20170530-04 comment=NONE
Finished Control File and SPFILE Autobackup at 30-MAY-17

released channel: ch1

released channel: ch2

 

  至此联机备份整个数据库完成,咱们能够看一下备份文件目录下是否有备份信息显示的文件

[oracle@oracledb ~]$ cd /home/oracle/oradata/backup
[oracle@oracledb backup]$ ls -l
total 2837192
-rw-r----- 1 oracle oinstall 9830400 May 30 22:56 ctl_ORCL_05_c-1452257309-20170530-04
-rw-r----- 1 oracle oinstall 1678073856 May 30 22:55 data_ORCL_05_15s5ir4q_1_1
-rw-r----- 1 oracle oinstall 6529024 May 30 22:50 data_ORCL_05_16s5ir4q_1_1
-rw-r----- 1 oracle oinstall 1169031168 May 30 22:55 data_ORCL_05_17s5ir51_1_1
-rw-r----- 1 oracle oinstall 13558784 May 30 22:49 log_ORCL_05_12s5ir4g_1_1
-rw-r----- 1 oracle oinstall 25548800 May 30 22:49 log_ORCL_05_13s5ir4g_1_1
-rw-r----- 1 oracle oinstall 2192384 May 30 22:50 log_ORCL_05_14s5ir4o_1_1
-rw-r----- 1 oracle oinstall 503808 May 30 22:56 log_ORCL_05_18s5irg0_1_1

 

   3.2  非系统表空间数据文件损坏恢复

   (1) 数据库运行在归档模式下,表空间users的数据文件损坏,有完整的备份,当前以及归档的日志无缺。

  先作当前数据的变化测试,使用scott用户给测试表添加数据。

insert into t_test1(id, name)
select 2,'latiny2' from dual;

commit;

 

关闭数据库,删除users01.dbf 数据文件,重启再数据库

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

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 343934608 bytes
Database Buffers 100663296 bytes
Redo Buffers 4141056 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/usr/oracle/app/oradata/orcl/users01.dbf'

数据库启动失败,由于users01.dbf 文件已损坏(手动删除),为了启动成功将损坏的数据文件先offline 再打开,此时尝试访问scott.t_test1显示对应的数据文件

没法访问。


SQL> alter database datafile 4 offline;

Database altered.

SQL> alter database open;

Database altered.

 

  (2) 恢复数据文件

  在rman 模式下恢复损坏的数据文件

RMAN> restore datafile 4;

Starting restore at 06-JUN-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=26 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=40 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 00004 to /usr/oracle/app/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/oradata/backup/data_ORCL_05_17s5ir51_1_1
channel ORA_DISK_1: piece handle=/home/oracle/oradata/backup/data_ORCL_05_17s5ir51_1_1 tag=TAG20170530T225001
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 06-JUN-17

 

RMAN> recover datafile 4;

Starting recover at 06-JUN-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_8_dlv1zyxk_.arc
archived log for thread 1 with sequence 9 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_9_dm23lqhh_.arc
archived log for thread 1 with sequence 10 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_10_dm23nl59_.arc
archived log for thread 1 with sequence 11 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_06/o1_mf_1_11_dmd9d6b5_.arc
archived log for thread 1 with sequence 12 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_06/o1_mf_1_12_dmd9gtql_.arc
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_8_dlv1zyxk_.arc thread=1 sequence=8
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_9_dm23lqhh_.arc thread=1 sequence=9
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_10_dm23nl59_.arc thread=1 sequence=10
media recovery complete, elapsed time: 00:00:02
Finished recover at 06-JUN-17

  

  数据文件恢复成功,将数据文件online

SQL> alter database datafile 4 online;

Database altered.

 

此时能够访问scott.t_test1,以前新增的数据也在其中。

 

3.3 系统表空间损坏恢复

系统表空间损坏,可是控制文件与日志文件无缺

(1)删除系统表空间,实验表空间损坏,关闭数据库删除文件以后重启数据库报错

SQL> shutdown immdiate;
SP2-0717: illegal SHUTDOWN option
SQL> shutdown immediate;
\Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
SP2-0042: unknown command "\startup" - rest of line ignored.
SQL> startup
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 348128912 bytes
Database Buffers 96468992 bytes
Redo Buffers 4141056 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/usr/oracle/app/oradata/orcl/system01.dbf'

 

  (2) 将数据文件offline 而后rman模式下恢复数据文件

SQL> alter database datafile 1 offline;

Database altered.

 

RMAN> restore datafile 1;

Starting restore at 06-JUN-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

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 /usr/oracle/app/oradata/orcl/system01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/oradata/backup/data_ORCL_05_17s5ir51_1_1
channel ORA_DISK_1: piece handle=/home/oracle/oradata/backup/data_ORCL_05_17s5ir51_1_1 tag=TAG20170530T225001
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 06-JUN-17

RMAN> recover datafile 1;

Starting recover at 06-JUN-17
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_8_dlv1zyxk_.arc
archived log for thread 1 with sequence 9 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_9_dm23lqhh_.arc
archived log for thread 1 with sequence 10 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_10_dm23nl59_.arc
archived log for thread 1 with sequence 11 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_06/o1_mf_1_11_dmd9d6b5_.arc
archived log for thread 1 with sequence 12 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_06/o1_mf_1_12_dmd9gtql_.arc
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_1_8_dlv1zyxk_.arc thread=1 sequence=8
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_9_dm23lqhh_.arc thread=1 sequence=9
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_02/o1_mf_1_10_dm23nl59_.arc thread=1 sequence=10
media recovery complete, elapsed time: 00:00:05
Finished recover at 06-JUN-17

 

SQL> alter database datafile 1 online;

Database altered.

 

数据库启动成功

SQL> alter database open;

Database altered.

SQL>

 

3.4 所有数据文件丢失

关闭数据库删除所有文件,重启数据库。

 

[oracle@oracledb orcl]$ ls -l
total 4877952
-rw-r----- 1 oracle oinstall 524296192 Jun 15 14:54 APSALU3_DATA.dbf
-rw-r----- 1 oracle oinstall 10010624 Jun 15 14:54 control01.ctl
-rw-r----- 1 oracle oinstall 2147491840 Jun 15 14:54 CTRR_DATA.dbf
-rw-r----- 1 oracle oinstall 52429312 Jun 15 14:54 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Jun 15 13:54 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Jun 15 13:55 redo03.log
-rw-r----- 1 oracle oinstall 660611072 Jun 15 14:54 sysaux01.dbf
-rw-r----- 1 oracle oinstall 765468672 Jun 15 14:54 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 Jun 12 21:53 temp01.dbf
-rw-r----- 1 oracle oinstall 723525632 Jun 15 14:54 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Jun 15 14:54 users01.dbf
[oracle@oracledb orcl]$ rm *;
[oracle@oracledb orcl]$ ls -l
total 0
[oracle@oracledb orcl]$

 

 

 

 数据库只能启动到nomount状态下,启动到mount下报错,由于没有控制文件

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 360711824 bytes
Database Buffers 83886080 bytes
Redo Buffers 4141056 bytes
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info


SQL>

 

先退出RMAN而后从新登陆,登陆以后恢复控制文件

[oracle@oracledb ~]$ rman target/

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jun 15 15:01:13 2017

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

connected to target database: ORCL (not mounted)

RMAN> restore controlfile from '/home/oracle/oradata/backup/control/ctl_ORCL_06_15_c-1452257309-20170615-05';

Starting restore at 15-JUN-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:16
output file name=/usr/oracle/app/oradata/orcl/control01.ctl
output file name=/usr/oracle/app/flash_recovery_area/orcl/control02.ctl
Finished restore at 15-JUN-17

RMAN>

 

 

控制文件恢复成功以后,启动数据库到mount状态下

SQL> alter database mount;

Database altered.

SQL>

 

RMAN下恢复数据库, restore databse;

RMAN> restore database;

Starting restore at 15-JUN-17
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 15-JUN-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=21 device type=DISK
Crosschecked 22 objects
Crosschecked 20 objects
Finished implicit crosscheck backup at 15-JUN-17

Starting implicit crosscheck copy at 15-JUN-17
using channel ORA_DISK_1
using channel ORA_DISK_2
Finished implicit crosscheck copy at 15-JUN-17

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_5_dn4cr5pm_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_6_dn4cr5qn_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_3_dn4cr5m9_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_2_dn4cr7kx_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_9_dn4crbvg_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_1_dn4cr7l6_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_7_dn4cr5mj_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_8_dn4cr8qp_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_4_dn4cr5vc_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_4_dmwg5bjo_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_2_dmw48n0t_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_1_dmw454w6_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_3_dmwfk7mt_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_4_dmxdm4cm_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_12/o1_mf_1_3_dmxcfz0q_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_5_dn43mxcl_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_1_dn3zoqo8_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_7_dn4857f0_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_4_dn42j321_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_6_dn43t9pc_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_2_dn3zqofd_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_8_dn489j4x_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_3_dn4265mf_.arc
File Name: /usr/oracle/app/flash_recovery_area/ORCL/archivelog_backup/2017_06_15/o1_mf_1_9_dn48c07s_.arc

using channel ORA_DISK_1
using channel ORA_DISK_2

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 00006 to /usr/oracle/app/oradata/orcl/APSALU3_DATA.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oracle/data/rman_ts1.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/oradata/backup/data/data2_ORCL_06_39s6rt41_1_1
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00001 to /usr/oracle/app/oradata/orcl/system01.dbf
channel ORA_DISK_2: restoring datafile 00002 to /usr/oracle/app/oradata/orcl/sysaux01.dbf
channel ORA_DISK_2: restoring datafile 00003 to /usr/oracle/app/oradata/orcl/undotbs01.dbf
channel ORA_DISK_2: restoring datafile 00004 to /usr/oracle/app/oradata/orcl/users01.dbf
channel ORA_DISK_2: restoring datafile 00008 to /home/oracle/data/default_tablespace.dbf
channel ORA_DISK_2: reading from backup piece /home/oracle/oradata/backup/data/data2_ORCL_06_3as6rt44_1_1
channel ORA_DISK_1: piece handle=/home/oracle/oradata/backup/data/data2_ORCL_06_39s6rt41_1_1 tag=TAG20170615T123512
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:05:50
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 /usr/oracle/app/oradata/orcl/CTRR_DATA.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oracle/data/CTRR_DATA_1.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/oradata/backup/data/data1_ORCL_06_38s6rt40_1_1
channel ORA_DISK_2: piece handle=/home/oracle/oradata/backup/data/data2_ORCL_06_3as6rt44_1_1 tag=TAG20170615T123512
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:07:15
channel ORA_DISK_1: piece handle=/home/oracle/oradata/backup/data/data1_ORCL_06_38s6rt40_1_1 tag=TAG20170615T123512
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:03:36
Finished restore at 15-JUN-17

 

将放在其余目录下的重作日志复制到默认的目录下,而后查看,若是只有一份重作日志且丢失,那么此步骤可省略,可是会形成服务器宕机以后的部分数据丢失,丢失量取决于未归档的重作日志存储的数据量

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/usr/oracle/app/oradata/orcl/redo03.log
/usr/oracle/app/oradata/orcl/redo02.log
/usr/oracle/app/oradata/orcl/redo01.log
/home/oracle/data/redo01_a.log

 

recover database 

RMAN> recover database;

Starting recover at 15-JUN-17
using channel ORA_DISK_1
using channel ORA_DISK_2

starting media recovery

archived log for thread 1 with sequence 6 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_6_dn4cr5qn_.arc
archived log for thread 1 with sequence 7 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_7_dn4cr5mj_.arc
archived log for thread 1 with sequence 8 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_8_dn4cr8qp_.arc
archived log for thread 1 with sequence 9 is already on disk as file /usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_9_dn4crbvg_.arc
archived log for thread 1 with sequence 10 is already on disk as file /home/oracle/data/redo01_a.log
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_6_dn4cr5qn_.arc thread=1 sequence=6
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_7_dn4cr5mj_.arc thread=1 sequence=7
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_8_dn4cr8qp_.arc thread=1 sequence=8
archived log file name=/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2017_06_15/o1_mf_1_9_dn4crbvg_.arc thread=1 sequence=9
archived log file name=/home/oracle/data/redo01_a.log thread=1 sequence=10
media recovery complete, elapsed time: 00:00:21
Finished recover at 15-JUN-17

 

SQL> alter database open resetlogs;

Database altered.

 

  至此数据库恢复完成,注意若是重作日志与数据文件,控制文件等一块儿丢失,没有备份,在其余磁盘上也没有作多个重组日志机制,只用备份的归档日志恢复的话,服务器宕机以后未归档的数据极可能会丢失,作不到100%的恢复。

相关文章
相关标签/搜索