天天看點

RMAN備份恢複測試

  1. 登入 rman  

[[email protected] 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. 模拟業務操作(建立一張測試表)  

[[email protected] 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

[[email protected] rmanbackup]$ cd /oracle/oradata

[[email protected] 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

[[email protected] oradata]$ mv FSNW FSNW_BAK

[[email protected] 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 -- 重新啟動資料庫,出現錯誤:找不到控制檔案

[[email protected] 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進行恢複  

[[email protected] 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.

[[email protected] 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,重新進行恢複

[[email protected] oradata]$ mkdir FSNW

[[email protected] 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;   [[email protected] FSNW_BAK]$ cp *.log ../FSNW

[[email protected] 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.

[[email protected] 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