本文转自:https://www.cnblogs.com/Latiny/p/6920428.html
对于Rman有了很深刻的认识,非常感谢博主
RMAN在数据库服务器的帮助下实现数据库文件、控制文件、数据库文件与控制文件的映像副本、归档日志文件、数据库服务器参数文件的备份。
RMAN的特点:
(1) 支持增量备份:传统的exp与expdp备份工具,只能实现一个完整备份而不能增量备份,RMAN采用备份级别实现增量备份,在一个完整的备份基础上采用增量备份可以大大减少备份的数量;
(2) 自动管理备份文件:RMAN备份的数据是RMAN自动管理的,包括文件名字,备份文件存储目录等;
(3) 自动化备份与恢复:在备份与恢复操作时,使用简单的指令就可以实现备份与恢复,执行过程完全有RMAN维护。
(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%的恢复。