本文轉自: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%的恢復。