RMAN備份恢復測試

 
1. 登錄 rman
 
[oracle@indb oradata]$ rman target /
 
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:50:07 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
connected to target database: FSNW (DBID=734270689)
 
2. 備份數據庫
 
RMAN> backup database format '/oracle/oradata/rmanbackup/DATA.%U.rman'
2> plus archivelog format '/oracle/oradata/rmanbackup/ARCH.%U.rman'
3> delete all input;
 

Starting backup at 22-9月 -08
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=1 recid=45 stamp=666108755
input archive log thread=1 sequence=2 recid=46 stamp=666108763
input archive log thread=1 sequence=3 recid=47 stamp=666108769
input archive log thread=1 sequence=4 recid=48 stamp=666108770
input archive log thread=1 sequence=5 recid=49 stamp=666108812
channel ORA_DISK_1: starting piece 1 at 22-9月 -08
channel ORA_DISK_1: finished piece 1 at 22-9月 -08
piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/oracle/oradata/arch/1_1_666101140.dbf recid=45 stamp=666108755
archive log filename=/oracle/oradata/arch/1_2_666101140.dbf recid=46 stamp=666108763
archive log filename=/oracle/oradata/arch/1_3_666101140.dbf recid=47 stamp=666108769
archive log filename=/oracle/oradata/arch/1_4_666101140.dbf recid=48 stamp=666108770
archive log filename=/oracle/oradata/arch/1_5_666101140.dbf recid=49 stamp=666108812
Finished backup at 22-9月 -08
 
Starting backup at 22-9月 -08
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/oracle/oradata/FSNW/FINANCE.dbf
input datafile fno=00001 name=/oracle/oradata/FSNW/system01.dbf
input datafile fno=00003 name=/oracle/oradata/FSNW/sysaux01.dbf
input datafile fno=00002 name=/oracle/oradata/FSNW/undotbs01.dbf
input datafile fno=00004 name=/oracle/oradata/FSNW/users01.dbf
channel ORA_DISK_1: starting piece 1 at 22-9月 -08
channel ORA_DISK_1: finished piece 1 at 22-9月 -08
piece handle=/oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman tag=TAG20080922T141335 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:25
Finished backup at 22-9月 -08
 
Starting backup at 22-9月 -08
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=6 recid=50 stamp=666109020
channel ORA_DISK_1: starting piece 1 at 22-9月 -08
channel ORA_DISK_1: finished piece 1 at 22-9月 -08
piece handle=/oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman tag=TAG20080922T141700 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/oracle/oradata/arch/1_6_666101140.dbf recid=50 stamp=666109020
Finished backup at 22-9月 -08
 
Starting Control File and SPFILE Autobackup at 22-9月 -08
piece handle=/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman comment=NONE
Finished Control File and SPFILE Autobackup at 22-9月 -08
 
RMAN> exit
 

Recovery Manager complete.

3. 模擬業務操作(創建一張測試表)
 
[oracle@indb rmanbackup]$ sqlplus
 
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:25:07 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
Enter user-name: / as sysdba
 
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
 
SQL> create table test_tianyc as select * From dba_objects;
 
Table created.
 
SQL> select count(*) from test_tianyc;
 
  COUNT(*)
----------
     49625

4. 模擬數據庫損壞(丟失控制文件、在線日誌文件和數據文件)
 
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@indb rmanbackup]$ cd /oracle/oradata
[oracle@indb oradata]$ ll
總計 12
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch
drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 將數據文件、控制文件、在線日誌文件所在文件夾FSNW重命名爲FSNW_BAK
[oracle@indb oradata]$ mv FSNW FSNW_BAK
[oracle@indb oradata]$ ll
總計 12
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch
drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW_BAK
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 重新啓動數據庫,出現錯誤:找不到控制文件
[oracle@indb oradata]$ sqlplus
 
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:28:51 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
Enter user-name: / as sysdba
Connected to an idle instance.
 
SQL> startup
ORACLE instance started.
 
Total System Global Area  926941184 bytes
Fixed Size                  1222648 bytes
Variable Size             264243208 bytes
Database Buffers          654311424 bytes
Redo Buffers                7163904 bytes
ORA-00205: error in identifying control file, check alert log for more info
 
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

5. 使用rman進行恢復
 
[oracle@indb oradata]$ rman target /
 
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:29:26 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
connected to target database: FSNW (not mounted)
 
5.1 恢復控制文件
 
-- 恢復控制文件必須加上 from 子句,“from + autobackup”或者“from + 控制文件所在的備份片”
-- 這裏提示恢復失敗,是因爲沒有文件夾 /oracle/oradata/FSNW
RMAN> restore controlfile from '/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman';
 
Starting restore at 22-9月 -08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
 
channel ORA_DISK_1: restoring control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/22/2008 14:30:28
ORA-19870: error reading backup piece /oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman
ORA-19504: failed to create file "/oracle/oradata/FSNW/control01.ctl"
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
 
RMAN> exit
 

Recovery Manager complete.
[oracle@indb oradata]$ ll
總計 12
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 arch
drwxrwxr-x 2 oracle oracle 4096 09-22 12:05 FSNW_BAK
drwxrwxr-x 2 oracle oracle 4096 09-22 14:17 rmanbackup
-- 創建文件夾 FSNW,重新進行恢復
[oracle@indb oradata]$ mkdir FSNW
[oracle@indb oradata]$ rman target /
 
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:31:01 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
connected to target database: FSNW (not mounted)
 
RMAN> restore controlfile from '/oracle/oradata/rmanbackup/CTL.c-734270689-20080922-03.rman';
 
Starting restore at 22-9月 -08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
 
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/oracle/oradata/FSNW/control01.ctl
output filename=/oracle/oradata/FSNW/control02.ctl
output filename=/oracle/oradata/FSNW/control03.ctl
Finished restore at 22-9月 -08
 
RMAN> alter database mount;
 
database mounted
released channel: ORA_DISK_1

5.2 恢復數據文件
 
RMAN> restore database;
 
Starting restore at 22-9月 -08
Starting implicit crosscheck backup at 22-9月 -08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 22-9月 -08
 
Starting implicit crosscheck copy at 22-9月 -08
using channel ORA_DISK_1
Finished implicit crosscheck copy at 22-9月 -08
 
searching for all files in the recovery area
cataloging files...
no files cataloged
 
using channel ORA_DISK_1
 
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /oracle/oradata/FSNW/system01.dbf
restoring datafile 00002 to /oracle/oradata/FSNW/undotbs01.dbf
restoring datafile 00003 to /oracle/oradata/FSNW/sysaux01.dbf
restoring datafile 00004 to /oracle/oradata/FSNW/users01.dbf
restoring datafile 00005 to /oracle/oradata/FSNW/FINANCE.dbf
channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/oradata/rmanbackup/DATA.0njr80sf_1_1.rman tag=TAG20080922T141335
channel ORA_DISK_1: restore complete, elapsed time: 00:03:30
Finished restore at 22-9月 -08

5.3 恢復歸檔日誌文件
 
-- 如果未刪除過期的歸檔記錄,則恢復歸檔日誌時可能會出現錯誤,就像下面的這樣:
RMAN> restore archivelog all;
 
Starting restore at 22-9月 -08
using channel ORA_DISK_1
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/22/2008 14:37:08
RMAN-06026: some targets not found - aborting restore
RMAN-06025: no backup of log thread 1 seq 3 lowscn 87447181 found to restore
RMAN-06025: no backup of log thread 1 seq 2 lowscn 87447109 found to restore
RMAN-06025: no backup of log thread 1 seq 1 lowscn 87439708 found to restore
RMAN-06025: no backup of log thread 1 seq 1146 lowscn 87439440 found to restore
RMAN-06025: no backup of log thread 1 seq 1145 lowscn 87439370 found to restore
RMAN-06025: no backup of log thread 1 seq 1144 lowscn 87438455 found to restore
RMAN-06025: no backup of log thread 1 seq 1143 lowscn 87438384 found to restore
RMAN-06025: no backup of log thread 1 seq 1142 lowscn 87438291 found to restore
RMAN-06025: no backup of log thread 1 seq 1141 lowscn 87438206 found to restore
RMAN-06025: no backup of log thread 1 seq 1140 lowscn 87427959 found to restore
RMAN-06025: no backup of log thread 1 seq 1139 lowscn 87383649 found to restore
 
-- 可以手工指定要恢復的歸檔日誌序列號(序列號可以從備份記錄中查到)
RMAN> restore archivelog sequence between 1 and 4;
 
Starting restore at 22-9月 -08
using channel ORA_DISK_1
 
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=1
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=3
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4
channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 22-9月 -08
 
-- 恢復完指定序列號後,應該再嘗試恢復後面的序列號,直到無對應的序列號爲止
RMAN> restore archivelog sequence between 5 and 5;
 
Starting restore at 22-9月 -08
using channel ORA_DISK_1
 
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5
channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/oradata/rmanbackup/ARCH.0mjr80sc_1_1.rman tag=TAG20080922T141332
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 22-9月 -08
 
RMAN> restore archivelog sequence between 6 and 6;
 
Starting restore at 22-9月 -08
using channel ORA_DISK_1
 
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=6
channel ORA_DISK_1: reading from backup piece /oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman
channel ORA_DISK_1: restored backup piece 1
piece handle=/oracle/oradata/rmanbackup/ARCH.0ojr812t_1_1.rman tag=TAG20080922T141700
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 22-9月 -08
 
RMAN> restore archivelog sequence between 7 and 7;
 
Starting restore at 22-9月 -08
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/22/2008 14:39:56
RMAN-20242: specification does not match any archive log in the recovery catalog

5.4 修復數據庫
 
-- 修復失敗,因爲缺少在線重做日誌文件(此時可以進行不完全恢復)
RMAN> recover database;
 
Starting recover at 22-9月 -08
using channel ORA_DISK_1
 
starting media recovery
 
archive log thread 1 sequence 6 is already on disk as file /oracle/oradata/arch/1_6_666101140.dbf
archive log filename=/oracle/oradata/arch/1_6_666101140.dbf thread=1 sequence=6
unable to find archive log
archive log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/22/2008 14:44:25
RMAN-06054: media recovery requesting unknown log: thread 1 seq 7 lowscn 87458540
 
5.4.1 這裏假設未丟失在線日誌文件(將在線日誌文件拷貝回去),測試一下完全修復。
 
RMAN> recover database;
 
Starting recover at 22-9月 -08
using channel ORA_DISK_1
 
starting media recovery
 
archive log thread 1 sequence 6 is already on disk as file /oracle/oradata/arch/1_6_666101140.dbf
archive log filename=/oracle/oradata/arch/1_6_666101140.dbf thread=1 sequence=6
unable to find archive log
archive log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/22/2008 14:44:25
RMAN-06054: media recovery requesting unknown log: thread 1 seq 7 lowscn 87458540

5.4.2 拷貝在線日誌到原位置,測試完全恢復
 
RMAN> host;
 
[oracle@indb FSNW_BAK]$ cp *.log ../FSNW
[oracle@indb FSNW_BAK]$ exit
exit
host command complete

5.4.3 再次recover數據庫:成功
 
RMAN> recover database;
 
Starting recover at 22-9月 -08
using channel ORA_DISK_1
 
starting media recovery
 
archive log thread 1 sequence 7 is already on disk as file /oracle/oradata/FSNW/redo03.log
archive log filename=/oracle/oradata/FSNW/redo03.log thread=1 sequence=7
media recovery complete, elapsed time: 00:00:02
Finished recover at 22-9月 -08

6. 打開數據庫
 
-- 由於恢復了控制文件,所以必須以resetlogs方式打開
RMAN> alter database open;
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 09/22/2008 14:46:02
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
 
RMAN> alter database open resetlogs;
 
database opened

7. 檢查數據
 
-- 未丟失數據
RMAN> exit
 

Recovery Manager complete.
[oracle@indb oradata]$ sqlplus
 
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 9月 22 14:49:32 2008
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
Enter user-name: / as sysdba
 
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
 
SQL> select count(*) from test_tianyc;
 
  COUNT(*)
----------
     49625
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章